forked from MacRuby/MacRuby
/
install.rake
368 lines (304 loc) · 10.4 KB
/
install.rake
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
require 'fileutils'
module Installer
include FileUtils
# Hard coded
def prog_mode; 0755; end
def dir_mode; 0755; end
def data_mode; 0644; end
def script_mode; 0775; end
def made_dirs
@made_dirs ||= []
end
def with_destdir dir
return dir if !DESTDIR or DESTDIR.empty?
return DESTDIR + dir
end
def ln_sf src, dest
super(src, with_destdir(dest))
# puts dest
end
def ln_sfh src, dest
ln_sf(src, dest) unless File.symlink?(with_destdir(dest))
end
def install src, dest, opts = {}
strip = opts.delete :strip
opts[:preserve] = true
super(src, with_destdir(dest), opts)
if made_dirs.include? dest
dest = File.join(dest, File.basename(src))
end
#puts dest
if strip
system("/usr/bin/strip -x '#{File.join(with_destdir(dest), File.basename(src))}'")
end
end
def makedirs *dirs
dirs.collect! do |dir|
realdir = with_destdir(dir)
realdir unless made_dirs.include?(dir) do
made_dirs << dir
# puts File.join(dir, '')
File.directory?(realdir)
end
end.compact!
super(dirs, :mode => dir_mode) unless dirs.empty?
end
def install_recursive srcdir, dest, options = {}
opts = options.clone
noinst = Array(opts.delete(:no_install))
glob = opts.delete(:glob) || '*'
subpath = srcdir.size..-1
Dir.glob("#{srcdir}/**/#{glob}") do |src|
base = File.basename(src)
next if base.match(/\A\#.*\#\z/) or base.match(/~\z/)
next if noinst.any? { |n| File.fnmatch?(n, base) }
d = dest + src[subpath]
if File.directory?(src)
makedirs(d)
else
makedirs(File.dirname(d))
install src, d, opts
end
end
end
def open_for_install path, mode
data = begin
open(realpath = with_destdir(path), 'rb') { |f| f.read }
rescue
nil
end
newdata = yield
unless newdata == data
open(realpath, 'wb', mode) { |f| f.write newdata }
end
File.chmod(mode, realpath)
puts 'Wrote ' + path
end
def dylib
"lib#{RUBY_SO_NAME}.#{NEW_RUBY_VERSION}.dylib"
end
def static
"lib#{RUBY_SO_NAME}-static.a"
end
def ruby_shebang
"#{FRAMEWORK_USR_BIN}/#{RUBY_INSTALL_NAME}"
end
def man_dir
"#{FRAMEWORK_USR_SHARE}/man"
end
def ri_dir
"#{FRAMEWORK_USR_SHARE}/ri/#{NEW_RUBY_VERSION}/system"
end
def lib_dir
"#{FRAMEWORK_USR_LIB}/ruby/#{NEW_RUBY_VERSION}"
end
def arch_lib_dir
"#{lib_dir}/#{NEW_RUBY_PLATFORM}"
end
def header_dir
"#{FRAMEWORK_USR}/include/ruby-#{NEW_RUBY_VERSION}"
end
def ruby_header_dir
"#{header_dir}/ruby"
end
def arch_header_dir
"#{header_dir}/#{NEW_RUBY_PLATFORM}"
end
def xcode_dir
`xcode-select -print-path`.chomp
end
def xcode_example_dir
"#{xcode_dir}/Examples/Ruby/MacRuby"
end
def xcode3_template_dir
'/Library/Application Support/Developer/3.0/Xcode'
end
def xcode4_template_dir
"#{xcode_dir}/Library/Xcode/Templates"
end
def xcode_usr_bin
"#{xcode_dir}/usr/bin"
end
def dest_bin
"#{SYM_INSTDIR}/bin"
end
def dest_man
"#{SYM_INSTDIR}/share/man"
end
end
namespace :install do
extend Installer
task :all => [:bin, :scripts, :lib, :ext, :headers, :doc, :man, :resources, :xcode_support]
desc 'Install MacRuby binaries'
task :bin do
puts 'Installing the macruby binary command'
makedirs FRAMEWORK_USR_BIN, FRAMEWORK_USR_LIB, arch_lib_dir
install RUBY_INSTALL_NAME, FRAMEWORK_USR_BIN, :mode => prog_mode, :strip => true
install 'rbconfig.rb', arch_lib_dir, :mode => data_mode
install 'rbconfig.rbo', arch_lib_dir, :mode => data_mode
install dylib, FRAMEWORK_USR_LIB, :mode => prog_mode, :strip => true
if File.exists?(static)
install static, FRAMEWORK_USR_LIB, :mode => data_mode, :strip => true
end
for link in DYLIB_ALIASES.split
ln_sf(dylib, File.join(FRAMEWORK_USR_LIB, link))
end
puts 'Installing LLVM tools'
install "#{LLVM_PATH}/bin/llc", "#{FRAMEWORK_USR_BIN}/llc", :mode => prog_mode
end
desc 'Install command scripts (e.g. macirb)'
task :scripts do
puts 'Installing command scripts'
makedirs FRAMEWORK_USR_BIN
for src in Dir['bin/*']
next unless File.file?(src)
next if /\/[.#]|(\.(old|bak|orig|rej|diff|patch|core)|~|\/core)$/i =~ src
bname = File.basename(src)
name = case bname
when 'rb_nibtool'
bname
else
RUBY_INSTALL_NAME.sub(/ruby/, bname)
end
shebang = ''
body = ''
open(src, 'rb') do |f|
shebang = f.gets
body = f.read
end
shebang.sub!(/^\#!.*?ruby\b/) { '#!' + ruby_shebang }
shebang.sub!(/\r$/, '')
body.gsub!(/\r$/, '')
cmd = File.join(FRAMEWORK_USR_BIN, name)
open_for_install(cmd, script_mode) do
shebang + body
end
end
end
desc 'Install the standard library'
task :lib do
makedirs lib_dir
for file in Dir['lib/**/*{.rb,.rbo,help-message}']
dir = File.dirname(file).sub!(/\Alib/, lib_dir) || lib_dir
makedirs dir
install file, dir, :mode => data_mode
end
end
desc 'Install the C extensions'
task :ext do
Builder::Ext.install
# Install the extensions rbo.
Dir.glob('ext/**/lib/**/*.rbo').each do |path|
ext_name, sub_path = path.scan(/^ext\/(.+)\/lib\/(.+)$/)[0]
next unless EXTENSIONS.include?(ext_name)
sub_dir = File.dirname(sub_path)
install path, "#{RUBY_SITE_LIB2}/#{sub_dir}", :mode => prog_mode
end
puts 'Installing Extension Objects'
makedirs arch_lib_dir, RUBY_SITE_LIB2, RUBY_VENDOR_ARCHLIB, arch_header_dir
install_recursive "#{EXTOUT}/#{NEW_RUBY_PLATFORM}", arch_lib_dir, :mode => prog_mode
install_recursive "#{EXTOUT}/include/#{NEW_RUBY_PLATFORM}", arch_header_dir, :glob => '*.h', :mode => data_mode
puts 'Installing extensions scripts'
makedirs lib_dir, RUBY_SITE_LIB2, RUBY_VENDOR_LIB2, ruby_header_dir
install_recursive "#{EXTOUT}/common", lib_dir, :mode => data_mode
install_recursive "#{EXTOUT}/include/ruby", ruby_header_dir, :glob => '*.h', :mode => data_mode
end
desc 'Install the MacRuby headers'
task :headers do
puts 'Installing headers'
makedirs header_dir
install_recursive 'include', header_dir, :glob => '*.h', :mode => data_mode
end
desc 'Install RDoc and RI documentation'
task :doc do
puts 'Installing RI data'
makedirs ri_dir
install_recursive 'doc/', ri_dir, :mode => data_mode
end
desc 'Install the MacRuby man pages'
task :man do
puts 'Installing man pages'
for mdoc in Dir['*.[1-9]']
# TODO is this check really needed?
next unless File.file?(mdoc) and open(mdoc){ |fh| fh.read(1) == '.' }
destdir = File.join(man_dir, "man#{mdoc[/(\d+)$/]}")
destfile = File.join(destdir, mdoc.sub(/^/, 'mac'))
makedirs destdir
install mdoc, destfile, :mode => data_mode
end
end
desc 'Install the MacRuby.framework Info.plist file'
task :resources do
puts 'Installing framework resources'
makedirs FRAMEWORK_RESOURCES
install File.join('framework/Info.plist'), FRAMEWORK_RESOURCES, :mode => data_mode
resources = File.join(FRAMEWORK_RESOURCES, 'English.lproj')
makedirs resources
install File.join('framework/InfoPlist.strings'), resources, :mode => data_mode
if File.symlink?(with_destdir(File.join(FRAMEWORK_VERSION, '..', 'Current')))
rm_f File.join(FRAMEWORK_VERSION, '..', 'Current')
end
ln_sfh INSTALL_VERSION.to_s, File.join(FRAMEWORK_VERSION, '..', 'Current')
ln_sfh 'Versions/Current/Headers', File.join(FRAMEWORK_VERSION, '../../Headers')
ln_sfh 'Versions/Current/MacRuby', File.join(FRAMEWORK_VERSION, '../../MacRuby')
ln_sfh 'Versions/Current/Resources', File.join(FRAMEWORK_VERSION, '../../Resources')
ln_sfh "usr/lib/#{dylib}", File.join(FRAMEWORK_VERSION, 'MacRuby')
ln_sfh "usr/include/ruby-#{NEW_RUBY_VERSION}", File.join(FRAMEWORK_VERSION, 'Headers')
ln_sfh "../#{NEW_RUBY_PLATFORM}/ruby/config.h",
File.join(FRAMEWORK_VERSION, "usr/include/ruby-#{NEW_RUBY_VERSION}/ruby/config.h")
puts 'Installing executable symlinks'
makedirs dest_bin
Dir.entries(with_destdir(FRAMEWORK_USR_BIN)).each do |file|
next if file.match(/^\./)
# Except rb_nibtool & llc!
next if file == 'rb_nibtool' or file == 'llc'
link = File.join('../../../', FRAMEWORK_USR_BIN, file)
link.sub!(/#{INSTALL_VERSION}/, 'Current')
link_dest = File.join(dest_bin, File.basename(file))
unless File.exists?(link_dest)
ln_sfh link, link_dest
end
end
puts 'Installing man page symlinks'
makedirs dest_man
Dir.entries(with_destdir(man_dir)).each do |man_set|
next if man_set.match(/^\./)
if File.stat(File.join(with_destdir(man_dir), man_set)).directory?
makedirs File.join(dest_man, File.basename(man_set))
Dir.entries(File.join(with_destdir(man_dir), man_set)).each do |man_file|
next if man_file.match(/^\./)
link = File.join('../../../../../', man_dir, man_set, man_file)
link.sub!(/#{INSTALL_VERSION}/, 'Current')
link_dest = File.join(dest_man, File.basename(man_set), File.basename(man_file))
unless File.exists?(link_dest)
ln_sfh link, link_dest
end
end
else
link = File.join('../../../../', man_dir, man_set)
link.sub!(/#{INSTALL_VERSION}/, 'Current')
ln_sfh link, File.join(dest_man, File.basename(man_set))
end
end
end
desc 'Install all Xcode related things'
task :xcode_support => [:nibtool, :xcode_templates, :xcode_samples]
task :nibtool do
puts 'Installing IB support'
makedirs xcode_usr_bin
ln_sfh File.join('../../..', FRAMEWORK_USR_BIN, 'rb_nibtool'), xcode_usr_bin
end
task :xcode_templates do
# TODO only install templates for installed Xcodes
puts 'Installing XCode templates'
makedirs xcode4_template_dir
install_recursive 'misc/xcode4-templates', xcode4_template_dir, :mode => prog_mode
makedirs xcode3_template_dir
install_recursive 'misc/xcode-templates', xcode3_template_dir, :mode => prog_mode
end
task :xcode_samples do
puts 'Installing MacRuby sample projects'
makedirs xcode_example_dir
install_recursive 'sample-macruby', xcode_example_dir, :mode => script_mode
end
end