automake-ng
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Automake-NG] [FYI] make flags analysis: take advantage of GNU make feat


From: Stefano Lattarini
Subject: [Automake-NG] [FYI] make flags analysis: take advantage of GNU make features
Date: Wed, 8 May 2013 01:12:43 +0200

* lib/am/header-vars.mk: Here.  In particular ...
(am__make_keepgoing): ... rename this ...
(am.make.keep-going): ... like this, and reimplement using ...
(am.make.is-running-with-option): ... this new macro, cannibalized
from the old version of the 'am.make.dry-run' macro.
(am.make.dry-run): Reimplement using such new macro.
* lib/am/subdirs.mk: Adjust.
* t/make-keepgoing.tap: Likewise.  While at, simplify by assuming
that $MAKE is GNU make, and enhance to test more setups (in particular,
this makes this test more in sync with the test 't/make-dryrun.tap').
* t/make-dryrun.tap: While at it, remove an extra empty line.

Signed-off-by: Stefano Lattarini <address@hidden>
---
 lib/am/header-vars.mk | 115 ++++++++++----------------------------------------
 lib/am/subdirs.mk     |   2 +-
 t/make-dryrun.tap     |   1 -
 t/make-keepgoing.tap  |  75 +++++++++++++++-----------------
 4 files changed, 57 insertions(+), 136 deletions(-)

diff --git a/lib/am/header-vars.mk b/lib/am/header-vars.mk
index d31bb60..37f0c87 100644
--- a/lib/am/header-vars.mk
+++ b/lib/am/header-vars.mk
@@ -158,99 +158,28 @@ am.vpath.rewrite = \
 # with mainline Automake.
 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.  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 := \
-  $(if $(findstring n,$(filter-out --%,$(MFLAGS))),true,false)
-
-## Shell code that determines whether we are running under GNU make.
-## This is somewhat of an hack, and might be improved, but is good
-## enough for now.
-## FIXME: copied over from mainline Automake.  This should be later
-##        discarder!
-am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)'
-
-## FIXME: copied over from mainline Automake.  Rewrite to be GNU make
-##       specific, please!
-## Shell code that determines whether the current make instance is
-## running with a given one-letter option (e.g., -k, -n) that takes
-## no argument.  Actually, the only supported option at the moment
-## is '-n' (support for '-k' will be added soon).
-am__make_running_with_option = \
-  case $${target_option-} in \
-      ?) ;; \
-      *) echo "am__make_running_with_option: internal error: invalid" \
-              "target option '$${target_option-}' specified" >&2; \
-         exit 1;; \
-  esac; \
-  has_opt=no; \
-  sane_makeflags=$$MAKEFLAGS; \
-  if $(am__is_gnu_make); then \
-## The format of $(MAKEFLAGS) is quite tricky with GNU make; the
-## variable $(MFLAGS) behaves much better in that regard.  So use it.
-    sane_makeflags=$$MFLAGS; \
-  else \
-## Non-GNU make: we must rely on $(MAKEFLAGS).  This is tricker and more
-## brittle, but is the best we can do.
-    case $$MAKEFLAGS in \
-## If we run "make TESTS='snooze nap'", FreeBSD make will export MAKEFLAGS
-## to " TESTS=foo\ nap", so that the simpler loop below (on word-splitted
-## $$MAKEFLAGS) would see a "make flag" equal to "nap", and would wrongly
-## misinterpret that as and indication that make is running in dry mode.
-## This has already happened in practice.  So we need this hack.
-      *\\[\ \  ]*) \
-## Extra indirection with ${bs} required by FreeBSD 8.x make.
-## Not sure why (so sorry for the cargo-cult programming here).
-        bs=\\; \
-        sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \
-          | sed "s/$$bs$$bs[$$bs $$bs  ]*//g"`;; \
-    esac; \
-  fi; \
-  skip_next=no; \
-  strip_trailopt () \
-  { \
-    flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \
-  }; \
-  for flg in $$sane_makeflags; do \
-    test $$skip_next = yes && { skip_next=no; continue; }; \
-    case $$flg in \
-      *=*|--*) continue;; \
-##
-## GNU make 3.83 has changed the format of $MFLAGS, and removed the space
-## between an option and its argument (e.g., from "-I dir" to "-Idir").
-## So we need to handle both formats, at least for options valid in GNU
-## make.  OTOH, BSD make formats $(MAKEFLAGS) by separating all options,
-## and separating any option from its argument, so things are easier
-## there.
-##
-## For GNU make and BSD make.
-        -*I) strip_trailopt 'I'; skip_next=yes;; \
-      -*I?*) strip_trailopt 'I';; \
-## For GNU make >= 3.83.
-        -*O) strip_trailopt 'O'; skip_next=yes;; \
-      -*O?*) strip_trailopt 'O';; \
-## For GNU make (possibly overkill, this one).
-        -*l) strip_trailopt 'l'; skip_next=yes;; \
-      -*l?*) strip_trailopt 'l';; \
-## For BSD make.
-      -[dEDm]) skip_next=yes;; \
-## For NetBSD make.
-      -[JT]) skip_next=yes;; \
-    esac; \
-    case $$flg in \
-      *$$target_option*) has_opt=yes; break;; \
-    esac; \
-  done; \
-  test $$has_opt = yes
-
-## Shell code that determines whether make is running in "keep-going mode"
-## ("make -k") or not.  Useful in rules that must recursively descend into
-## subdirectories, and decide whther to stop at the first error or not.
-am__make_keepgoing = (target_option=k; $(am__make_running_with_option))
+# Shell code that determines whether the current make instance is
+# running with a given letter option (e.g., -k, -n) that takes
+# no argument.  It is either 'true' or 'false', so that it can be
+# easily used in shell code as well as in GNU make conditionals.
+# Use $(MFLAGS), not $(MAKEFLAGS), since the former doesn't contain
+# the command line variable definitions, and it always begins with
+# a hyphen unless it is empty, assumptions that allow a simpler
+# implementation.  It is worthwhile to note that, when expanded
+# from the top-level make, $(MFLAGS) doesn't contain references to
+# options that take an argument, either mandatory (e.g., '-I') or
+# optional (e.g., '-O').  This *vastly* semplifies the implementation
+# of this macro.
+am.make.is-running-with-option = \
+  $(if $(findstring $(strip $1),filter-out --%,$(MFLAGS)),true,false)
+
+# Tell whether make is running in "dry mode".
+am.make.dry-run := $(call am.make.is-running-with-option, n)
+
+# Shell code that determines whether make is running in "keep-going mode"
+# ("make -k") or not.  Useful in rules that must recursively descend into
+# subdirectories, and decide whether to stop at the first error or not.
+am.make.keep-going := $(call am.make.is-running-with-option, k)
 
 am.util.strip-first-word = $(wordlist 2,$(words $(1)),$(1))
 am.util.strip-last-word  = $(wordlist 2,$(words $(1)),dummy $(1))
diff --git a/lib/am/subdirs.mk b/lib/am/subdirs.mk
index ca33ae8..4c9469c 100644
--- a/lib/am/subdirs.mk
+++ b/lib/am/subdirs.mk
@@ -44,7 +44,7 @@ $(am.recurs.all-targets): %-recursive:
 ## Using $failcom allows "-k" to keep its natural meaning when running a
 ## recursive rule.
        @fail=; \
-       if $(am__make_keepgoing); then \
+       if $(am.make.keep-going); then \
          failcom='fail=yes'; \
        else \
          failcom='exit 1'; \
diff --git a/t/make-dryrun.tap b/t/make-dryrun.tap
index 97c8a47..ff9d5eb 100755
--- a/t/make-dryrun.tap
+++ b/t/make-dryrun.tap
@@ -59,7 +59,6 @@ check_make ()
     esac
     shift
   done
-
   for kind in plain recursive; do
     for opts in '' '-s'  '-s -rR'; do
       r=ok
diff --git a/t/make-keepgoing.tap b/t/make-keepgoing.tap
index f9db028..af6fae5 100755
--- a/t/make-keepgoing.tap
+++ b/t/make-keepgoing.tap
@@ -14,35 +14,36 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-# Check that $(am__make_keepgoing) works as expected.
+# Check that $(am.make.keep-going) works as expected.
 
 . test-init.sh
 
-plan_ 60
-
-mkdir kool # Also used later.
-if echo nil: | $MAKE -I kool -f -; then
-  make_supports_option_I () { return 0; }
-else
-  make_supports_option_I () { return 1; }
-fi
+plan_ 120
 
 echo AC_OUTPUT >> configure.ac
 
 cat > Makefile.am <<'END'
+# For debugging.
+$(warning MAKEFLAGS[make] => '$(MAKEFLAGS)')
+$(warning MFLAGS[make]    => '$(MFLAGS)')
+$(warning MAKEFLAGS[env]  => '$(shell printf "%s\\n" "$$MAKEFLAGS")')
+$(warning MFLAGS[env]     => '$(shell printf "%s\\n" "$$MFLAGS")')
+
 all:
        @echo 'Default target $@ should not be called'>&2; exit 1;
-k-y:
-       @echo ":: $$MAKEFLAGS :: $$MFLAGS ::" ;: For debugging.
-       $(am__make_keepgoing)
-k-n:
-       @echo ":: $$MAKEFLAGS :: $$MFLAGS ::" ;: For debugging.
-       $(am__make_keepgoing) && exit 1; exit 0
+k-y-plain:
+       $(am.make.keep-going)
+k-n-plain:
+       $(am.make.keep-going) && exit 1; exit 0
+k-y-recursive:
+       $(MAKE) k-y-plain
+k-n-recursive:
+       $(MAKE) k-n-plain
 END
 
 check_make ()
 {
-  msg= mode= condition=: directive= reason= skip_reason=
+  msg= mode=
   case $1 in
     k-[yn]) mode=$1;;
     *) fatal_ "check_run: invalid usage";;
@@ -50,25 +51,22 @@ check_make ()
   shift
   while test $# -gt 0; do
     case $1 in
-      -C) condition=$2 skip_reason=$3; shift; shift;;
       -M) msg=$2; shift;;
-      -X) directive=TODO;;
       --) shift; break;;
        *) break;;
     esac
     shift
   done
-  for opts in '' '-s'  '-s -r'; do
-    r=ok
-    pmsg=${mode}${msg:+" [$msg]"}${opts:+" ($opts)"}
-    if $condition; then
-      $MAKE $opts "$mode" ${1+"$@"} || r='not ok'
-    else
-      directive=SKIP reason=$skip_reason
-    fi
-    result_ "$r" -D "$directive" -r "$reason" "$pmsg"
+  for kind in plain recursive; do
+    for opts in '' '-s'  '-s -r'; do
+      r=ok
+      msg2="${mode}, ${kind}"${msg:+" [$msg]"}${opts:+" ($opts)"}
+      $MAKE $opts "$mode-$kind" ${1+"$@"} || r='not ok'
+      result_ "$r" "$msg2"
+      unset r msg2
+    done
   done
-  unset r msg pmsg opts mode condition directive reason skip_reason
+  unset r msg msg2 opts mode
 }
 
 # ----------------------------------------------------------------------
@@ -93,26 +91,21 @@ check_make k-n MYFLAGS="-k --keepgoing -k --keep-run -k"
 # ----------------------------------------------------------------------
 
 check_make k-y -k
-check_make k-y -C using_gmake "\$MAKE is not GNU make" --keep-going
+check_make k-y --keep-going
 
 # ----------------------------------------------------------------------
 
 # Related to automake bug#12554: the "k" in "kool" used to confound
-# am__make_keepgoing into thinking the '-k' option had been passed.
+# am.make.keep-going into thinking the '-k' option had been passed.
 
 pr='bug#12554'
 
-check_make k-n -C make_supports_option_I "-I make option unsupported" \
-               -M "$pr" -I kool
-
-check_make k-n -C using_gmake "\$MAKE is not GNU make" \
-               -M "$pr" -I kool --include keep-going
-
-check_make k-y -C make_supports_option_I "-I make option unsupported" \
-               -M "$pr" -I kool -k
-
-check_make k-y -C using_gmake "\$MAKE is not GNU make" \
-               -M "$pr" --keep-going -I kool --include keep-going
+mkdir kool
+check_make k-n -M "$pr" -I kool
+check_make k-n -M "$pr" -I kool --include keep-going
+check_make k-y -M "$pr" -I kool -k
+check_make k-y -M "$pr" --keep-going -I kool --include keep-going
+rmdir kool
 
 # ----------------------------------------------------------------------
 
-- 
1.8.3.rc0.19.g7e6a0cc




reply via email to

[Prev in Thread] Current Thread [Next in Thread]