1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
=begin
Copyright (C) 2000-2006 StatPro Italia srl
This file is part of QuantLib, a free-software/open-source library
for financial quantitative analysts and developers - http://quantlib.org/
QuantLib is free software: you can redistribute it and/or modify it under the
terms of the QuantLib license. You should have received a copy of the
license along with this program; if not, please email quantlib-dev@lists.sf.net
The license is also available online at http://quantlib.org/html/license.html
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the license for more details.
=end
require 'rbconfig'
require 'mkmf'
require 'ftools'
def usage
puts <<EOU
Usage: ruby setup.rb command [options]
Commands:
wrap generate wrappers from SWIG interfaces
build build QuantLib-Ruby
install [--prefix=path] [--debian] install QuantLib-Ruby in path
sdist create source distribution
bdist create binary distribution
clean clean up
EOU
exit
end
# parse command line
cmd = ARGV.shift or usage()
cmd = cmd.downcase
usage() unless ['wrap','build','test','install',
'sdist','bdist','clean'].member? cmd
if cmd != "install"
usage() if ARGV.shift
else
opt = ARGV.shift
while opt
if opt[0...9] == "--prefix="
Prefix = opt[9..-1]
elsif opt[0...8] == "--debian"
Debian = true
else
usage()
end
opt = ARGV.shift
end
end
# Current QuantLib version
Version = "0.3.13"
cfg = Config::MAKEFILE_CONFIG
# commands
class Command
def initialize(&block)
@block = block
end
def execute
@block.call
end
end
Wrap = Command.new {
swigDir = "../SWIG"
cmd = "swig -ruby -c++ -I#{swigDir} -o ./quantlib_wrap.cpp quantlib.i"
puts cmd
system cmd
}
Build = Command.new {
cfg = Config::MAKEFILE_CONFIG
if cfg['host_os'] == 'mswin32'
QL_DIR = ENV['QL_DIR']
if QL_DIR
$CPPFLAGS += " /I#{QL_DIR}"
$LIBPATH += ["#{QL_DIR}\\lib"]
else
puts 'warning: unable to detect QuantLib installation'
puts 'I will assume that it was added to the default compiler paths'
end
$CPPFLAGS += " /MT"
$CPPFLAGS += " /GR"
$CPPFLAGS += " /GX"
$CPPFLAGS += " /Zm250"
$CPPFLAGS += " /DNOMINMAX"
else
$CFLAGS += " " + (ENV['CFLAGS'] || "")
$CPPFLAGS += " " + IO.popen("quantlib-config --cflags").gets.strip
$CPPFLAGS += " -Wno-uninitialized -Wno-unused"
$CPPFLAGS += " " + (ENV['CXXFLAGS'] || "")
$CPPFLAGS += " -DBOOST_DISABLE_THREADS"
$libs += " " + IO.popen("quantlib-config --libs").gets.strip
old_cc = cfg['CC']
cfg['CC'] = ENV['CXX'] || "g++"
cfg['CPP'].sub!(old_cc,cfg['CC'])
cfg['LDSHARED'].sub!(old_cc,cfg['CC'])
if cfg['host_os'][0..5] =='darwin'
cfg['LDSHARED'].sub!('cc',cfg['CC'])
cfg['LDSHARED'] += " -flat_namespace -undefined suppress"
end
end
# we have to juggle files as create_makefile is stubborn about file names
if File.exists?("Makefile")
File.rename("Makefile","Makefile.old")
end
create_makefile("QuantLibc")
File.rename("Makefile","extension.mak")
if File.exists?("Makefile.old")
File.rename("Makefile.old", "Makefile")
end
if cfg['host_os'] == 'mswin32'
system("nmake /f extension.mak")
else
system("make -f extension.mak")
end
}
RunTests = Command.new {
Build.execute
puts "Testing QuantLib-Ruby #{Version}..."
$LOAD_PATH.unshift Dir.pwd
Dir.chdir 'test'
load 'QuantLibTestSuite.rb'
Dir.chdir '..'
$LOAD_PATH.shift
}
Install = Command.new {
Build.execute
if defined? Prefix
# strip old prefix and add the new one
oldPrefix = Config::CONFIG["prefix"]
if defined? Debian
archDir = Config::CONFIG["archdir"]
libDir = Config::CONFIG["rubylibdir"]
else
archDir = Config::CONFIG["sitearchdir"]
libDir = Config::CONFIG["sitelibdir"]
end
archDir = Prefix + archDir.gsub(/^#{oldPrefix}/,"")
libDir = Prefix + libDir.gsub(/^#{oldPrefix}/,"")
else
archDir = Config::CONFIG["sitearchdir"]
libDir = Config::CONFIG["sitelibdir"]
end
[archDir,libDir].each { |path| File.makedirs path }
if cfg['host_os'][0..5] == 'darwin'
binary = 'QuantLibc.bundle'
else
binary = 'QuantLibc.so'
end
File.install "./"+binary, archDir+"/"+binary, 0555, true
File.install "./QuantLib.rb", libDir+"/QuantLib.rb", 0555, true
}
availableCommands = {
"wrap" => Wrap,
"build" => Build,
"test" => RunTests,
"install" => Install }
availableCommands[cmd].execute
|