Commit 6460ef77 authored by take_cheeze's avatar take_cheeze Committed by Yukihiro "Matz" Matsumoto

Compile mruby compiler as mrbgem.

Compiler codes is moved to "mruby-compiler".
Executable `mrbc` is moved to "mruby-bin-mrbc".
parent 214bc3c9
......@@ -21,7 +21,6 @@ end
# 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"
......
MRuby::Gem::Specification.new 'mruby-bin-mrbc' do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'mruby compiler executable'
spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler'
exec = exefile("#{build.build_dir}/bin/mrbc")
mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten
file exec => mrbc_objs + [libfile("#{build.build_dir}/lib/libmruby_core")] do |t|
build.linker.run t.name, t.prerequisites
end
build.bins << 'mrbc' unless build.bins.find { |v| v == 'mrbc' }
end
MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'mruby compiler library'
current_dir = spec.dir
current_build_dir = spec.build_dir
lex_def = "#{current_dir}/core/lex.def"
core_objs = Dir.glob("#{current_dir}/core/*.c").map { |f|
next nil if build.cxx_abi_enabled? and f =~ /(codegen).c$/
objfile(f.pathmap("#{current_build_dir}/core/%n"))
}.compact
if build.cxx_abi_enabled?
core_objs <<
build.compile_as_cxx("#{current_build_dir}/core/y.tab.c", "#{current_build_dir}/core/y.tab.cxx",
objfile("#{current_build_dir}/y.tab"), ["#{current_dir}/core"]) <<
build.compile_as_cxx("#{current_dir}/core/codegen.c", "#{current_build_dir}/core/codegen.cxx")
else
core_objs << objfile("#{current_build_dir}/core/y.tab")
file objfile("#{current_build_dir}/core/y.tab") => "#{current_build_dir}/core/y.tab.c" do |t|
cc.run t.name, t.prerequisites.first, [], ["#{current_dir}/core"]
end
end
file objfile("#{current_build_dir}/core/y.tab") => lex_def
# Parser
file "#{current_build_dir}/core/y.tab.c" => ["#{current_dir}/core/parse.y"] do |t|
yacc.run t.name, t.prerequisites.first
end
# Lexical analyzer
file lex_def => "#{current_dir}/core/keywords" do |t|
gperf.run t.name, t.prerequisites.first
end
file libfile("#{build.build_dir}/lib/libmruby_core") => core_objs
build.libmruby << core_objs
end
......@@ -2,4 +2,6 @@ MRuby::Gem::Specification.new('mruby-eval') do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'standard Kernel#eval method'
add_dependency 'mruby-compiler', :core => 'mruby-compiler'
end
......@@ -3,76 +3,17 @@ MRuby.each_target do
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|
next nil if cxx_abi_enabled? and f =~ /(codegen|error|vm).c$/
next nil if cxx_abi_enabled? and f =~ /(error|vm).c$/
objfile(f.pathmap("#{current_build_dir}/%n"))
}.compact
if cxx_abi_enabled?
cxx_abi_dependency = %w(codegen error vm)
cxx_abi_objs = cxx_abi_dependency.map { |v|
src = "#{current_build_dir}/#{v}.cxx"
file src => ["#{current_dir}/#{v}.c", __FILE__] do |t|
File.open(t.name, 'w') do |f|
f.write <<EOS
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
extern "C" {
#include "#{MRUBY_ROOT}/#{t.prerequisites.first}"
}
#{v == 'error'? 'mrb_int mrb_jmpbuf::jmpbuf_id = 0;' : ''}
EOS
end
end
file objfile(src) => src do |t|
cxx.run t.name, t.prerequisites.first, [], [current_dir]
end
objfile src
}
cxx_abi_objs << objfile("#{current_build_dir}/y.tab")
file "#{current_build_dir}/y.tab.cxx" => ["#{current_build_dir}/y.tab.c", __FILE__] do |t|
File.open(t.name, 'w') do |f|
f.write <<EOS
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
extern "C" {
#include "#{t.prerequisites.first}"
}
EOS
end
end
file objfile("#{current_build_dir}/y.tab") => ["#{current_build_dir}/y.tab.cxx", lex_def] do |t|
cxx.run t.name, t.prerequisites.first, [], [current_dir]
end
objs += cxx_abi_objs
else
objs += [objfile("#{current_build_dir}/y.tab")]
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
objs += %w(vm error).map { |v| compile_as_cxx "#{current_dir}/#{v}.c", "#{current_build_dir}/#{v}.cxx" }
end
self.libmruby << objs
file libfile("#{build_dir}/lib/libmruby_core") => objs do |t|
archiver.run t.name, t.prerequisites
end
# Parser
file "#{current_build_dir}/y.tab.c" => ["#{current_dir}/parse.y"] do |t|
yacc.run t.name, t.prerequisites.first
end
# Lexical analyzer
file lex_def => "#{current_dir}/keywords" do |t|
gperf.run t.name, t.prerequisites.first
end
end
......@@ -80,7 +80,7 @@ module MRuby
@git = Command::Git.new(self)
@mrbc = Command::Mrbc.new(self)
@bins = %w(mrbc)
@bins = []
@gems, @libmruby = MRuby::Gem::List.new, []
@build_mrbtest_lib_only = false
@cxx_abi_enabled = false
......@@ -92,6 +92,8 @@ module MRuby
MRuby::Build.current = MRuby.targets[@name]
MRuby.targets[@name].instance_eval(&block)
build_mrbc_exec if name == 'host'
end
def enable_debug
......@@ -119,6 +121,33 @@ module MRuby
@cxx_abi_enabled = true
end
def compile_as_cxx src, cxx_src, obj = nil, includes = []
src = File.absolute_path src
cxx_src = File.absolute_path cxx_src
obj = objfile(cxx_src) if obj.nil?
file cxx_src => [src, __FILE__] do |t|
File.open(t.name, 'w') do |f|
f.write <<EOS
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
extern "C" {
#include "#{src}"
}
#{File.basename(src) == 'error.c'? 'mrb_int mrb_jmpbuf::jmpbuf_id = 0;' : ''}
EOS
end
end
file obj => cxx_src do |t|
cxx.run t.name, t.prerequisites.first, [], ["#{MRUBY_ROOT}/src"] + includes
end
obj
end
def enable_bintest
@enable_bintest = true
end
......@@ -142,8 +171,16 @@ module MRuby
MRUBY_ROOT
end
def build_mrbc_exec
gem :core => 'mruby-bin-mrbc'
end
def mrbcfile
MRuby.targets[@name].exefile("#{MRuby.targets[@name].build_dir}/bin/mrbc")
return @mrbcfile if @mrbcfile
mrbc_build = MRuby.targets['host']
gems.each { |v| mrbc_build = self if v.name == 'mruby-bin-mrbc' }
@mrbcfile = mrbc_build.exefile("#{mrbc_build.build_dir}/bin/mrbc")
end
def compilers
......
MRuby.each_target do
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("#{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
end
end
end
......@@ -8,6 +8,8 @@ MRuby::Build.new('debug') do |conf|
conf.compilers.each do |c|
c.defines += %w(MRB_GC_STRESS MRB_GC_FIXED_ARENA)
end
build_mrbc_exec
end
MRuby::Build.new do |conf|
......@@ -33,4 +35,6 @@ MRuby::Build.new('cxx_abi') do |conf|
conf.enable_bintest
enable_cxx_abi
build_mrbc_exec
end
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