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