Rakefile 4.5 KB
Newer Older
1
# encoding: utf-8
2 3
# Build description.
# 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

7 8 9 10
# load build systems
load "#{MRUBY_ROOT}/tasks/ruby_ext.rake"
load "#{MRUBY_ROOT}/tasks/mruby_build.rake"
load "#{MRUBY_ROOT}/tasks/mrbgem_spec.rake"
11

12
# load configuration file
Yuichiro MASUI's avatar
Yuichiro MASUI committed
13 14
MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
load MRUBY_CONFIG
15

16
# load basic rules
17 18 19
MRuby.each_target do |build|
  build.define_rules
end
20

21 22 23 24 25 26 27
# load custom rules
load "#{MRUBY_ROOT}/src/mruby_core.rake"
load "#{MRUBY_ROOT}/mrblib/mrblib.rake"
load "#{MRUBY_ROOT}/tools/mrbc/mrbc.rake"

load "#{MRUBY_ROOT}/tasks/mrbgems.rake"
load "#{MRUBY_ROOT}/tasks/libmruby.rake"
28

29 30
load "#{MRUBY_ROOT}/tasks/mrbgems_test.rake"
load "#{MRUBY_ROOT}/test/mrbtest.rake"
31

32
##############################
33 34
# generic build targets, rules
task :default => :all
35

cremno's avatar
cremno committed
36 37 38
bin_path = "#{MRUBY_ROOT}/bin"
FileUtils.mkdir_p bin_path, { :verbose => $verbose }

39
depfiles = MRuby.targets['host'].bins.map do |bin|
cremno's avatar
cremno committed
40
  install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
41 42 43
  source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")

  file install_path => source_path do |t|
44
    FileUtils.rm_f t.name, { :verbose => $verbose }
45
    FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
46
  end
47

48
  install_path
49
end
50

51
MRuby.each_target do |target|
Masaki Muranaka's avatar
Masaki Muranaka committed
52
  gems.map do |gem|
53 54 55 56
    current_dir = gem.dir.relative_path_from(Dir.pwd)
    relative_from_root = gem.dir.relative_path_from(MRUBY_ROOT)
    current_build_dir = "#{build_dir}/#{relative_from_root}"

Masaki Muranaka's avatar
Masaki Muranaka committed
57
    gem.bins.each do |bin|
58
      exec = exefile("#{build_dir}/bin/#{bin}")
59
      objs = Dir.glob("#{current_dir}/tools/#{bin}/*.{c,cpp,cxx,cc}").map { |f| objfile(f.pathmap("#{current_build_dir}/tools/#{bin}/%n")) }
60 61 62 63 64 65 66

      file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
        gem_flags = gems.map { |g| g.linker.flags }
        gem_flags_before_libraries = gems.map { |g| g.linker.flags_before_libraries }
        gem_flags_after_libraries = gems.map { |g| g.linker.flags_after_libraries }
        gem_libraries = gems.map { |g| g.linker.libraries }
        gem_library_paths = gems.map { |g| g.linker.library_paths }
take_cheeze's avatar
take_cheeze committed
67
        linker.run t.name, t.prerequisites, gem_libraries, gem_library_paths, gem_flags, gem_flags_before_libraries, gem_flags_after_libraries
68 69
      end

70 71 72 73 74 75 76 77
      if target == MRuby.targets['host']
        install_path = MRuby.targets['host'].exefile("#{MRUBY_ROOT}/bin/#{bin}")

        file install_path => exec do |t|
          FileUtils.rm_f t.name, { :verbose => $verbose }
          FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
        end
        depfiles += [ install_path ]
mimaki's avatar
mimaki committed
78 79 80 81 82 83 84 85 86 87
      elsif target == MRuby.targets['host-debug']
        unless MRuby.targets['host'].gems.map {|g| g.bins}.include?([bin])
          install_path = MRuby.targets['host-debug'].exefile("#{MRUBY_ROOT}/bin/#{bin}")

          file install_path => exec do |t|
            FileUtils.rm_f t.name, { :verbose => $verbose }
            FileUtils.cp t.prerequisites.first, t.name, { :verbose => $verbose }
          end
          depfiles += [ install_path ]
        end
88 89 90
      else
        depfiles += [ exec ]
      end
91 92 93 94
    end
  end
end

95 96 97 98
depfiles += MRuby.targets.map { |n, t|
  [t.libfile("#{t.build_dir}/lib/libmruby")]
}.flatten

99
depfiles += MRuby.targets.reject { |n, t| n == 'host' }.map { |n, t|
100
  t.bins.map { |bin| t.exefile("#{t.build_dir}/bin/#{bin}") }
101
}.flatten
102

103
desc "build all targets, install (locally) in-repo"
104 105 106 107 108 109 110 111
task :all => depfiles do
  puts
  puts "Build summary:"
  puts
  MRuby.each_target do
    print_build_summary
  end
end
112

113
desc "run all mruby tests"
114
task :test => ["all"] + MRuby.targets.values.map { |t| t.build_mrbtest_lib_only? ? t.libfile("#{t.build_dir}/test/mrbtest") : t.exefile("#{t.build_dir}/test/mrbtest") } do
115
  MRuby.each_target do
116
    run_test unless build_mrbtest_lib_only?
117
  end
118 119 120 121
end

desc "clean all built and in-repo installed artifacts"
task :clean do
122
  MRuby.each_target do |t|
123
    FileUtils.rm_rf t.build_dir, { :verbose => $verbose }
124
  end
125
  FileUtils.rm_f depfiles, { :verbose => $verbose }
126 127 128 129 130 131 132 133 134
  puts "Cleaned up target build folder"
end

desc "clean everything!"
task :deep_clean => ["clean"] do
  MRuby.each_target do |t|
    FileUtils.rm_rf t.gem_clone_dir, { :verbose => $verbose }
  end
  puts "Cleaned up mrbgems build folder"
135
end
136 137 138 139 140

desc 'generate document'
task :doc do
  load "#{MRUBY_ROOT}/doc/language/generator.rb"
end