Sha256: 0e7d2364a889a75c05b8379b0e16c1fa9c2501b81437493c405b349ddc846f3d
Contents?: true
Size: 1.35 KB
Versions: 1
Compression:
Stored size: 1.35 KB
Contents
#!/usr/bin/env ruby require 'tempfile' 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) outfile = opts.fetch(:outfile) c_code = <<'EOF' #include <stdlib.h> #include <mruby.h> #include <mruby/compile.h> #include <mruby/string.h> void check_exc(mrb_state *mrb, char *filename) { if (mrb->exc) { mrb_value exc = mrb_obj_value(mrb->exc); mrb_value exc_msg = mrb_funcall(mrb, exc, "to_s", 0); fprintf(stderr, "ERROR in %s - %s: %s\n", filename, mrb_obj_classname(mrb, exc), mrb_str_to_cstr(mrb, exc_msg)); /* mrb_print_backtrace(mrb); # empty */ exit(1); } } int main(void) { mrb_state *mrb = mrb_open(); if (!mrb) { printf("mrb problem"); exit(1); } EOF c_code += opts.fetch(:rb_files).map { |rbf| "\n" + MRubyTools.rb2c(rbf) + "\n\n" }.join c_code += <<EOF mrb_close(mrb); return 0; } EOF puts c_code + "\n" if opts[:verbose] file = opts[:cfile] || Tempfile.new(['generated', '.c']) file.write(c_code) file.close msd = MRubyTools.mruby_src_dir gcc_args = [ '-std=c99', "-I", File.join(msd, 'include'), file.path, "-o", outfile, File.join(msd, 'build', 'host', 'lib', 'libmruby.a'), '-lm', ] puts "compiling..." puts "created binary executable: #{outfile}" if system('gcc', *gcc_args)
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mruby_tools-0.0.1.1 | bin/mrbt |