Module: GecodeBuild
- Defined in:
- ext/libgecode3/extconf.rb
Defined Under Namespace
Classes: BuildError
Constant Summary collapse
- GECODE_VENDOR_DIR =
File.("../vendor/gecode-3.7.3", __FILE__).freeze
- PREFIX =
File.("../../../lib/dep-selector-libgecode/vendored-gecode", __FILE__).freeze
Class Method Summary collapse
- .configure ⇒ Object
- .configure_cmd ⇒ Object
- .gecode_vendor_dir ⇒ Object
- .num_processors ⇒ Object
-
.patch_configure ⇒ Object
Depending on the version of mingw we’re using, g++ may or may not fail when given the -pthreads option.
- .prefix ⇒ Object
- .run ⇒ Object
- .run_build_commands ⇒ Object
- .setup_env ⇒ Object
- .system(*args) ⇒ Object
- .windows? ⇒ Boolean
Class Method Details
.configure ⇒ Object
20 21 22 |
# File 'ext/libgecode3/extconf.rb', line 20 def self.configure File.join(GECODE_VENDOR_DIR, "configure") end |
.configure_cmd ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'ext/libgecode3/extconf.rb', line 28 def self.configure_cmd args = %W[ sh #{configure} --prefix=#{prefix} --disable-doc-dot --disable-doc-search --disable-doc-tagfile --disable-doc-chm --disable-doc-docset --disable-qt --disable-examples --disable-flatzinc ] args << "--with-host-os=windows" if windows? args end |
.gecode_vendor_dir ⇒ Object
16 17 18 |
# File 'ext/libgecode3/extconf.rb', line 16 def self.gecode_vendor_dir GECODE_VENDOR_DIR end |
.num_processors ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'ext/libgecode3/extconf.rb', line 89 def self.num_processors n = case RbConfig::CONFIG['host_os'] when /darwin/ ((`which hwprefs` != '') ? `hwprefs thread_count` : `sysctl -n hw.ncpu`).chomp when /linux/ `cat /proc/cpuinfo | grep processor | wc -l`.chomp when /freebsd/ `sysctl -n hw.ncpu`.chomp when /mswin|mingw/ require 'win32ole' wmi = WIN32OLE.connect("winmgmts://") # This only includes physical cores, HT's are not included. cpu = wmi.ExecQuery("select NumberOfCores from Win32_Processor") cpu.to_enum.first.NumberOfCores else 4 end n = n.to_i return 1 if n < 1 return 4 if n > 4 n end |
.patch_configure ⇒ Object
Depending on the version of mingw we’re using, g++ may or may not fail when given the -pthreads option. When testing with ‘gcc version 4.6.2 (GCC)` mingw, this patch is required for the build to succeed.
76 77 78 79 80 81 82 |
# File 'ext/libgecode3/extconf.rb', line 76 def self.patch_configure if windows? original_configure = IO.read(configure) original_configure.gsub!('pthread', 'mthread') File.open(configure, "w+") { |f| f.print(original_configure) } end end |
.prefix ⇒ Object
24 25 26 |
# File 'ext/libgecode3/extconf.rb', line 24 def self.prefix PREFIX end |
.run ⇒ Object
122 123 124 125 126 |
# File 'ext/libgecode3/extconf.rb', line 122 def self.run Dir.chdir(gecode_vendor_dir) do run_build_commands or raise BuildError, "Failed to build gecode library." end end |
.run_build_commands ⇒ Object
112 113 114 115 116 117 118 119 120 |
# File 'ext/libgecode3/extconf.rb', line 112 def self.run_build_commands setup_env patch_configure system(*configure_cmd) && system("make", "clean") && system("make", "-j", (num_processors + 1).to_s) && system("make", "install") && system("make", "distclean") end |
.setup_env ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'ext/libgecode3/extconf.rb', line 46 def self.setup_env if windows? ENV['CC'] ||= 'gcc' ENV['CXX'] ||= 'g++' # Ruby DevKit ships with BSD Tar ENV['PROG_TAR'] ||= 'bsdtar' # Optimize for size on Windows ENV['CFLAGS'] = "#{ENV['CFLAGS']} -Os" ENV['CXXFLAGS'] = "#{ENV['CXXFLAGS']} -Os" # Older versions of CentOS and RHEL need to use this elsif File.exist?('/usr/bin/gcc44') ENV['CC'] = 'gcc44' ENV['CXX'] = 'g++44' end # Configure the gecode libraries to look for other gecode libraries in the # installed lib dir. This isn't needed for dep-selector to correctly link # the libraries it uses, but if you check the libraries with `ldd`, they # will appear to have missing deps or to link to system installed gecode. # When used inside an Omnibus project, this will make the health checker # report an error. libpath = File.join(PREFIX, "lib") ENV['LD_RUN_PATH'] = libpath end |
.system(*args) ⇒ Object
84 85 86 87 |
# File 'ext/libgecode3/extconf.rb', line 84 def self.system(*args) print("-> #{args.join(' ')}\n") super(*args) end |
.windows? ⇒ Boolean
12 13 14 |
# File 'ext/libgecode3/extconf.rb', line 12 def self.windows? !!(RUBY_PLATFORM =~ /mswin|mingw|windows/) end |