diff options
Diffstat (limited to 'ext/extmk.rb')
-rw-r--r-- | ext/extmk.rb | 45 |
1 files changed, 31 insertions, 14 deletions
diff --git a/ext/extmk.rb b/ext/extmk.rb index 97cf4b4a2f..2cee3df3dc 100644 --- a/ext/extmk.rb +++ b/ext/extmk.rb @@ -27,6 +27,7 @@ $:.replace [srcdir, srcdir+"/lib", "."] require 'mkmf' require 'ftools' require 'shellwords' +require 'getopts' $topdir = File.expand_path(".") $top_srcdir = srcdir @@ -113,22 +114,40 @@ def extmake(target) true end -require 'getopts' +def parse_args() + getopts('n', 'extstatic:', 'dest-dir:', + 'make:', 'make-flags:', 'mflags:') + + $dryrun = $OPT['n'] + $force_static = $OPT['extstatic'] == 'static' + $destdir = $OPT['dest-dir'] || '' + $make = $OPT['make'] || $make + make_flags = ($OPT['make-flags'] || '').strip + mflags = ($OPT['mflags'] || '').strip + + # BSD make defines both MFLAGS and MAKEFLAGS, and MAKEFLAGS it + # defines includes a preceding '-' unlike other implementations. + # So we use MFLAGS if defined, otherwise use ('-' + MAKEFLAGS). + if mflags.empty? + mflags = "-#{make_flags}" unless make_flags.empty? + end -getopts('', 'extstatic', 'make:', 'make-flags:') + $mflags = Shellwords.shellwords(mflags) + $make, *rest = Shellwords.shellwords($make) + $mflags.unshift(*rest) unless rest.empty? -$force_static = $OPT['extstatic'] == 'static' -$make = $OPT['make'] || $make -$mflags = Shellwords.shellwords($OPT['make-flags'] || "").uniq -$mflags[0].sub!(/^\w+$/, '-\&') unless $mflags.empty? -$make, *$mflags[0, 0] = Shellwords.shellwords($make) + $mflags << '-n' if $dryrun -$mflags.delete_if{|x| x == '-' || x == '--'} + $mflags << "DESTDIR=#{$destdir}" -mflags = $mflags.grep(/^-([^-])/){$1}.join -mflags.downcase! if $nmake == ?m -$continue = mflags.include?(?k) -$dryrun = mflags.include?(?n) + # Most make implementations put each flag separated in MAKEFLAGS, so + # we can just search for an option with exact match. Only nmake + # puts flags together, but nmake does not propagate -k via MAKEFLAGS + # anyway. + $continue = $mflags.include?('-k') +end + +parse_args() unless $message if $message = ARGV.shift and /^[a-z]+$/ =~ $message @@ -149,8 +168,6 @@ unless $message end end -$mflags = $mflags.partition{|x| x[0] == ?-}.flatten! - EXEEXT = CONFIG['EXEEXT'] if CROSS_COMPILING $ruby = CONFIG['MINIRUBY'] |