From fcbf63e62c627deae76c1b8cb8c0876c536ed811 Mon Sep 17 00:00:00 2001 From: Jari Vetoniemi Date: Mon, 16 Mar 2020 18:49:26 +0900 Subject: Fresh start --- jni/ruby/nacl/create_nmf.rb | 70 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 jni/ruby/nacl/create_nmf.rb (limited to 'jni/ruby/nacl/create_nmf.rb') diff --git a/jni/ruby/nacl/create_nmf.rb b/jni/ruby/nacl/create_nmf.rb new file mode 100644 index 0000000..cdfe7ad --- /dev/null +++ b/jni/ruby/nacl/create_nmf.rb @@ -0,0 +1,70 @@ +#!/usr/bin/ruby +# Copyright:: Copyright 2012 Google Inc. +# License:: All Rights Reserved. +# Original Author:: Yugui Sonoda (mailto:yugui@google.com) +# +# Wrapper for create_nmf.py / generate_nmf.py + +require File.join(File.dirname(__FILE__), 'nacl-config') + +include NaClConfig +$verbosity = 0 + +def usage_and_exit + $stderr.puts "Usage: #{$PROGRAM_NAME} [--verbose=N] path/to/input.nexe path/to/output.nmf" + exit false +end + +def create_dynamically_linked(nmf, exe) + cmd = [ + PYTHON, CREATE_NMF, + '-o', nmf, + '-D', OBJDUMP, + '-L', HOST_LIB, + exe + ] + puts cmd.join(' ') if $verbosity > 0 + exec(*cmd) +end + +def create_statically_linked(nmf, exe) + File.open(nmf, "w") {|f| + f.write <<-EOS.gsub(/^ {6}/, '') + { + "program": { + "#{ARCH}": { + "url": "#{exe}" + } + } + } + EOS + } +end + +def main + while m = ARGV.first.match(/--([a-z-]+)(?:=(\S+))?/) + case m[1] + when 'verbose' + usage_and_exit unless m[2][/\A[0-9]+\z/] + $verbosity = m[2].to_i + when 'help' + usage_end_exit + end + ARGV.shift + end + + usage_and_exit if ARGV.size < 2 + + exe, nmf = ARGV[0], ARGV[1] + if newlib? + create_statically_linked(nmf, exe) + else + create_dynamically_linked(nmf, exe) + end +end + +if __FILE__ == $0 + main() +end + + -- cgit v1.2.3