[270] | 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 | # load build systems
|
---|
| 9 | load "#{MRUBY_ROOT}/tasks/ruby_ext.rake"
|
---|
| 10 | load "#{MRUBY_ROOT}/tasks/mruby_build.rake"
|
---|
| 11 | load "#{MRUBY_ROOT}/tasks/mrbgem_spec.rake"
|
---|
| 12 |
|
---|
| 13 | # load configuration file
|
---|
| 14 | MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
|
---|
| 15 | load MRUBY_CONFIG
|
---|
| 16 |
|
---|
| 17 | # load basic rules
|
---|
| 18 | MRuby.each_target do |build|
|
---|
| 19 | build.define_rules
|
---|
| 20 | end
|
---|
| 21 |
|
---|
| 22 | # load custom rules
|
---|
| 23 | load "#{MRUBY_ROOT}/src/mruby_core.rake"
|
---|
| 24 | load "#{MRUBY_ROOT}/mrblib/mrblib.rake"
|
---|
| 25 |
|
---|
| 26 | load "#{MRUBY_ROOT}/tasks/mrbgems.rake"
|
---|
| 27 | load "#{MRUBY_ROOT}/tasks/libmruby.rake"
|
---|
| 28 |
|
---|
| 29 | load "#{MRUBY_ROOT}/tasks/benchmark.rake"
|
---|
| 30 |
|
---|
[331] | 31 | load "#{MRUBY_ROOT}/tasks/gitlab.rake"
|
---|
| 32 |
|
---|
[270] | 33 | ##############################
|
---|
| 34 | # generic build targets, rules
|
---|
| 35 | task :default => :all
|
---|
| 36 |
|
---|
| 37 | bin_path = ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin"
|
---|
| 38 | FileUtils.mkdir_p bin_path, { :verbose => $verbose }
|
---|
| 39 |
|
---|
| 40 | depfiles = MRuby.targets['host'].bins.map do |bin|
|
---|
| 41 | install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
|
---|
| 42 | source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")
|
---|
| 43 |
|
---|
| 44 | file install_path => source_path do |t|
|
---|
| 45 | FileUtils.rm_f t.name, { :verbose => $verbose }
|
---|
| 46 | FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
|
---|
| 47 | end
|
---|
| 48 |
|
---|
| 49 | install_path
|
---|
| 50 | end
|
---|
| 51 |
|
---|
| 52 | MRuby.each_target do |target|
|
---|
| 53 | gems.map do |gem|
|
---|
| 54 | current_dir = gem.dir.relative_path_from(Dir.pwd)
|
---|
| 55 | relative_from_root = gem.dir.relative_path_from(MRUBY_ROOT)
|
---|
| 56 | current_build_dir = File.expand_path "#{build_dir}/#{relative_from_root}"
|
---|
| 57 |
|
---|
| 58 | if current_build_dir !~ /^#{build_dir}/
|
---|
| 59 | current_build_dir = "#{build_dir}/mrbgems/#{gem.name}"
|
---|
| 60 | end
|
---|
| 61 |
|
---|
| 62 | gem.bins.each do |bin|
|
---|
| 63 | exec = exefile("#{build_dir}/bin/#{bin}")
|
---|
| 64 | objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) }
|
---|
| 65 |
|
---|
| 66 | file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
|
---|
| 67 | gem_flags = gems.map { |g| g.linker.flags }
|
---|
| 68 | gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
|
---|
| 69 | gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
|
---|
| 70 | gem_libraries = gems.map { |g| g.linker.libraries }
|
---|
| 71 | gem_library_paths = gems.map { |g| g.linker.library_paths }
|
---|
| 72 | linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries, gem_flags_after_libraries
|
---|
| 73 | end
|
---|
| 74 |
|
---|
| 75 | if target == MRuby.targets['host']
|
---|
| 76 | install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
|
---|
| 77 |
|
---|
| 78 | file install_path => exec do |t|
|
---|
| 79 | FileUtils.rm_f t.name, { :verbose => $verbose }
|
---|
| 80 | FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
|
---|
| 81 | end
|
---|
| 82 | depfiles += [ install_path ]
|
---|
| 83 | elsif target == MRuby.targets['host-debug']
|
---|
| 84 | unless MRuby.targets['host'].gems.map {|g| g.bins}.include?([bin])
|
---|
| 85 | install_path = MRuby.targets['host-debug'].exefile("#{bin_path}/#{bin}")
|
---|
| 86 |
|
---|
| 87 | file install_path => exec do |t|
|
---|
| 88 | FileUtils.rm_f t.name, { :verbose => $verbose }
|
---|
| 89 | FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
|
---|
| 90 | end
|
---|
| 91 | depfiles += [ install_path ]
|
---|
| 92 | end
|
---|
| 93 | else
|
---|
| 94 | depfiles += [ exec ]
|
---|
| 95 | end
|
---|
| 96 | end
|
---|
| 97 | end
|
---|
| 98 | end
|
---|
| 99 |
|
---|
| 100 | depfiles += MRuby.targets.map { |n, t|
|
---|
| 101 | [t.libfile("#{t.build_dir}/lib/libmruby")]
|
---|
| 102 | }.flatten
|
---|
| 103 |
|
---|
| 104 | depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
|
---|
| 105 | t.bins.map { |bin| t.exefile("#{t.build_dir}/bin/#{bin}") }
|
---|
| 106 | }.flatten
|
---|
| 107 |
|
---|
| 108 | desc "build all targets, install (locally) in-repo"
|
---|
| 109 | task :all => depfiles do
|
---|
| 110 | puts
|
---|
| 111 | puts "Build summary:"
|
---|
| 112 | puts
|
---|
| 113 | MRuby.each_target do
|
---|
| 114 | print_build_summary
|
---|
| 115 | end
|
---|
| 116 | end
|
---|
| 117 |
|
---|
| 118 | desc "run all mruby tests"
|
---|
| 119 | task :test => ["all"] do
|
---|
| 120 | MRuby.each_target do
|
---|
| 121 | run_test if test_enabled?
|
---|
| 122 | end
|
---|
| 123 | end
|
---|
| 124 |
|
---|
| 125 | desc "clean all built and in-repo installed artifacts"
|
---|
| 126 | task :clean do
|
---|
| 127 | MRuby.each_target do |t|
|
---|
| 128 | FileUtils.rm_rf t.build_dir, { :verbose => $verbose }
|
---|
| 129 | end
|
---|
| 130 | FileUtils.rm_f depfiles, { :verbose => $verbose }
|
---|
| 131 | puts "Cleaned up target build folder"
|
---|
| 132 | end
|
---|
| 133 |
|
---|
| 134 | desc "clean everything!"
|
---|
| 135 | task :deep_clean => ["clean"] do
|
---|
| 136 | MRuby.each_target do |t|
|
---|
| 137 | FileUtils.rm_rf t.gem_clone_dir, { :verbose => $verbose }
|
---|
| 138 | end
|
---|
| 139 | puts "Cleaned up mrbgems build folder"
|
---|
| 140 | end
|
---|
| 141 |
|
---|
| 142 | desc 'generate document'
|
---|
| 143 | task :doc do
|
---|
| 144 | begin
|
---|
| 145 | sh "mrbdoc"
|
---|
| 146 | rescue
|
---|
| 147 | puts "ERROR: To generate documents, you should install yard-mruby gem."
|
---|
| 148 | puts " $ gem install yard-mruby"
|
---|
| 149 | end
|
---|
| 150 | end
|
---|