From f0103202cc0764f3be151d954b411af0ced8ebcd Mon Sep 17 00:00:00 2001 From: knu Date: Sat, 25 Jan 2003 18:59:34 +0000 Subject: * instruby.rb, ext/extmk.rb, Makefile.in, win32/Makefile.sub, bcc32/Makefile.sub: Replace the complicated MFLAGS/MAKEFLAGS parser with something plain and comprehensible. This fixes a bug where make flags were wrongly reordered and the resulted command line often did not make sense especially when BSD make is used with extra arguments given. Tested with FreeBSD and Linux by me and mswin32, bccwin32 and mingw by usa. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@3408 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/extmk.rb | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'ext') diff --git a/ext/extmk.rb b/ext/extmk.rb index 97cf4b4a2..2cee3df3d 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'] -- cgit