From: Stefano Lattarini Date: Tue, 2 Oct 2012 22:03:10 +0000 (+0200) Subject: dry run: use $(MFLAGS), not $(MAKEFLAGS), to determine whether running dry X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=136a7f587daf8ee9af062703725a4d18f8ca2fa6;p=thirdparty%2Fautomake.git dry run: use $(MFLAGS), not $(MAKEFLAGS), to determine whether running dry $(MFLAGS) does not containing the command line variable definitions, and it always begins with a hyphen unless it is empty (MAKEFLAGS begins with a hyphen only when it begins with an option that has no single-letter version, such as '--warn-undefined-variables'). This allows use to make stricter assumptions on its content, thus simplifying the implementation of ... * lib/am/header-vars.am (am__make_dryrun): ... this macro. * t/make-dryrun.tap: Simplify accordingly. Signed-off-by: Stefano Lattarini --- diff --git a/lib/am/header-vars.mk b/lib/am/header-vars.mk index 27699ba41..c067bdf6a 100644 --- a/lib/am/header-vars.mk +++ b/lib/am/header-vars.mk @@ -160,19 +160,12 @@ DESTDIR ?= # Tell whether make is running in "dry mode". It is either 'true' or # 'false', so that it can be easily used in shell code as well as in -# GNU make conditionals. -# If we run "make TESTS='snooze nap'", GNU make will export MAKEFLAGS to -# "TESTS=foo\ nap", so that the builtins operating on word-split lists -# would see a "make flag" equal to "nap" when analyzing $(MAKEFLAGS), and -# would wrongly misinterpret that as and indication that make is running -# in dry mode. This has already happened in practice. So we need the -# hack with $(subst \ , ...). +# GNU make conditionals. Use $(MFLAGS), not $(MAKEFLAGS), since the +# former doesn't containing the command line variable definitions, and +# it always begins with a hyphen unless it is empty, assumptions that +# allow a simpler implementation. am.make.dry-run := \ - $(strip $(if $(strip \ - $(foreach v, $(subst \ ,,$(strip $(MAKEFLAGS))), \ - $(if $(or $(findstring =,$v),$(filter --%,$v)),, \ - $(findstring n,$v)))), \ - true, false)) + $(if $(findstring n,$(filter-out --%,$(MFLAGS))),true,false) am.util.strip-first-word = $(wordlist 2,$(words $(1)),$(1)) am.util.strip-last-word = $(wordlist 2,$(words $(1)),dummy $(1)) diff --git a/t/make-dryrun.tap b/t/make-dryrun.tap index 83f886263..487681be6 100755 --- a/t/make-dryrun.tap +++ b/t/make-dryrun.tap @@ -18,7 +18,7 @@ . ./defs || exit 1 -plan_ 32 +plan_ 14 echo AC_OUTPUT >> configure.ac @@ -26,18 +26,13 @@ cat > Makefile.am <<'END' all: @echo "Target '$@' should never run" >&2; exit 1; notdry-plain: - @echo ":: $$MAKEFLAGS ::" # For debugging. - @$(warning << $(MAKEFLAGS) >>) # Likewise. $(am.make.dry-run) && exit 1; exit 0 notdry-recursive: $(MAKE) notdry-plain dry-plain: - +@echo ":: $$MAKEFLAGS ::" # For debugging. - +@$(warning << $(MAKEFLAGS) >>) # Likewise. +$(am.make.dry-run) || exit 1; echo ok > from-dry-mode dry-recursive: $(MAKE) dry-plain -foo = $(error foo should not be expanded) END $ACLOCAL || fatal_ "aclocal failed" @@ -57,15 +52,11 @@ check_no_dryrun () cnt=1 check_no_dryrun +check_no_dryrun -k # Test against a known regression. This was especially heinous, since # make running in normal mode was sometimes mistaken for make running # in dry mode. -check_no_dryrun TESTS="n1.test n2.test" -check_no_dryrun TESTS="n1 n2" -check_no_dryrun TESTS="n1 n2" -check_no_dryrun FOOFLAGS="-n -n -knf2 n --none -n" -check_no_dryrun MYFLAGS="-n --dryrun -n --dry-run -n" mkdir n ./--dry-run check_no_dryrun -I n check_no_dryrun -I --dry-run @@ -92,24 +83,4 @@ check_dryrun --dry-run -k # ---------------------------------------------------------------------- -# Test for when shell metacharacters or backslashes are in $(MAKEFLAGS). - -check_metachars () -{ - for kind in plain recursive; do - command_ok_ "wet-run, $kind, with shell metachars ($cnt)" \ - $MAKE notdry-$kind ${1+"$@"} - done - cnt=$(($cnt + 1)) -} -cnt=1 - -check_metachars MYFLAGS="-n \"n\" '-n' --none -n" -check_metachars MYFLAGS='-knf2\ n\ \\n' -check_metachars MYFLAGS="(&) | ; \" \` '" -check_metachars MYFLAGS=" ' # ' " -check_metachars MYFLAGS='$(foo)' - -# ---------------------------------------------------------------------- - :