Subject: [PATCH 4/7] header-vars: simplify how make flags are determined

From: Stefano Lattarini <[email-masked]>
Date: Mon, 29 Apr 2013 23:00:32 +0200

Actually, son far only the '-n' option ("dry mode") was detected,
but this change will allow us to soon detect more options.

* lib/am/header-vars.am (am__running_with_option): Even when $MAKEFLAGS
appears to contain definition of variables with embedded whitespace,
use simple textual pre-processing over $MAKEFLAGS rather than tricky
recursive invocations of make to determine whether the '-n' option was
given.  This is enough to correctly handle all the tricky usages covered
in the testsuite.
* t/nodep.sh: Adjust to avoid a spurious failure.

Signed-off-by: Stefano Lattarini <[email-masked]>
---
 lib/am/header-vars.am | 45 +++++++++++++++++++++++++--------------------
 t/nodep.sh            |  6 ++++--
 2 files changed, 29 insertions(+), 22 deletions(-)

diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am
index 8426dcb..c0a5f0c 100644
--- a/lib/am/header-vars.am
+++ b/lib/am/header-vars.am
@@ -40,7 +40,7 @@ am__make_running_with_option = \
     case $${am__target_option-} in \
         n) ;; \
         *) echo "am__make_running_with_option: internal error: invalid" \
-	        "target option '$${am__target_option-}' specified" >&2; \
+                "target option '$${am__target_option-}' specified" >&2; \
            exit 1;; \
     esac; \
     am__has_opt=no; \
@@ -54,8 +54,8 @@ am__make_running_with_option = \
         esac; \
       done; \
     else \
-## Non-GNU make: we must rely on $(MAKEFLAGS).  This is tricky and brittle,
-## but is the best we can do.
+## 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
@@ -63,25 +63,30 @@ am__make_running_with_option = \
 ## misinterpret that as and indication that make is running in dry mode.
 ## This has already happened in practice.  So we need this unpleasant hack.
          *\\[\ \	]*) \
-           echo 'am--echo: ; @echo "AM"  OK' | $(MAKE) -f - 2>/dev/null \
-             | grep '^AM OK$$' >/dev/null || am__has_opt=yes ;; \
+## Extra indirection with ${am__bs} required by FreeBSD 8.x make.
+## Not sure why (so sorry for the cargo-cult programming here).
+           am__bs=\\; \
+           am__flags=`printf '%s\n' "$$MAKEFLAGS" \
+            | sed "s/$$am__bs$$am__bs[$$am__bs $$am__bs	]*//g"`;; \
          *) \
-	   am__skip_next=no; \
-           for am__flg in $$MAKEFLAGS; do \
-	     if test $$am__skip_next = yes; then \
-	       am__skip_next=no; \
-	       continue; \
-	     fi; \
-             case $$am__flg in \
-               *=*|--*) ;; \
-## Quite ugly special-casing.  We might need other similar, but let's
-## wait until the need arises.
-	       -I) am__skip_next=yes;; \
-               *$$am__target_option*) am__has_opt=yes; break;; \
-             esac; \
-           done ;;\
-       esac; \
+           am__flags=$$MAKEFLAGS;; \
+      esac; \
+      am__skip_next=no; \
+      for am__flg in $$am__flags; do \
+        if test $$am__skip_next = yes; then \
+          am__skip_next=no; \
+          continue; \
+        fi; \
+        case $$am__flg in \
+          *=*|--*) ;; \
+## Quite ugly special-casing.  We might need other similar ones actually,
+## but let's wait until the need arises.
+          -I) am__skip_next=yes;; \
+          *$$am__target_option*) am__has_opt=yes; break;; \
+        esac; \
+      done;\
     fi; \
+    unset am__skip_next am__flg am__flags am__target_option; \
     test $$am__has_opt = yes; \
   }
 
diff --git a/t/nodep.sh b/t/nodep.sh
index c36405d..b0b29f6 100755
--- a/t/nodep.sh
+++ b/t/nodep.sh
@@ -36,5 +36,7 @@ mkdir x
 $ACLOCAL
 $AUTOMAKE
 
-grep '%' Makefile.in && exit 1
-exit 0
+sed 's/printf .*%s//' Makefile.in > Makefile.tmp
+grep '%' Makefile.tmp && exit 1
+
+:
-- 
1.8.2.1.610.g562af5b