Module: GecodeBuild

Defined in:
ext/libgecode3/extconf.rb

Defined Under Namespace

Classes: BuildError

Constant Summary collapse

GECODE_VENDOR_DIR =
File.expand_path("../vendor/gecode-3.7.3", __FILE__).freeze
PREFIX =
File.expand_path("../../../lib/dep-selector-libgecode/vendored-gecode", __FILE__).freeze

Class Method Summary collapse

Class Method Details

.configureObject



20
21
22
# File 'ext/libgecode3/extconf.rb', line 20

def self.configure
  File.join(GECODE_VENDOR_DIR, "configure")
end

.configure_cmdObject



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_dirObject



16
17
18
# File 'ext/libgecode3/extconf.rb', line 16

def self.gecode_vendor_dir
  GECODE_VENDOR_DIR
end

.patch_configureObject

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.



65
66
67
68
69
70
71
# File 'ext/libgecode3/extconf.rb', line 65

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

.prefixObject



24
25
26
# File 'ext/libgecode3/extconf.rb', line 24

def self.prefix
  PREFIX
end

.runObject



87
88
89
90
91
# File 'ext/libgecode3/extconf.rb', line 87

def self.run
  Dir.chdir(gecode_vendor_dir) do
    run_build_commands or raise BuildError, "Failed to build gecode library."
  end
end

.run_build_commandsObject



78
79
80
81
82
83
84
85
# File 'ext/libgecode3/extconf.rb', line 78

def self.run_build_commands
  setup_env
  patch_configure
  system(*configure_cmd) &&
    system("make", "clean") &&
    system("make", "-j", "5") &&
    system("make", "install")
end

.setup_envObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'ext/libgecode3/extconf.rb', line 46

def self.setup_env
  if windows?
    ENV['CC'] = 'gcc'
    ENV['CXX'] = 'g++'
  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



73
74
75
76
# File 'ext/libgecode3/extconf.rb', line 73

def self.system(*args)
  print("-> #{args.join(' ')}\n")
  super(*args)
end

.windows?Boolean

Returns:

  • (Boolean)


12
13
14
# File 'ext/libgecode3/extconf.rb', line 12

def self.windows?
 !!(RUBY_PLATFORM =~ /mswin|mingw|windows/)
end