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