Commit 87d0630d authored by Yukihiro "Matz" Matsumoto's avatar Yukihiro "Matz" Matsumoto

Merge pull request #876 from masuidrive/fixed_build_system

Support to build on pwd != mruby source root
parents 58b9e767 0970ca95
# encoding: utf-8
# Build description.
# basic build file for mruby
MRUBY_ROOT = File.dirname(File.expand_path(__FILE__))
load 'tasks/ruby_ext.rake'
load 'tasks/mruby_build.rake'
load 'tasks/mrbgem_spec.rake'
# load build systems
load "#{MRUBY_ROOT}/tasks/ruby_ext.rake"
load "#{MRUBY_ROOT}/tasks/mruby_build.rake"
load "#{MRUBY_ROOT}/tasks/mrbgem_spec.rake"
##############################
# compile flags
load 'build_config.rb'
MRUBY_CONFIGS = ['build_config.rb']
if ENV['MRUBY_CONFIG']
MRUBY_CONFIGS << ENV['MRUBY_CONFIG']
load ENV['MRUBY_CONFIG']
# load configuration file
MRUBY_CONFIGS = ["#{MRUBY_ROOT}/build_config.rb", ENV['MRUBY_CONFIG']].compact
MRUBY_CONFIGS.each do |config|
load config unless config.empty?
end
# load basic rules
MRuby.each_target do |build|
build.define_rules
end
load 'src/mruby_core.rake'
load 'mrblib/mrblib.rake'
load 'tools/mrbc/mrbc.rake'
# 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"
load "#{MRUBY_ROOT}/tools/mruby/mruby.rake"
load "#{MRUBY_ROOT}/tools/mirb/mirb.rake"
load 'tasks/mrbgems.rake'
load 'tasks/libmruby.rake'
load 'tools/mruby/mruby.rake'
load 'tools/mirb/mirb.rake'
load "#{MRUBY_ROOT}/tasks/mrbgems_test.rake"
load "#{MRUBY_ROOT}/test/mrbtest.rake"
load 'tasks/mrbgems_test.rake'
load 'test/mrbtest.rake'
##############################
# generic build targets, rules
task :default => :all
depfiles = MRuby.targets['host'].bins.map do |bin|
install_path = MRuby.targets['host'].exefile("bin/#{bin}")
file install_path => MRuby.targets['host'].exefile("build/host/bin/#{bin}") do |t|
FileUtils.rm t.name, :force => true
install_path = MRuby.targets['host'].exefile("#{MRUBY_ROOT}/bin/#{bin}")
source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")
file install_path => source_path do |t|
FileUtils.cp t.prerequisites.first, t.name
end
......
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
self.libmruby << objfile("#{build_dir}/#{dir}/mrblib")
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
self.libmruby << objfile("#{current_build_dir}/mrblib")
file objfile("#{build_dir}/#{dir}/mrblib") => "#{build_dir}/#{dir}/mrblib.c"
file "#{build_dir}/#{dir}/mrblib.c" => [mrbcfile] + Dir.glob("#{dir}/*.rb") do |t|
file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c"
file "#{current_build_dir}/mrblib.c" => [mrbcfile] + Dir.glob("#{current_dir}/*.rb") do |t|
mrbc_, *rbfiles = t.prerequisites
FileUtils.mkdir_p File.dirname(t.name)
open(t.name, 'w') do |f|
_pp "GEN", "*.rb", "#{t.name}"
f.puts File.read("#{dir}/init_mrblib.c")
_pp "GEN", "*.rb", "#{t.name.relative_path}"
f.puts File.read("#{current_dir}/init_mrblib.c")
mrbc.run f, rbfiles, 'mrblib_irep'
end
end
......
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
lex_def = "#{dir}/lex.def"
objs = Dir.glob("src/*.{c}").map { |f| objfile(f.pathmap("#{build_dir}/%X")) } + [objfile("#{build_dir}/#{dir}/y.tab")]
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
lex_def = "#{current_dir}/lex.def"
objs = Dir.glob("#{current_dir}/*.c").map { |f| objfile(f.pathmap("#{current_build_dir}/%n")) }
objs += [objfile("#{current_build_dir}/y.tab")]
self.libmruby << objs
file libfile("#{build_dir}/lib/libmruby_core") => objs do |t|
......@@ -10,16 +13,16 @@ MRuby.each_target do
end
# Parser
file "#{build_dir}/#{dir}/y.tab.c" => ["#{dir}/parse.y"] do |t|
file "#{current_build_dir}/y.tab.c" => ["#{current_dir}/parse.y"] do |t|
yacc.run t.name, t.prerequisites.first
end
file objfile("#{build_dir}/#{dir}/y.tab") => ["#{build_dir}/#{dir}/y.tab.c", lex_def] do |t|
cc.run t.name, t.prerequisites.first, [], [dir]
file objfile("#{current_build_dir}/y.tab") => ["#{current_build_dir}/y.tab.c", lex_def] do |t|
cc.run t.name, t.prerequisites.first, [], [current_dir]
end
# Lexical analyzer
file lex_def => "#{dir}/keywords" do |t|
file lex_def => "#{current_dir}/keywords" do |t|
gperf.run t.name, t.prerequisites.first
end
end
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
if enable_gems?
# set up all gems
......@@ -8,7 +9,7 @@ MRuby.each_target do
# loader all gems
self.libmruby << objfile("#{build_dir}/mrbgems/gem_init")
file objfile("#{build_dir}/mrbgems/gem_init") => "#{build_dir}/mrbgems/gem_init.c"
file "#{build_dir}/mrbgems/gem_init.c" => [MRUBY_CONFIGS].flatten do |t|
file "#{build_dir}/mrbgems/gem_init.c" => MRUBY_CONFIGS.flatten do |t|
FileUtils.mkdir_p "#{build_dir}/mrbgems"
open(t.name, 'w') do |f|
f.puts %Q[/*]
......
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
gems.each do |g|
test_rbobj = g.test_rbireps.ext(exts.object)
......
load 'tasks/mruby_build_gem.rake'
load 'tasks/mruby_build_commands.rake'
load "#{MRUBY_ROOT}/tasks/mruby_build_gem.rake"
load "#{MRUBY_ROOT}/tasks/mruby_build_commands.rake"
module MRuby
class << self
......@@ -30,7 +30,7 @@ module MRuby
end
def self.load
Dir.glob("#{File.dirname(__FILE__)}/toolchains/*.rake").each do |file|
Dir.glob("#{MRUBY_ROOT}/tasks/toolchains/*.rake").each do |file|
Kernel.load file
end
end
......@@ -44,7 +44,7 @@ module MRuby
include Rake::DSL
include LoadGems
attr_accessor :name, :bins, :exts, :file_separator
attr_reader :root, :libmruby, :gems
attr_reader :libmruby, :gems
COMPILERS = %w(cc cxx objc asm)
COMMANDS = COMPILERS + %w(linker archiver yacc gperf git exts mrbc)
......@@ -56,8 +56,6 @@ module MRuby
@name = name.to_s
unless MRuby.targets[@name]
@root = File.expand_path("#{File.dirname(__FILE__)}/..")
if ENV['OS'] == 'Windows_NT'
@exts = Exts.new('.o', '.exe', '.a')
else
......@@ -93,12 +91,16 @@ module MRuby
tc.setup(self)
end
def root
MRUBY_ROOT
end
def build_dir
"build/#{self.name}"
"#{MRUBY_ROOT}/build/#{self.name}"
end
def mrbcfile
MRuby.targets['host'].exefile("build/host/bin/mrbc")
MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/mrbc")
end
def compilers
......@@ -114,7 +116,7 @@ module MRuby
else
compiler.defines += %w(DISABLE_GEMS)
end
compiler.define_rules build_dir
compiler.define_rules build_dir, File.expand_path(File.join(File.dirname(__FILE__), '..'))
end
end
......@@ -161,14 +163,14 @@ module MRuby
def run_test
puts ">>> Test #{name} <<<"
mrbtest = exefile("#{build_dir}/test/mrbtest")
sh "#{filename mrbtest}"
sh "#{filename mrbtest.relative_path}"
puts
end
def print_build_summary
puts "================================================"
puts " Config Name: #{@name}"
puts " Output Directory: #{self.build_dir}"
puts " Output Directory: #{self.build_dir.relative_path}"
puts " Binaries: #{@bins.join(', ')}" unless @bins.empty?
unless @gems.empty?
puts " Included Gems:"
......
......@@ -39,7 +39,7 @@ module MRuby
@command = ENV['CC'] || 'cc'
@flags = [ENV['CFLAGS'] || []]
@source_exts = source_exts
@include_paths = ["#{build.root}/include"]
@include_paths = ["#{MRUBY_ROOT}/include"]
@defines = %w()
@option_include_path = '-I%s'
@option_define = '-D%s'
......@@ -60,7 +60,7 @@ module MRuby
include_path_flags = [include_paths, _include_paths, File.dirname(infile)].flatten.map do |f|
option_include_path % filename(f)
end
_pp "CC", infile, outfile
_pp "CC", infile.relative_path, outfile.relative_path
_run compile_options, { :flags => all_flags(_defineds, _include_paths, _flags),
:infile => filename(infile), :outfile => filename(outfile) }
end
......@@ -76,7 +76,7 @@ module MRuby
source_exts.each do |ext, compile|
rule generated_file_matcher => [
proc { |file|
file.sub(generated_file_matcher, "#{source_dir}\\1#{ext}")
file.sub(generated_file_matcher, "#{source_dir}/\\1#{ext}")
},
proc { |file|
get_dependencies(file)
......@@ -141,7 +141,7 @@ module MRuby
library_flags = [libraries, _libraries].flatten.map { |d| option_library % d }
library_path_flags = [library_paths, _library_paths].flatten.map { |f| option_library_path % filename(f) }
_pp "LD", outfile
_pp "LD", outfile.relative_path
_run link_options, { :flags => all_flags(_library_paths, _flags),
:outfile => filename(outfile) , :objs => filename(objfiles).join(' '),
:flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
......@@ -161,7 +161,7 @@ module MRuby
def run(outfile, objfiles)
FileUtils.mkdir_p File.dirname(outfile)
_pp "AR", outfile
_pp "AR", outfile.relative_path
_run archive_options, { :outfile => filename(outfile), :objs => filename(objfiles).join(' ') }
end
end
......@@ -177,7 +177,7 @@ module MRuby
def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile)
_pp "YACC", infile, outfile
_pp "YACC", infile.relative_path, outfile.relative_path
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end
end
......@@ -193,7 +193,7 @@ module MRuby
def run(outfile, infile)
FileUtils.mkdir_p File.dirname(outfile)
_pp "GPERF", infile, outfile
_pp "GPERF", infile.relative_path, outfile.relative_path
_run compile_options, { :outfile => filename(outfile) , :infile => filename(infile) }
end
end
......@@ -210,7 +210,7 @@ module MRuby
end
def run_clone(dir, url, _flags = [])
_pp "GIT", url, dir
_pp "GIT", url, dir.relative_path
_run clone_options, { :flags => [flags, _flags].flatten.join(' '), :url => url, :dir => filename(dir) }
end
end
......@@ -226,7 +226,7 @@ module MRuby
@command ||= @build.mrbcfile
IO.popen("#{filename @command} #{@compile_options % {:funcname => funcname}}", 'r+') do |io|
[infiles].flatten.each do |f|
_pp "MRBC", "#{f}", nil, :indent => 2
_pp "MRBC", f.relative_path, nil, :indent => 2
io.write IO.read(f)
end
io.close_write
......
......@@ -12,6 +12,10 @@ class String
def relative_path_from(dir)
Pathname.new(File.expand_path(self)).relative_path_from(Pathname.new(File.expand_path(dir))).to_s
end
def relative_path
relative_path_from(Dir.pwd)
end
# Compatible with 1.9 on 1.8
def %(params)
......
......@@ -2,7 +2,7 @@ MRuby::Toolchain.new(:gcc) do |conf|
[conf.cc, conf.cxx, conf.objc, conf.asm].each do |cc|
cc.command = ENV['CC'] || 'gcc'
cc.flags = [ENV['CFLAGS'] || %w(-g -O3 -Wall -Werror-implicit-function-declaration)]
cc.include_paths = ["#{root}/include"]
cc.include_paths = ["#{MRUBY_ROOT}/include"]
cc.defines = %w(DISABLE_GEMS)
cc.option_include_path = '-I%s'
cc.option_define = '-D%s'
......
......@@ -2,7 +2,7 @@ MRuby::Toolchain.new(:vs2012) do |conf|
[conf.cc, conf.cxx].each do |cc|
cc.command = ENV['CC'] || 'cl.exe'
cc.flags = [ENV['CFLAGS'] || %w(/c /nologo /W3 /D_DEBUG /MDd /Zi /Od /RTC1 /DHAVE_STRING_H /DNO_GETTIMEOFDAY /D_CRT_SECURE_NO_WARNINGS)]
cc.include_paths = ["#{root}/include"]
cc.include_paths = ["#{MRUBY_ROOT}/include"]
cc.defines = %w(DISABLE_GEMS)
cc.option_include_path = '/I%s'
cc.option_define = '/D%s'
......
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
exec = exefile("#{build_dir}/#{dir}/mrbtest")
clib = "#{build_dir}/#{dir}/mrbtest.c"
exec = exefile("#{current_build_dir}/mrbtest")
clib = "#{current_build_dir}/mrbtest.c"
mlib = clib.ext(exts.object)
mrbs = Dir.glob("#{dir}/t/*.rb")
init = "#{dir}/init_mrbtest.c"
asslib = "#{dir}/assert.rb"
mrbs = Dir.glob("#{current_dir}/t/*.rb")
init = "#{current_dir}/init_mrbtest.c"
asslib = "#{current_dir}/assert.rb"
mrbtest_lib = libfile("#{build_dir}/#{dir}/mrbtest")
mrbtest_lib = libfile("#{current_build_dir}/mrbtest")
file mrbtest_lib => [mlib, gems.map(&:test_objs), gems.map { |g| g.test_rbireps.ext(exts.object) }].flatten do |t|
archiver.run t.name, t.prerequisites
end
unless build_mrbtest_lib_only?
driver_obj = objfile("#{build_dir}/#{dir}/driver")
driver_obj = objfile("#{current_build_dir}/driver")
file exec => [driver_obj, mrbtest_lib, 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 }
......@@ -27,7 +29,7 @@ MRuby.each_target do
file mlib => [clib]
file clib => [mrbcfile, init, asslib] + mrbs do |t|
_pp "GEN", "*.rb", "#{clib}"
_pp "GEN", "*.rb", "#{clib.relative_path}"
FileUtils.mkdir_p File.dirname(clib)
open(clib, 'w') do |f|
f.puts IO.read(init)
......
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
if bins.find { |s| s.to_s == 'mirb' }
exec = exefile("#{build_dir}/bin/mirb")
objs = Dir.glob("#{dir}/*.c").map { |f| objfile(f.pathmap("#{build_dir}/%X")) }.flatten
objs = Dir.glob("#{current_dir}/*.c").map { |f| objfile(f.pathmap("#{current_build_dir}/%n")) }
file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
gem_flags = gems.map { |g| g.linker.flags }
......
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
if bins.find { |s| s.to_s == 'mrbc' }
exec = exefile("#{build_dir}/bin/mrbc")
objs = Dir.glob("#{dir}/*.c").map { |f| objfile(f.pathmap("#{build_dir}/%X")) }.flatten
objs = Dir.glob("#{current_dir}/*.c").map { |f| objfile(f.pathmap("#{current_build_dir}/%n")) }.flatten
file exec => objs + [libfile("#{build_dir}/lib/libmruby_core")] do |t|
linker.run t.name, t.prerequisites
......
MRuby.each_target do
dir = File.dirname(__FILE__).relative_path_from(root)
current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd)
relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT)
current_build_dir = "#{build_dir}/#{relative_from_root}"
if bins.find { |s| s.to_s == 'mruby' }
exec = exefile("#{build_dir}/bin/mruby")
objs = Dir.glob("#{dir}/*.c").map { |f| objfile(f.pathmap("#{build_dir}/%X")) }.flatten
objs = Dir.glob("#{current_dir}/*.c").map { |f| objfile(f.pathmap("#{current_build_dir}/%n")) }.flatten
file exec => objs + [libfile("#{build_dir}/lib/libmruby")] do |t|
gem_flags = gems.map { |g| g.linker.flags }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment