summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authortake_cheeze <[email protected]>2015-04-06 15:20:13 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2015-06-01 21:53:55 +0900
commit6460ef77bcceb17d80d1b46a07b28fada19737c8 (patch)
tree802d327b0efbe1ed9ed1a1109657e23705b4f89f
parent214bc3c95a9e01a7be4d76e94d80be9d9d59bd4b (diff)
downloadmruby-6460ef77bcceb17d80d1b46a07b28fada19737c8.tar.gz
mruby-6460ef77bcceb17d80d1b46a07b28fada19737c8.zip
Compile mruby compiler as mrbgem.
Compiler codes is moved to "mruby-compiler". Executable `mrbc` is moved to "mruby-bin-mrbc".
-rw-r--r--Rakefile1
-rw-r--r--mrbgems/mruby-bin-mrbc/mrbgem.rake16
-rw-r--r--mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c (renamed from tools/mrbc/mrbc.c)0
-rw-r--r--mrbgems/mruby-compiler/bintest/mrbc.rb (renamed from bintest/mrbc.rb)0
-rw-r--r--mrbgems/mruby-compiler/core/codegen.c (renamed from src/codegen.c)0
-rw-r--r--mrbgems/mruby-compiler/core/keywords (renamed from src/keywords)0
-rw-r--r--mrbgems/mruby-compiler/core/lex.def (renamed from src/lex.def)0
-rw-r--r--mrbgems/mruby-compiler/core/node.h (renamed from src/node.h)0
-rw-r--r--mrbgems/mruby-compiler/core/parse.y (renamed from src/parse.y)0
-rw-r--r--mrbgems/mruby-compiler/mrbgem.rake40
-rw-r--r--mrbgems/mruby-eval/mrbgem.rake2
-rw-r--r--src/mruby_core.rake63
-rw-r--r--tasks/mruby_build.rake41
-rw-r--r--tools/mrbc/mrbc.rake14
-rw-r--r--travis_config.rb4
15 files changed, 103 insertions, 78 deletions
diff --git a/Rakefile b/Rakefile
index 66f54a4e2..0f33c5ee8 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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"
diff --git a/mrbgems/mruby-bin-mrbc/mrbgem.rake b/mrbgems/mruby-bin-mrbc/mrbgem.rake
new file mode 100644
index 000000000..e710b5a49
--- /dev/null
+++ b/mrbgems/mruby-bin-mrbc/mrbgem.rake
@@ -0,0 +1,16 @@
+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
diff --git a/tools/mrbc/mrbc.c b/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
index f27f87a5d..f27f87a5d 100644
--- a/tools/mrbc/mrbc.c
+++ b/mrbgems/mruby-bin-mrbc/tools/mrbc/mrbc.c
diff --git a/bintest/mrbc.rb b/mrbgems/mruby-compiler/bintest/mrbc.rb
index b016378a1..b016378a1 100644
--- a/bintest/mrbc.rb
+++ b/mrbgems/mruby-compiler/bintest/mrbc.rb
diff --git a/src/codegen.c b/mrbgems/mruby-compiler/core/codegen.c
index 16233347c..16233347c 100644
--- a/src/codegen.c
+++ b/mrbgems/mruby-compiler/core/codegen.c
diff --git a/src/keywords b/mrbgems/mruby-compiler/core/keywords
index 9cb86608c..9cb86608c 100644
--- a/src/keywords
+++ b/mrbgems/mruby-compiler/core/keywords
diff --git a/src/lex.def b/mrbgems/mruby-compiler/core/lex.def
index ea456a843..ea456a843 100644
--- a/src/lex.def
+++ b/mrbgems/mruby-compiler/core/lex.def
diff --git a/src/node.h b/mrbgems/mruby-compiler/core/node.h
index 532a8323a..532a8323a 100644
--- a/src/node.h
+++ b/mrbgems/mruby-compiler/core/node.h
diff --git a/src/parse.y b/mrbgems/mruby-compiler/core/parse.y
index 5b17649a9..5b17649a9 100644
--- a/src/parse.y
+++ b/mrbgems/mruby-compiler/core/parse.y
diff --git a/mrbgems/mruby-compiler/mrbgem.rake b/mrbgems/mruby-compiler/mrbgem.rake
new file mode 100644
index 000000000..3a22762fa
--- /dev/null
+++ b/mrbgems/mruby-compiler/mrbgem.rake
@@ -0,0 +1,40 @@
+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
diff --git a/mrbgems/mruby-eval/mrbgem.rake b/mrbgems/mruby-eval/mrbgem.rake
index 7c6acc534..cb8835b32 100644
--- a/mrbgems/mruby-eval/mrbgem.rake
+++ b/mrbgems/mruby-eval/mrbgem.rake
@@ -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
diff --git a/src/mruby_core.rake b/src/mruby_core.rake
index 88fca83fc..abde441d5 100644
--- a/src/mruby_core.rake
+++ b/src/mruby_core.rake
@@ -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
diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake
index 66608286d..50bed0fbe 100644
--- a/tasks/mruby_build.rake
+++ b/tasks/mruby_build.rake
@@ -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
diff --git a/tools/mrbc/mrbc.rake b/tools/mrbc/mrbc.rake
deleted file mode 100644
index 1a0309a0d..000000000
--- a/tools/mrbc/mrbc.rake
+++ /dev/null
@@ -1,14 +0,0 @@
-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
diff --git a/travis_config.rb b/travis_config.rb
index fadafd8c1..2b4059cf1 100644
--- a/travis_config.rb
+++ b/travis_config.rb
@@ -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