forked from lballabio/QuantLib-SWIG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.rb.in
174 lines (157 loc) · 5.12 KB
/
setup.rb.in
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
173
=begin
Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
Copyright (C) 2003, 2004, 2005, 2006, 2007 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
<[email protected]>. The license is also available online at
<http://quantlib.org/license.shtml>.
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 'fileutils'
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 = "@PACKAGE_VERSION@"
cfg = RbConfig::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 = RbConfig::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 += " /MD"
$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 = RbConfig::CONFIG["prefix"]
if defined? Debian
archDir = RbConfig::CONFIG["archdir"]
libDir = RbConfig::CONFIG["rubylibdir"]
else
archDir = RbConfig::CONFIG["sitearchdir"]
libDir = RbConfig::CONFIG["sitelibdir"]
end
archDir = Prefix + archDir.gsub(/^#{oldPrefix}/,"")
libDir = Prefix + libDir.gsub(/^#{oldPrefix}/,"")
else
archDir = RbConfig::CONFIG["sitearchdir"]
libDir = RbConfig::CONFIG["sitelibdir"]
end
[archDir,libDir].each { |path| FileUtils.makedirs path }
if cfg['host_os'][0..5] == 'darwin'
binary = 'QuantLibc.bundle'
else
binary = 'QuantLibc.so'
end
FileUtils.install "./"+binary, archDir+"/"+binary, :mode => 0555, :verbose => true
FileUtils.install "./QuantLib.rb", libDir+"/QuantLib.rb", :mode => 0555, :verbose => true
}
availableCommands = {
"wrap" => Wrap,
"build" => Build,
"test" => RunTests,
"install" => Install }
availableCommands[cmd].execute