summaryrefslogtreecommitdiffhomepage
path: root/Rakefile
diff options
context:
space:
mode:
Diffstat (limited to 'Rakefile')
-rw-r--r--Rakefile174
1 files changed, 157 insertions, 17 deletions
diff --git a/Rakefile b/Rakefile
index 4115d9e8e..5c5a6e8eb 100644
--- a/Rakefile
+++ b/Rakefile
@@ -14,7 +14,13 @@ require "mruby-core-ext"
require "mruby/build"
# load configuration file
-MRUBY_CONFIG = (ENV['MRUBY_CONFIG'] && ENV['MRUBY_CONFIG'] != '') ? ENV['MRUBY_CONFIG'] : "#{MRUBY_ROOT}/build_config.rb"
+if ENV['MRUBY_CONFIG']
+ MRUBY_CONFIG = ENV['MRUBY_CONFIG']
+ MRUBY_TARGET = File.basename(MRUBY_CONFIG, ".rb")
+else
+ MRUBY_TARGET = ENV['MRUBY_TARGET'] || ENV['TARGET'] || "host"
+ MRUBY_CONFIG = "#{MRUBY_ROOT}/target/#{MRUBY_TARGET}.rb"
+end
load MRUBY_CONFIG
# load basic rules
@@ -46,15 +52,19 @@ task :default => :all
bin_path = ENV['INSTALL_DIR'] || "#{MRUBY_ROOT}/bin"
-depfiles = MRuby.targets['host'].bins.map do |bin|
- install_path = MRuby.targets['host'].exefile("#{bin_path}/#{bin}")
- source_path = MRuby.targets['host'].exefile("#{MRuby.targets['host'].build_dir}/bin/#{bin}")
+if MRuby.targets['host']
+ target = MRuby.targets['host']
+ depfiles = target.bins.map do |bin|
+ install_path = target.exefile("#{bin_path}/#{bin}")
+ source_path = target.exefile("#{target.build_dir}/bin/#{bin}")
- file install_path => source_path do |t|
- install_D t.prerequisites.first, t.name
+ file install_path => source_path do |t|
+ install_D t.prerequisites.first, t.name
+ end
+ install_path
end
-
- install_path
+else
+ depfiles = []
end
MRuby.each_target do |target|
@@ -87,15 +97,6 @@ MRuby.each_target do |target|
install_D t.prerequisites.first, t.name
end
depfiles += [ install_path ]
- elsif target == MRuby.targets['host-debug']
- unless MRuby.targets['host'].gems.map {|g| g.bins}.include?([bin])
- install_path = MRuby.targets['host-debug'].exefile("#{bin_path}/#{bin}")
-
- file install_path => exec do |t|
- install_D t.prerequisites.first, t.name
- end
- depfiles += [ install_path ]
- end
else
depfiles += [ exec ]
end
@@ -103,6 +104,143 @@ MRuby.each_target do |target|
end
end
+mkdir_p "#{MRUBY_ROOT}/build"
+cfiles = (
+ Dir.glob("#{MRUBY_ROOT}/src/*.c")+
+ Dir.glob("#{MRUBY_ROOT}/mrbgems/**/*.c")+
+ Dir.glob("#{MRUBY_ROOT}/build/repos/**/{src,core}/*.c")
+).uniq
+rbfiles = (
+ Dir.glob("#{MRUBY_ROOT}/mrblib/**/*.rb")+
+ Dir.glob("#{MRUBY_ROOT}/mrbgems/*/mrblib/**/*.rb")+
+ Dir.glob("#{MRUBY_ROOT}/build/repos/**/mrblib/**/*.rb")
+).uniq
+psfiles = Dir.glob("#{MRUBY_ROOT}/{mrblib,mrbgems,build/repos}/**/presym")
+symbols = []
+psfiles.each do |file|
+ symbols += File.readlines(file).grep_v(/^# /)
+end
+symbols.each{|x| x.chomp!}
+presym_file="#{MRUBY_ROOT}/build/presym"
+op_table = {
+ "!" => "not",
+ "!=" => "neq",
+ "!~" => "nmatch",
+ "%" => "mod",
+ "&" => "and",
+ "&&" => "andand",
+ "*" => "mul",
+ "**" => "pow",
+ "+" => "add",
+ "+@" => "plus",
+ "-" => "sub",
+ "-@" => "minus",
+ "/" => "div",
+ "<" => "lt",
+ "<=" => "le",
+ "<<" => "lshift",
+ "<=>" => "cmp",
+ "==" => "eq",
+ "===" => "eqq",
+ "=~" => "match",
+ ">" => "gt",
+ ">=" => "ge",
+ ">>" => "rshift",
+ "[]" => "aref",
+ "[]=" => "aset",
+ "^" => "xor",
+ "`" => "tick",
+ "|" => "or",
+ "||" => "oror",
+ "~" => "neg",
+}
+
+file presym_file => cfiles+rbfiles+psfiles+[__FILE__] do
+ csymbols = cfiles.map do |f|
+ src = File.read(f)
+ src.gsub!(/\/\/.+(\n|$)/, "\n")
+ [src.scan(/intern_lit\([^\n"]*"([^\n "]*)"/),
+ src.scan(/mrb_define_method\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_class_method\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_class\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_module\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_module_function\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_const\([^\n"]*"([^\n"]*)"/),
+ src.scan(/mrb_define_global_const\([^\n"]*"([^\n"]*)"/),
+ src.scan(/MRB_SYM\((\w+)\)/),
+ src.scan(/MRB_QSYM\((\w+)\)/).map{|x,|
+ x.sub!(/_p$/, "?") || x.sub!(/_b$/, "!") || x.sub!(/_e$/, "=") || x.sub!(/^0_/, "@") || x.sub!(/^00_/, "@@")
+ }.compact]
+ end
+ rbsymbols = rbfiles.map do |f|
+ src = File.read(f)
+ src.force_encoding(Encoding::BINARY)
+ [src.scan(/\bclass +([A-Z]\w*)/),
+ src.scan(/\bmodule +([A-Z]\w*)/),
+ src.scan(/\bdef +(\w+[!?=]?)/),
+ src.scan(/\balias +(\w+[!?]?)/),
+ src.scan(/\b([A-Z]\w*) *=[^=]/),
+ src.scan(/(\$[a-zA-Z_]\w*)/),
+ src.scan(/(\$[$!?0-9]\w*)/),
+ src.scan(/(@@?[a-zA-Z_]\w*)/),
+ src.scan(/[^.]\.([a-zA-Z_]\w*[!?]?)/),
+ src.scan(/\.([a-zA-Z_]\w* *=)/).map{|x|x.map{|s|s.gsub(' ', '')}},
+ src.scan(/\b([a-zA-Z_]\w*):/),
+ src.scan(/:([a-zA-Z_]\w*[!?=]?)/),
+ src.scan(/[\(\[\{ ]:"([^"]+)"/).map{|x|x.map{|s|s.gsub('\#', '#')}},
+ src.scan(/[ \(\[\{]:'([^']+)'/)
+ ]
+ end
+ symbols = (symbols+csymbols+rbsymbols+op_table.keys).flatten.compact.uniq.sort.map{|x| x.gsub("\n", '\n')}
+ presyms = File.readlines(presym_file) rescue []
+ presyms.each{|x| x.chomp!}
+ if presyms != symbols
+ File.write(presym_file, symbols.join("\n"))
+ end
+end
+
+presym_inc=presym_file+".inc"
+file presym_inc => presym_file do
+ presyms = File.readlines(presym_file)
+ presyms.each{|x| x.chomp!}
+ File.open(presym_inc, "w") do |f|
+ f.print "/* MRB_PRESYM_CSYM(sym, num) - symbol which is valid C id name */\n"
+ f.print "/* MRB_PRESYM_QSYM(name, sym, num) - symbol with alias name */\n"
+ f.print "/* MRB_PRESYM_SYM(name, num) - symbol which is not valid C id */\n"
+ presyms.each.with_index do |sym,i|
+ if sym.bytes.detect{|x|x>0x80} || /\A\$/ =~ sym
+ f.print "MRB_PRESYM_SYM(\"#{sym}\", #{i+1})\n"
+ elsif /\A\w+\Z/ =~ sym
+ f.print "MRB_PRESYM_CSYM(#{sym}, #{i+1})\n"
+ elsif op_table.key?(sym)
+ f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{op_table[sym]}, #{i+1})\n"
+ elsif /\A[A-Za-z_]\w*\?\Z/ =~ sym
+ s = sym.dup; s[-1] = "_p"
+ f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
+ elsif /\A[A-Za-z_]\w*\!\Z/ =~ sym
+ s = sym.dup; s[-1] = "_b"
+ f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
+ elsif /\A[A-Za-z_]\w*\=\Z/ =~ sym
+ s = sym.dup; s[-1] = "_e"
+ f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
+ elsif /\A@@/ =~ sym
+ s = sym.dup; s[0,2] = "00_"
+ f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
+ elsif /\A@/ =~ sym
+ s = sym.dup; s[0] = "0_"
+ f.print "MRB_PRESYM_QSYM(\"#{sym}\", #{s}, #{i+1})\n"
+ else
+ f.print "MRB_PRESYM_SYM(\"#{sym}\", #{i+1})\n"
+ end
+ end
+ f.print "#define MRB_PRESYM_MAX #{presyms.size}"
+ end
+end
+
+desc "preallocated symbols"
+task :gensym => presym_inc
+task :all => :gensym
+
depfiles += MRuby.targets.map { |n, t|
t.libraries
}.flatten
@@ -156,5 +294,7 @@ task :deep_clean => ["clean", "clean_doc"] do
MRuby.each_target do |t|
rm_rf t.gem_clone_dir
end
+ rm_f presym_file
+ rm_f presym_inc
puts "Cleaned up mrbgems build folder"
end