make flags analysis: refactor, to reduce code duplication
authorStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 1 May 2013 21:26:42 +0000 (23:26 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Wed, 1 May 2013 21:27:14 +0000 (23:27 +0200)
And make it a little more reliable.

* t/header-vars.am (am__make_running_with_option): Here.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
lib/am/header-vars.am

index 4ad1783..3de46dc 100644 (file)
@@ -44,15 +44,11 @@ am__make_running_with_option = \
            exit 1;; \
     esac; \
     am__has_opt=no; \
+    am__flags=$$MAKEFLAGS; \
     if $(am__is_gnu_make); then \
-## GNU make: $(MAKEFLAGS) is quite tricky there, while the older variable
-## $(MFLAGS) behaves much better.  So use the latter.
-      for am__flg in $$MFLAGS; do \
-        case $$am__flg in \
-          *=*|--*) ;; \
-          -*$$am__target_option*) am__has_opt=yes; break;; \
-        esac; \
-      done; \
+## The format of $(MAKEFLAGS) is quite tricky with GNU make; the
+## variable $(MFLAGS) behaves much better in that regard.  So use it.
+      am__flags=$$MFLAGS; \
     else \
 ## Non-GNU make: we must rely on $(MAKEFLAGS).  This is tricker and more
 ## brittle, but is the best we can do.
@@ -68,24 +64,22 @@ am__make_running_with_option = \
            am__bs=\\; \
            am__flags=`printf '%s\n' "$$MAKEFLAGS" \
             | sed "s/$$am__bs$$am__bs[$$am__bs $$am__bs        ]*//g"`;; \
-         *) \
-           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 \
-          *=*|--*) ;; \
+    fi; \
+    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; \
+        -I) am__skip_next=yes;; \
+        *$$am__target_option*) am__has_opt=yes; break;; \
+      esac; \
+    done;\
     unset am__skip_next am__flg am__flags am__target_option; \
     test $$am__has_opt = yes; \
   }