forked from shoes/shoes3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
538 lines (467 loc) · 16.4 KB
/
Rakefile
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
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'fileutils'
require 'find'
require 'yaml'
require 'rbconfig'
include FileUtils
APP = YAML.load_file(File.join(ENV['APP'] || ".", "app.yaml"))
# APP['version'] = APP['major'] # for historical reasons
# populate APP[] with uppercase names and string values
APP['VERSION'] = "#{APP['major']}.#{APP['minor']}.#{APP['tiny']}"
APP['MAJOR'] = APP['major'].to_s
APP['MINOR'] = APP['minor'].to_s
APP['TINY'] = APP['tiny'].to_s
APP['NAME'] = APP['release']
APP['DATE'] = Time.now.to_s
APP['PLATFORM'] = RbConfig::CONFIG['arch'] # not correct for cross compile
case APP['revision']
when 'git'
gitp = ENV['GIT'] || "git"
APP['REVISION'] = (`#{gitp} rev-list HEAD`.split.length).to_s
when 'file'
File.open('VERSION.txt', 'r') do |f|
ln = f.read
rev = ln[/r\(\d+\)/]
APP['REVISION'] = "#{rev[/\d+/].to_i + 1}"
end
else
if APP['revision'].kind_of? Fixnum
APP['REVISION'] = APP['revision'].to_s
else
APP['REVISION'] = '9' # make it up
end
end
NAME = APP['shortname'] || APP['name'].downcase.gsub(/\W+/, '')
APPNAME = APP['name'] # OSX needs this
SONAME = 'shoes'
APPARGS = APP['run']
# TODO: Shadow these until replaced with APP[] in env/setup/tasks files
RUBY_SO = RbConfig::CONFIG['RUBY_SO_NAME']
APP['RUBY_SO'] = RbConfig::CONFIG['RUBY_SO_NAME']
RUBY_V = RbConfig::CONFIG['ruby_version']
APP['RUBY_V'] = RbConfig::CONFIG['ruby_version']
SHOES_RUBY_ARCH = RbConfig::CONFIG['arch']
APP['SHOES_RUBY_ARCH'] = RbConfig::CONFIG['arch']
# default exts, gems & locations to build and include - replace with custom.yaml
APP['GEMLOC'] = ""
APP['EXTLOC'] = ""
APP['EXTLIST'] = []
APP['GEMLIST'] = []
APP['Bld_Tmp'] = 'tmp'
APP['Bld_Pre'] = ENV['NFS_ALTP'] if ENV['NFS_ALTP']
if File.exists? "build_target"
CROSS = true
File.open('build_target','r') do |f|
str = f.readline
TGT_ARCH = str.split('=')[1].strip
# is the build output directory outside the shoes3 dir
if APP['Bld_Pre']
TGT_DIR = APP['Bld_Pre']+TGT_ARCH
else
TGT_DIR = TGT_ARCH
end
mkdir_p "#{TGT_DIR}"
BLD_ARGS = {}
# This allows short circuiting the need to load setup and env (and pkg-config overhead)
# Exprimental - no visible performance gain. see make/linux/minlin/env.rb
if File.exists? "#{TGT_DIR}/build.yaml"
$stderr.puts "loading building args"
thsh = YAML.load_file("#{TGT_DIR}/build.yaml")
thsh.each {|k,v| BLD_ARGS[k] = v}
HAVE_BLD = true
else
HAVE_BLD = false
end
end
else
CROSS = false
if ARGV.length == 0 # bare rake w/o a setup called earlier
plt = case RUBY_PLATFORM
when /darwin/ then 'osx'
when /mingw/ then 'win32'
when /linux/ then 'linux'
when /freebsd/ then 'bsd'
end
$stderr.puts "Please Select a #{plt}:setup: target from the"
$stderr.puts " list shown by 'rake -T'"
end
TGT_DIR = 'unknown'
end
BIN = "*.{bundle,jar,o,so,obj,pdb,pch,res,lib,def,exp,exe,ilk}"
#CLEAN.include ["{bin,shoes}/#{BIN}", "req/**/#{BIN}", "#{TGT_DIR}", "*.app"]
#CLEAN.include ["req/**/#{BIN}", "#{TGT_DIR}", "*.app"]
CLEAN.include ["#{TGT_DIR}/libshoes.dll", "#{TGT_DIR}/*shoes.exe",
"#{TGT_DIR}/libshoes.so","#{TGT_DIR}/shoes", "#{TGT_DIR}/shoes-bin",
"#{TGT_DIR}/*.app", "#{TGT_DIR}/#{APP['Bld_tmp']}/**/*.o"]
CLOBBER.include ["#{TGT_DIR}/.DS_Store", "#{TGT_DIR}", "build_target", "cshoes", "shoes/**/*.o"]
# for Host building for target
case RUBY_PLATFORM
when /mingw/
if CROSS
require File.expand_path("make/win32/#{TGT_ARCH}/env")
require File.expand_path("make/win32/#{TGT_ARCH}/tasks")
require File.expand_path("make/win32/#{TGT_ARCH}/stubs")
require File.expand_path("make/win32/#{TGT_ARCH}/setup")
require File.expand_path("make/gems")
require File.expand_path('make/subsys')
else
# just enough to do a rake w/o target
require File.expand_path('make/win32/none/env.rb')
require File.expand_path('make/win32/none/tasks.rb')
end
Builder = MakeMinGW
NAMESPACE = :win32
when /darwin/
if CROSS
# Building tight shoes on OSX for OSX
require File.expand_path("make/darwin/#{TGT_ARCH}/env")
require File.expand_path("make/darwin/#{TGT_ARCH}/tasks")
require File.expand_path("make/darwin/#{TGT_ARCH}/stubs")
require File.expand_path("make/darwin/#{TGT_ARCH}/setup")
require File.expand_path("make/gems")
require File.expand_path("make/subsys")
else
# just enough to do a rake w/o target
require File.expand_path('make/darwin/none/env')
require File.expand_path('make/darwin/none/tasks')
end
Builder = MakeDarwin
NAMESPACE = :osx
when /bsd/
#$stderr.puts "running BSD"
if CROSS
case TGT_ARCH
when /freebsd/
require File.expand_path('make/bsd/freebsd/env')
require File.expand_path('make/bsd/freebsd/tasks')
require File.expand_path('make/bsd/freebsd/setup')
require File.expand_path("make/gems")
require File.expand_path('make/subsys')
when /minbsd/
require File.expand_path('make/bsd/minbsd/env')
require File.expand_path('make/bsd/minbsd/tasks')
require File.expand_path('make/bsd/minbsd/setup')
require File.expand_path('make/subsys')
else
require File.expand_path('make/bsd/none/env')
require File.expand_path('make/bsd/none/tasks')
end
else
require File.expand_path('make/bsd/none/env')
require File.expand_path('make/bsd/none/tasks')
$stderr.puts "Please pick a bsd:setup: target - see rake -T"
end
Builder = MakeBSD
NAMESPACE = :bsd
when /linux/
if CROSS
case TGT_ARCH
when /x86_64-linux/
require File.expand_path('make/linux/x86_64-linux/env')
require File.expand_path('make/linux/x86_64-linux/tasks')
require File.expand_path('make/linux/x86_64-linux/setup')
require File.expand_path("make/gems")
require File.expand_path('make/subsys')
when /i686-linux/
require File.expand_path('make/linux/i686-linux/env')
require File.expand_path('make/linux/i686-linux/tasks')
require File.expand_path('make/linux/i686-linux/setup')
require File.expand_path("make/gems")
require File.expand_path('make/subsys')
when /pi2/
require File.expand_path('make/linux/pi2/env')
require File.expand_path('make/linux/pi2/tasks')
require File.expand_path('make/linux/pi2/setup')
require File.expand_path("make/gems")
require File.expand_path('make/subsys')
when /xarmv6hf/
require File.expand_path('make/linux/xarm6hf/env')
require File.expand_path('make/linux/xarm6hf/tasks')
require File.expand_path('make/gems')
when /xwin7/
require File.expand_path('make/linux/xwin7/env')
require File.expand_path('make/linux/xwin7/tasks')
require File.expand_path('make/linux/xwin7/stubs')
require File.expand_path('make/linux/xwin7/setup')
require File.expand_path('make/linux/xwin7/packdeps')
require File.expand_path('make/gems')
require File.expand_path('make/subsys')
when /xmsys2/
require File.expand_path('make/linux/xmsys2/env')
require File.expand_path('make/linux/xmsys2/tasks')
require File.expand_path('make/linux/xmsys2/stubs')
require File.expand_path('make/linux/xmsys2/packdeps')
require File.expand_path('make/linux/xmsys2/setup')
require File.expand_path('make/gems')
require File.expand_path('make/subsys')
when /minlin/
# This is Loose Shoes setup now known as minlin
if CROSS && HAVE_BLD # shortcut
puts "skipping #{TGT_ARCH} env.rb, setup.rb"
require File.expand_path('make/linux/minlin/tasks')
require File.expand_path('make/subsys')
DLEXT = BLD_ARGS['DLEXT']
CC = BLD_ARGS['CC']
SOLOCS = BLD_ARGS['SOLOCS']
LINUX_CFLAGS = BLD_ARGS['LINUX_CFLAGS']
LINUX_LDFLAGS = BLD_ARGS['LINUX_LDFLAGS']
LINUX_LIBS = BLD_ARGS['LINUX_LIBS']
else
#puts "Require All minlin:"
require File.expand_path('make/linux/minlin/env')
require File.expand_path('make/linux/minlin/tasks')
require File.expand_path('make/linux/minlin/setup')
require File.expand_path('make/subsys')
end
else
$stderr.puts "Unknown builder for #{TGT_ARCH}, removing setting"
rm_rf "build_target" if File.exists? "build_target"
end
else
# just enough to do a rake w/o target - will fail with a decent enough
# error message
require File.expand_path('make/linux/none/env')
require File.expand_path('make/linux/none/tasks')
end
Builder = MakeLinux
NAMESPACE = :linux
else
puts "Sorry, your platform [#{RUBY_PLATFORM}] is not supported..."
end
# --------------------------
# common platform tasks
desc "Same as `rake build'"
task :default => [:build]
desc "Package Shoes for distribution"
task :package => [:version, :installer]
task :build_os => ["#{TGT_DIR}/#{NAME}"]
task "shoes/version.h" do |t|
File.open(t.name, 'w') do |f|
f << "#ifndef SHOES_VERSION_H\n"
f << "#define SHOES_VERSION_H\n\n"
f << "// compatatibily pre 3.2.22\n"
f << "#define SHOES_RELEASE_ID #{APP['MAJOR']}\n"
f << "#define SHOES_REVISION #{APP['REVISION']}\n"
f << "#define SHOES_RELEASE_NAME \"#{APP['NAME']}\"\n"
f << "#define SHOES_BUILD_DATE \"#{APP['DATE']}\"\n"
f << "#define SHOES_PLATFORM \"#{SHOES_RUBY_ARCH}\"\n"
f << "// post 3.2.22\n"
f << "#define SHOES_VERSION_NUMBER \"#{APP['VERSION']}\"\n"
f << "#define SHOES_VERSION_MAJOR #{APP['MAJOR']}\n"
f << "#define SHOES_VERSION_MINOR #{APP['MINOR']}\n"
f << "#define SHOES_VERSION_TINY #{APP['TINY']}\n"
f << "#define SHOES_VERSION_NAME \"#{APP['NAME']}\"\n"
f << "#define SHOES_VERSION_REVISION #{APP['REVISION']}\n"
f << "#define SHOES_VERSION_DATE \"#{APP['DATE']}\"\n"
f << "#define SHOES_VERSION_PLATFORM \"#{APP['PLATFORM']}\"\n"
if CROSS && (!TGT_DIR[/minlin/] && !TGT_DIR[/minbsd/])
f << "#define SHOES_STYLE \"TIGHT_SHOES\"\n\n"
else
f << "#define SHOES_STYLE \"LOOSE_SHOES\"\n\n"
end
f << "extern VALUE cTypes;\n"
f << "\nvoid shoes_version_init();\n\n"
f << "#endif\n"
end
end
# TODO: Left for historical reasons (aka OSX)
task "#{TGT_DIR}/VERSION.txt" do |t|
File.open(t.name, 'w') do |f|
f << %{shoes #{RELEASE_NAME.downcase} (0.r#{REVISION}) [#{SHOES_RUBY_ARCH} Ruby#{RUBY_V}]}
%w[DEBUG].each { |x| f << " +#{x.downcase}" if ENV[x] }
f << "\n"
end
end
#TODO: should the following be a task or file?
file "shoes/types/types.h" do |t|
puts "Processing #{t.name}..."
rm_rf "shoes/types/types.h" if File.exists? "shoes/types/types.h"
headers = Dir["shoes/types/*.h"] - ["shoes/types/types.h"]
content = headers.collect { |file|
File.read(file).scan(/shoes_[[:alnum:]_]+_init\(\);/)
}.flatten
File.open(t.name, 'w') do |f|
headers.sort.each { |header|
f << "#include \"#{header}\"\n"
}
f << "\n#define SHOES_TYPES_INIT \\\n#{content.sort.collect { |n| "\t#{n}" }.join(" \\\n") }\n"
end
end
def create_version_file file_path
File.open(file_path, 'w') do |f|
f << "shoes #{APP['NAME'].downcase} #{APP['VERSION']} r(#{APP['REVISION']}) #{APP['PLATFORM']} #{APP['DATE']}"
f << "\n"
end
end
# TODO: called from osx(s) copy_files_to_dist in task.rb
def osx_version_txt t
create_version_file t
end
desc "create VERSION.txt"
task :version do
create_version_file 'VERSION.txt'
end
# --------------------------
# tasks depending on Builder = MakeLinux|MakeDarwin|MakeMinGW
desc "Build using your OS setup"
task :build => ["#{NAMESPACE}:build"]
# ------ new build --------
rtp = "#{TGT_DIR}/#{APP['Bld_Tmp']}"
file "#{rtp}/zzsetup.done" do
Builder.static_setup SOLOCS
Builder.copy_gems #used to be common_build, located in make/gems.rb
Builder.setup_system_resources
touch "#{rtp}/zzsetup.done"
$stderr.puts "Build Products in #{rtp}"
end
#These tasks create object files:
SubDirs = ["#{rtp}/zzbase.done", "#{rtp}/http/zzdownload.done",
"#{rtp}/plot/zzplot.done", "#{rtp}/console/zzconsole.done",
"#{rtp}/types/zzwidgets.done", "#{rtp}/native/zznative.done"]
# Windows doesn't use console - don't try to build it. Delete from dependcies
case TGT_DIR
when /win7/, /xwin7/, /msys2/, /xmsys2/
SubDirs.delete("#{rtp}/console/zzconsole.done")
end
# These tasks copy updated Shoes lib/*/*.rb files and samples and the manual
StaticDirs = ["#{rtp}/copyonly/zzmanual.done", "#{rtp}/copyonly/zzshoesrb.done",
"#{rtp}/copyonly/zzshoesrblib.done", "#{rtp}/copyonly/zzsimple.done",
"#{rtp}/copyonly/zzgood.done", "#{rtp}/copyonly/zzexpert.done"]
file "#{TGT_DIR}/libshoes.#{DLEXT}" => ["#{rtp}/zzsetup.done", "shoes/types/types.h",
"shoes/version.h"] + SubDirs + StaticDirs do
# need to compile version.c -> .o (and create the verion.h for every build)
sh "#{CC} -o #{rtp}/version.o -I. -c #{LINUX_CFLAGS} shoes/version.c"
Builder.new_so "#{TGT_DIR}/libshoes.#{DLEXT}"
end
# rake build (or just rake) will get here.
task :new_build => "#{TGT_DIR}/libshoes.#{DLEXT}" do
# We can link shoes now - this will be done via a Builder call
# because it's platform specific.
Builder.new_link "#{TGT_DIR}/shoes"
end
desc "Not Recommended! Install min Shoes in your ~/.shoes Directory"
task :install do
if ! (TGT_DIR[/minlin/] || TGT_DIR[/minbsd/])
puts "Sorry. You can't do an install of your source built Tight Shoes"
puts " Install the 'rake package' distro just like a user does."
else
create_version_file "#{TGT_DIR}/VERSION.txt"
#Builder.copy_files_to_dist
Builder.make_userinstall
end
end
directory "#{TGT_DIR}" # was 'dist'
def cc(t)
$stderr.puts "compiling #{t}"
sh "#{CC} -I. -c -o #{t.name} #{LINUX_CFLAGS} #{t.source}"
end
rule ".o" => ".m" do |t|
cc t
end
rule ".o" => ".c" do |t|
cc t
end
task :installer => ["#{NAMESPACE}:installer"]
namespace :osx do
namespace :setup do
#desc "Setup to build Shoes for 10.10+"
#task :yosemite do
# sh "echo 'TGT_ARCH=yosemite' >build_target"
#end
desc "Setup to build Shoes for 10.9+ from 10.10+"
task :xmavericks do
sh "echo 'TGT_ARCH=xmavericks' >build_target"
end
#desc "Setup to build Shoes for 10.9+ from 10.9"
#task :mavericks do
# sh "echo 'TGT_ARCH=mavericks' >build_target"
#end
#desc "Setup to build for 10.6+ from 10.6"
#task :snow do
# sh "echo 'TGT_ARCH=snow' >build_target"
#end
#desc "Downshift Build 10.6 from 10.9"
#task "xsnow" do
# sh "echo 'TGT_ARCH=xsnow' >build_target"
#end
end
task :build => [:new_build]
task :installer do
Builder.make_installer
end
end
namespace :win32 do
namespace :setup do
desc "Winodws build with devkit"
task :win7 do
sh "echo TGT_ARCH=win7 >build_target"
end
desc "Windows build with msys2"
task :msys2 do
sh "echo TGT_ARCH=msys2 >build_target"
end
end
task :build => ["build_target", :new_build]
task :installer do
Builder.make_installer
end
end
namespace :bsd do
namespace :setup do
desc "freebsd 11.1 x86_64"
task :freebsd do
sh "echo 'TGT_ARCH=freebsd' >build_target"
end
desc "freebsd minimal"
task :minbsd do
sh "echo 'TGT_ARCH=minbsd' >build_target"
end
end
task :build => ["build_target", :new_build]
task :installer do
Builder.make_installer
end
end
# get here when rake decides it's running on a linux system
namespace :linux do
namespace :setup do
desc "build non-portable linux"
task :minlin do
sh "echo 'TGT_ARCH=minlin' >build_target"
end
#desc "Cross compile to arm6hf - advanced users"
task :xarm6hf do
sh "echo 'TGT_ARCH=xarmv6hf' >build_target"
end
desc "Native arm build - pi 2+"
task :pi2 do
sh "echo 'TGT_ARCH=pi2' >build_target"
end
#desc "Cross compile for msys2 deps (mingw)"
task :xmsys2 do
puts "Cross compile newer deps (mingw)"
sh "echo 'TGT_ARCH=xmsys2' >build_target"
end
desc "Cross compile with MingW32"
task :xwin7 do
puts "Cross compile for Windows MingW32"
sh "echo 'TGT_ARCH=xwin7' >build_target"
end
desc "chroot build for i686 (32bit linux)"
task :i686_linux do
puts "Cross complile for i686-linux"
sh "echo 'TGT_ARCH=i686-linux' >build_target"
end
desc "chroot build for x86_64 (64bit linux)"
task :x86_64_linux do
puts "Cross complile for x86_64-linux"
sh "echo 'TGT_ARCH=x86_64-linux' >build_target"
end
end
task :build => [:new_build]
task :installer do
Builder.make_installer
end
end