Top Level Namespace

Defined Under Namespace

Modules: WSK Classes: Float, Rational

Constant Summary collapse

ROOT_DIR =
File.expand_path("#{File.dirname(__FILE__)}/../..")

Instance Method Summary collapse

Instance Method Details

#build_external_libs(*iLstExternalLibs) ⇒ Object

Build external libraries. Set CFLAGS and LDFLAGS accordingly.

Parameters
  • iLstExternalLibs (list<String>): List of external libraries names (taken from the external directory)



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'ext/WSK/CommonBuild.rb', line 16

def build_external_libs(*iLstExternalLibs)
  require 'rUtilAnts/Misc'
  RUtilAnts::Misc::install_misc_on_object
  iLstExternalLibs.each do |iLibName|
    lLibDir = File.expand_path("#{File.dirname(__FILE__)}/../../external/#{iLibName}")
    # Build the external library first
    # Don't do it from this environment, as it can modify global compilation variables
    change_dir(lLibDir) do
      lCmd = 'ruby -w build.rb'
      raise "Unable to build external library #{iLibName} (using #{lCmd}): #{$?.inspect}" if (!system(lCmd)) or (($? != nil) and ($? != 0))
    end
    $CFLAGS += " -I#{lLibDir}/include "
    $LDFLAGS += " -L#{lLibDir}/lib -l#{iLibName} "
  end
end

#build_local_gmpObject

Build a local copy of GMP, downloaded directly from the Internet



43
44
45
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
72
73
74
75
76
# File 'ext/WSK/CommonBuild.rb', line 43

def build_local_gmp
  lGMPBaseName = 'gmp-5.1.3'
  lGMPDir = "#{ROOT_DIR}/gmp"
  lGMPInstallDir = "#{ROOT_DIR}/gmp/#{lGMPBaseName}-install"

  puts "**** Have to download, compile and install the GMP library in #{lGMPInstallDir}."
  puts ''

  FileUtils::mkdir_p(lGMPDir)
  lOldDir = Dir.getwd
  Dir.chdir(lGMPDir)
  begin
    puts "** Download #{lGMPBaseName} from ftp://ftp.gmplib.org/pub/gmp/#{lGMPBaseName}.tar.bz2 ..."
    require 'net/ftp'
    ftp = Net::FTP.new('ftp.gmplib.org')
    ftp.
    ftp.getbinaryfile("pub/gmp/#{lGMPBaseName}.tar.bz2")
    ftp.close
    puts '** Extract archive contents ...'
    exec_cmd "tar xjf #{lGMPBaseName}.tar.bz2"
    Dir.chdir(lGMPBaseName)
    puts '** Configure GMP for compilation ...'
    exec_cmd "sh ./configure --prefix=#{lGMPInstallDir}"
    puts '** Compile GMP ...'
    exec_cmd 'make'
    puts "** Install locally GMP in #{lGMPInstallDir} ..."
    exec_cmd 'make install'
  ensure
    Dir.chdir(lOldDir)
  end

  puts "**** GMP installed correctly in #{lGMPInstallDir}."
  puts ''
end

#exec_cmd(iCmd) ⇒ Object

Execute a command, with nice logging and error handling around

Parameters:

  • iCmd (String): Command to execute

Raises:

  • (RuntimeError)


36
37
38
39
40
# File 'ext/WSK/CommonBuild.rb', line 36

def exec_cmd(iCmd)
  puts "[#{Dir.getwd}]> #{iCmd}"
  raise RuntimeError, "Unable to execute \"#{iCmd}\" on your system." if !system(iCmd)
  puts ''
end

#find_gmpObject

Look for GMP in system and locally If it is found, compilation and link options will include it

Return:

  • Boolean: Has GMP been found?



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/WSK/CommonBuild.rb', line 83

def find_gmp
  rSuccess = have_library('gmp','mpz_get_str','gmp.h')

  if (!rSuccess)
    # Find locally installed GMP
    lGMPDir = File.expand_path("#{File.dirname(__FILE__)}/../../gmp")
    if (File.exist?(lGMPDir))
      lLastInstalledGMP = Dir.glob("#{lGMPDir}/*-install").sort[-1]
      if (lLastInstalledGMP != nil)
        puts "Found GMP installed in #{lLastInstalledGMP}."
        find_header('gmp.h',"#{lLastInstalledGMP}/include")
        find_library('gmp',nil,"#{lLastInstalledGMP}/lib")
        rSuccess = true
      else
        puts 'Could not find GMP library installed locally.'
      end
    end
  end

  return rSuccess
end