bin/mrbt in mruby_tools-0.0.2.1 vs bin/mrbt in mruby_tools-0.0.3.1
- old
+ new
@@ -4,27 +4,35 @@
require 'mruby_tools'
# args like: file1.rb file2.rb -o outfile
# possibly: file1.rb -o outfile file2.rb -c generated.c
-opts = MRubyTools.args(ARGV)
-MRubyTools.usage if opts[:help]
+opts = MRubyTools::CLI.args(ARGV)
+MRubyTools::CLI.usage if opts[:help]
+mrb = MRubyTools.new(opts[:mruby_dir]) # nil is fine
+begin
+ mrb.validate!
+rescue MRubyTools::MRubyNotFound => e
+ warn "#{e.class}: can't find #{e}"
+ exit 1
+end
+
rb_files = opts.fetch(:rb_files)
-MRubyTools.usage("no .rb files provided") if rb_files.empty?
-c_code = MRubyTools.c_wrapper(rb_files)
+MRubyTools::CLI.usage("no .rb files provided") if rb_files.empty?
+
+c_code = MRubyTools::C.wrapper(rb_files)
puts c_code + "\n" if opts[:verbose]
-out_file = opts.fetch(:out_file)
c_file = opts.fetch(:c_file)
c_file.write(c_code)
c_file.close
+puts "generated #{c_file.path}" if opts[:verbose]
-msd = MRubyTools.mruby_src_dir
-
-gcc_args = [
- '-std=c99', "-I", File.join(msd, 'include'), c_file.path, "-o", out_file,
- File.join(msd, 'build', 'host', 'lib', 'libmruby.a'), '-lm',
-]
-
+out_file = opts.fetch(:out_file)
puts "compiling..."
-puts "created binary executable: #{out_file}" if system('gcc', *gcc_args)
+if mrb.compile(c_file.path, out_file)
+ puts "created binary executable: #{out_file}"
+else
+ warn "FATAL: compile failed"
+ exit 1
+end