Class: Libv8::Builder

Inherits:
Object
  • Object
show all
Includes:
Arch, Checkout, Make, Patcher
Defined in:
ext/libv8/builder.rb

Constant Summary

Constants included from Patcher

Patcher::PATCH_DIRECTORY

Constants included from Checkout

Checkout::GYP_SVN, Checkout::GYP_Source, Checkout::V8_Source

Instance Method Summary collapse

Methods included from Patcher

patch!, patch_directories, patch_directories_for, patches

Methods included from Checkout

check_git_svn!, checkout!, git?

Methods included from Make

make

Methods included from Arch

arm?, libv8_arch, rubinius?, x64?, x86_64_from_arch_flag, x86_64_from_build_cpu, x86_64_from_byte_length

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



15
16
17
# File 'ext/libv8/builder.rb', line 15

def initialize
  @compiler = choose_compiler
end

Instance Method Details

#build_libv8!Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'ext/libv8/builder.rb', line 48

def build_libv8!
  Dir.chdir(V8_Source) do
    fail 'No compilers available' if @compiler.nil?
    checkout!
    setup_python!
    setup_build_deps!
    patch! *patch_directories_for(@compiler)
    print_build_info
    puts `env CXX=#{@compiler} LINK=#{@compiler} #{make} #{make_flags}`
  end
  return $?.exitstatus
end

#make_flags(*flags) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'ext/libv8/builder.rb', line 19

def make_flags(*flags)
  profile = enable_config('debug') ? 'debug' : 'release'

  # FreeBSD uses gcc 4.2 by default which leads to
  # compilation failures due to warnings about aliasing.
  # http://svnweb.freebsd.org/ports/head/lang/v8/Makefile?view=markup
  flags << "strictaliasing=off" if @compiler.is_a?(Compiler::GCC) and @compiler.version < '4.4'

  # Avoid compilation failures on the Raspberry Pi.
  flags << "vfp2=off vfp3=off" if @compiler.target.include? "arm"

  # FIXME: Determine when to activate this instead of leaving it on by
  # default.
  flags << "hardfp=on" if @compiler.target.include? "arm"

  # Fix Malformed archive issue caused by GYP creating thin archives by
  # default.
  flags << "ARFLAGS.target=crs"

  # Solaris / Smart OS requires additional -G flag to use with -fPIC
  flags << "CFLAGS=-G" if @compiler.target =~ /solaris/

  # Disable werror as this version of v8 is getting difficult to maintain
  # with it on
  flags << 'werror=no'

  "#{libv8_arch}.#{profile} #{flags.join ' '}"
end

#setup_build_deps!Object



75
76
77
78
79
80
# File 'ext/libv8/builder.rb', line 75

def setup_build_deps!
  # This uses the Git mirror of the svn repository used by
  # "make dependencies", instead of calling that make target
  `rm -rf build/gyp`
  `ln -fs #{GYP_Source} build/gyp`
end

#setup_python!Object



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'ext/libv8/builder.rb', line 61

def setup_python!
  # If python v2 cannot be found in PATH,
  # create a symbolic link to python2 the current directory and put it
  # at the head of PATH. That way all commands that inherit this environment
  # will use ./python -> python2
  if python_version !~ /^2/
    unless system 'which python2 2>&1 > /dev/null'
      fail "libv8 requires python 2 to be installed in order to build, but it is currently #{python_version}"
    end
    `ln -fs #{`which python2`.chomp} python`
    ENV['PATH'] = "#{File.expand_path '.'}:#{ENV['PATH']}"
  end
end