1 | # encoding: utf-8
|
---|
2 | # Build description.
|
---|
3 | # basic build file for mruby
|
---|
4 | MRUBY_ROOT = File.dirname(File.expand_path(__FILE__))
|
---|
5 | MRUBY_BUILD_HOST_IS_CYGWIN = RUBY_PLATFORM.include?('cygwin')
|
---|
6 | MRUBY_BUILD_HOST_IS_OPENBSD = RUBY_PLATFORM.include?('openbsd')
|
---|
7 |
|
---|
8 | Rake.verbose(false) if Rake.verbose == Rake::DSL::DEFAULT
|
---|
9 |
|
---|
10 | $LOAD_PATH << File.join(MRUBY_ROOT, "lib")
|
---|
11 |
|
---|
12 | # load build systems
|
---|
13 | require "mruby-core-ext"
|
---|
14 | require "mruby/build"
|
---|
15 |
|
---|
16 | # load configuration file
|
---|
17 | MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
|
---|
18 | load MRUBY_CONFIG
|
---|
19 |
|
---|
20 | # load basic rules
|
---|
21 | MRuby.each_target do |build|
|
---|
22 | build.define_rules
|
---|
23 | end
|
---|
24 |
|
---|
25 | # load custom rules
|
---|
26 | load "#{MRUBY_ROOT}/src/mruby_core.rake"
|
---|
27 | load "#{MRUBY_ROOT}/mrblib/mrblib.rake"
|
---|
28 |
|
---|
29 | load "#{MRUBY_ROOT}/tasks/mrbgems.rake"
|
---|
30 | load "#{MRUBY_ROOT}/tasks/libmruby.rake"
|
---|
31 |
|
---|
32 | load "#{MRUBY_ROOT}/tasks/benchmark.rake"
|
---|
33 |
|
---|
34 | load "#{MRUBY_ROOT}/tasks/gitlab.rake"
|
---|
35 | load "#{MRUBY_ROOT}/tasks/doc.rake"
|
---|
36 |
|
---|
37 | def install_D(src, dst)
|
---|
38 | rm_f dst
|
---|
39 | mkdir_p File.dirname(dst)
|
---|
40 | cp src, dst
|
---|
41 | end
|
---|
42 |
|
---|
43 | ##############################
|
---|
44 | # generic build targets, rules
|
---|
45 | task :default => :all
|
---|
46 |
|
---|
47 | bin_path = ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin"
|
---|
48 |
|
---|
49 | depfiles = MRuby.targets['host'].bins.map do |bin|
|
---|
50 | install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
|
---|
51 | source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")
|
---|
52 |
|
---|
53 | file install_path => source_path do |t|
|
---|
54 | install_D t.prerequisites.first, t.name
|
---|
55 | end
|
---|
56 |
|
---|
57 | install_path
|
---|
58 | end
|
---|
59 |
|
---|
60 | MRuby.each_target do |target|
|
---|
61 | gems.map do |gem|
|
---|
62 | current_dir = gem.dir.relative_path_from(Dir.pwd)
|
---|
63 | relative_from_root = gem.dir.relative_path_from(MRUBY_ROOT)
|
---|
64 | current_build_dir = File.expand_path "#{build_dir}/#{relative_from_root}"
|
---|
65 |
|
---|
66 | if current_build_dir !~ /^#{Regexp.escape(build_dir)}/
|
---|
67 | current_build_dir = "#{build_dir}/mrbgems/#{gem.name}"
|
---|
68 | end
|
---|
69 |
|
---|
70 | gem.bins.each do |bin|
|
---|
71 | exec = exefile("#{build_dir}/bin/#{bin}")
|
---|
72 | objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) }
|
---|
73 |
|
---|
74 | file exec => objs + target.libraries do |t|
|
---|
75 | gem_flags = gems.map { |g| g.linker.flags }
|
---|
76 | gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
|
---|
77 | gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
|
---|
78 | gem_libraries = gems.map { |g| g.linker.libraries }
|
---|
79 | gem_library_paths = gems.map { |g| g.linker.library_paths }
|
---|
80 | linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries, gem_flags_after_libraries
|
---|
81 |
|
---|
82 | gem.call_post_build_event target
|
---|
83 | end
|
---|
84 |
|
---|
85 | if target == MRuby.targets['host']
|
---|
86 | install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
|
---|
87 |
|
---|
88 | file install_path => exec do |t|
|
---|
89 | install_D t.prerequisites.first, t.name
|
---|
90 | end
|
---|
91 | depfiles += [ install_path ]
|
---|
92 | elsif target == MRuby.targets['host-debug']
|
---|
93 | unless MRuby.targets['host'].gems.map {|g| g.bins}.include?([bin])
|
---|
94 | install_path = MRuby.targets['host-debug'].exefile("#{bin_path}/#{bin}")
|
---|
95 |
|
---|
96 | file install_path => exec do |t|
|
---|
97 | install_D t.prerequisites.first, t.name
|
---|
98 | end
|
---|
99 | depfiles += [ install_path ]
|
---|
100 | end
|
---|
101 | else
|
---|
102 | depfiles += [ exec ]
|
---|
103 | end
|
---|
104 | end
|
---|
105 | end
|
---|
106 | end
|
---|
107 |
|
---|
108 | depfiles += MRuby.targets.map { |n, t|
|
---|
109 | t.libraries
|
---|
110 | }.flatten
|
---|
111 |
|
---|
112 | depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
|
---|
113 | t.bins.map { |bin| t.exefile("#{t.build_dir}/bin/#{bin}") }
|
---|
114 | }.flatten
|
---|
115 |
|
---|
116 | desc "build all targets, install (locally) in-repo"
|
---|
117 | task :all => depfiles do
|
---|
118 | puts
|
---|
119 | puts "Build summary:"
|
---|
120 | puts
|
---|
121 | MRuby.each_target do
|
---|
122 | print_build_summary
|
---|
123 | end
|
---|
124 | MRuby::Lockfile.write
|
---|
125 | end
|
---|
126 |
|
---|
127 | desc "run all mruby tests"
|
---|
128 | task :test
|
---|
129 | MRuby.each_target do
|
---|
130 | if test_enabled?
|
---|
131 | t = :"test_#{self.name}"
|
---|
132 | task t => ["all"] do
|
---|
133 | run_test
|
---|
134 | end
|
---|
135 | task :test => t
|
---|
136 | end
|
---|
137 |
|
---|
138 | if bintest_enabled?
|
---|
139 | t = :"bintest_#{self.name}"
|
---|
140 | task t => ["all"] do
|
---|
141 | run_bintest
|
---|
142 | end
|
---|
143 | task :test => t
|
---|
144 | end
|
---|
145 | end
|
---|
146 |
|
---|
147 | desc "clean all built and in-repo installed artifacts"
|
---|
148 | task :clean do
|
---|
149 | MRuby.each_target do |t|
|
---|
150 | rm_rf t.build_dir
|
---|
151 | end
|
---|
152 | rm_f depfiles
|
---|
153 | puts "Cleaned up target build folder"
|
---|
154 | end
|
---|
155 |
|
---|
156 | desc "clean everything!"
|
---|
157 | task :deep_clean => ["clean", "clean_doc"] do
|
---|
158 | MRuby.each_target do |t|
|
---|
159 | rm_rf t.gem_clone_dir
|
---|
160 | end
|
---|
161 | puts "Cleaned up mrbgems build folder"
|
---|
162 | end
|
---|