-
Notifications
You must be signed in to change notification settings - Fork 16
/
install.rb
300 lines (257 loc) · 7.11 KB
/
install.rb
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
require 'rbconfig'
require 'fileutils'
require 'rdoc/rdoc'
require 'mkmf'
LINALG_VERSION = "1.0.1"
DLEXT = Config::CONFIG["DLEXT"]
# developer use only
module LinalgPackager
include FileUtils
module Ext
def self.each
[
"ext/lapack",
"ext/linalg",
].each { |dir|
Dir.chdir(dir) { |path|
yield path
}
}
end
end
def _archive(pkgdir, type)
filename = "#{pkgdir}.#{type}"
case type
when :tgz
system("tar zvcf #{filename} #{pkgdir}")
when :zip
system("zip -r #{filename} #{pkgdir}")
else
raise "unknown archive type"
end
system("md5sum #{filename} > #{filename}.md5")
end
def _release(pkgdir, ziptype)
Dir.chdir("..") {
rm_rf pkgdir
cp_r "linalg", pkgdir
rm_rf(Dir.glob("#{pkgdir}/**/CVS") +
Dir.glob("#{pkgdir}/**/.svn") +
["#{pkgdir}/.git"])
_archive(pkgdir, ziptype)
rm_rf pkgdir
}
end
def _release_bin(pkgdir, ziptype)
distclean
config
make
doc
mv "ext/lapack/lapack.#{DLEXT}", "."
mv "ext/linalg/linalg.#{DLEXT}", "."
distclean(false)
mv "lapack.#{DLEXT}", "ext/lapack"
mv "linalg.#{DLEXT}", "ext/linalg"
_release(pkgdir, ziptype)
rm "ext/lapack/lapack.#{DLEXT}"
rm "ext/linalg/linalg.#{DLEXT}"
distclean
end
def release_src
distclean
_release("linalg-#{LINALG_VERSION}", :tgz)
end
def release_bin
pkgdir = "linalg-#{LINALG_VERSION}-#{CONFIG["arch"]}-ruby#{CONFIG["MAJOR"]}#{CONFIG["MINOR"]}"
if pkgdir =~ /mingw32|mswin32/
pkgdir.sub!(/mingw32/, "mswin32")
_release_bin(pkgdir, :zip)
else
_release_bin(pkgdir, :tgz)
end
end
def publish
doc
Dir.chdir("doc") {
args = %w(scp -r . [email protected]:/var/www/gforge-projects/linalg)
puts args.join(" ")
raise unless system(*args)
}
end
end
module Main
include LinalgPackager
include FileUtils
extend self
def doc
rdoc_files = [
'lib/linalg.rb',
'lib/lapack.rb',
'lib/linalg/exception.rb',
'lib/linalg/iterators.rb',
'lib/linalg/dmatrix/main.rb',
] + Dir['lib/linalg/dmatrix/*.rb'].reject { |f|
f =~ %r!/alias.rb$! or f =~ %r!/main.rb$!
} + [
'ext/linalg/dmatrix.c',
'lib/linalg/dmatrix/alias.rb',
'README',
]
rm_rf "doc"
RDoc::RDoc.new.document(
rdoc_files +
["--main", "README",
"--title", "Linalg: Ruby Linear Algebra Library"])
end
def distclean(rmdoc = true)
Ext.each { |path|
puts "distclean #{path}"
if File.exists? "Makefile"
system("#{$make} distclean")
end
}
rm_rf "doc" if rmdoc
rm_f Dir.glob("*.gem")
rm_f Dir.glob("*~")
rm_f Dir.glob("**/*~")
rm_rf Dir.glob("ext/**/conftest.dSYM")
rm_f Dir.glob("ext/**/g2c.h")
rm_f Dir.glob("ext/**/libg2c.a")
rm_f Dir.glob("**/mkmf.log")
end
def make
Ext.each { |path|
puts "make #{path}"
unless system("#{$make}")
raise "compilation failed"
end
}
end
def config
Ext.each { |path|
puts "config #{path}"
unless system("#{$ruby} extconf.rb")
raise "configuration failed"
end
}
end
alias_method :configure, :config
alias_method :extconf, :config
def clean
Ext.each { |path|
puts "clean #{path}"
system("#{$make} clean")
}
end
def test
Dir.chdir("test") {
puts "testing"
system("#{$ruby} -w all.rb")
}
end
def install
sitelibdir = Config::CONFIG["sitelibdir"]
sitearchdir = Config::CONFIG["sitearchdir"]
spec = [
["ext/linalg/linalg.#{DLEXT}", sitearchdir + "/linalg.#{DLEXT}", 0755],
["ext/lapack/lapack.#{DLEXT}", sitearchdir + "/lapack.#{DLEXT}", 0755],
["lib/linalg.rb", sitelibdir + "/linalg.rb", 0644],
] + Dir.glob("lib/linalg/*.rb").map { |f|
[f, sitelibdir + "/linalg/" + File.basename(f), 0644]
} + Dir.glob("lib/linalg/dmatrix/*.rb").map { |f|
[f, sitelibdir + "/linalg/dmatrix/" + File.basename(f), 0644]
}
File.open("InstalledFiles", "w") { |log|
class << log
def puts(*args)
super(*args)
STDOUT.puts(*args)
end
end
spec.each { |f|
mkdir_p File.dirname(f[1]), :mode => 0755
FileUtils.install f[0], f[1], :mode => f[2]
log.puts "install #{f[0]} --> #{f[1]}"
}
}
puts
puts "Installation was successful."
puts "Installed files are recorded in InstalledFiles."
puts "Documentation is in doc/."
end
def uninstall
sitelibdir = Config::CONFIG["sitelibdir"]
sitearchdir = Config::CONFIG["sitearchdir"]
[
sitearchdir + "/lapack.#{DLEXT}",
sitearchdir + "/linalg.#{DLEXT}",
sitelibdir + "/linalg.rb",
sitelibdir + "/linalg/",
"InstalledFiles",
].each { |f|
rm_rf(f)
puts "remove #{f}"
}
end
def setup
make
doc
end
def auto
unless FileTest.exist?("ext/lapack/lapack.#{DLEXT}") and
FileTest.exist?("ext/linalg/linalg.#{DLEXT}")
config
make
doc
end
install
end
action = ARGV.shift || "auto"
send(action, *ARGV)
end
module LinalgGem
include FileUtils
def makegembin
cp "ext/lapack/lapack.#{DLEXT}", "lib"
cp "ext/linalg/linalg.#{DLEXT}", "lib"
mv "doc", "doc-save"
distclean
mv "doc-save", "doc"
_makegem
rm_f Dir.glob("lib/*.#{DLEXT}")
end
def makegem
distclean
_makegem
end
def _makegem
require 'rubygems'
spec = Gem::Specification.new { |s|
s.name = 'linalg'
s.version = LINALG_VERSION
s.summary = <<EOS
Ruby Linear Algebra Library. Advanced linear algebra and fast matrix classes based on classic Fortran routines.
EOS
s.summary.strip!
s.description = <<EOS
linalg is a linear algebra library for real and complex matrices. Current functionality includes: singular value decomposition, eigenvectors and eigenvalues of a general matrix, least squares, LU, QR, Schur, Cholesky, stand-alone LAPACK bindings.
EOS
s.description.strip!
s.files = Dir.glob("**/*").reject { |f|
false or
f =~ %r!CVS$! or
f =~ %r!\.svn$! or
f =~ %r!\.gem$!
}
s.require_path = 'lib'
s.autorequire = 'linalg'
s.has_rdoc = false # requires generated .c files
s.test_suite_file = "test/all.rb"
s.author = "James M. Lawrence"
s.email = "[email protected]"
s.homepage = "http://linalg.rubyforge.org"
s.rubyforge_project = "linalg"
}
Gem::Builder.new(spec).build
end
end