#!/usr/bin/env ruby DOCUMENTATION = <:replace, :replace=>"?").encode('UTF-8') match = /^TOP=(.*)$/.match(make_proto_contents) if match.nil? then STDERR.puts "error: could not extract TOP from Make.proto (missing TOP=.. definition?)" return 4 end top = match[1].rstrip() end if not File.directory? top then require 'pry' require 'pry-byebug' binding.pry STDERR.puts "error: TOP does not exist or not a directory: #{top}" return 5 end makelib = File.join(cwd, top, '..', '..' , 'makelib') if not File.exist? makelib then STDERR.puts "error: makefile include library does not exist or not a directory: #{makelib}" return 6 end File.open(File.join(cwd, out), "w") do | f | f.puts <<-CONTENTS # # Do not edit! Automatically generated by stmkmf. # MAKELIB ?= #{top}/../../makelib include $(MAKELIB)/definitions.make #{File.exists?(File.join(cwd, 'Make.spec')) ? 'include Make.spec' : ''} include Make.proto include $(MAKELIB)/rules.make CONTENTS end return 0 end if __FILE__ == $0 require 'optparse' cwd = '.' out = 'makefile' optparser = OptionParser.new do | optparser | optparser.banner = "Usage: stmkmf.rb [options] [stx-top-directory]" optparser.on('-C', '--cd DIRECTORY', "Generates makefile in DIRECTORY. Optional, default is current working cwd.") do | value | cwd = value end optparser.on('-o', '--out FILE', "Write result to FILE. Optional, default is 'makefile'") do | value | out = value end optparser.on(nil, '--help', "Prints this message") do puts DOCUMENTATION puts optparser.help() exit 0 end end optparser.parse! top = ARGV[0] || nil exit stmkmf(cwd: cwd, out: out, top: top) end