refactor: new variable telling whether make is running in "dry mode"
authorStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 23 Jan 2012 20:02:05 +0000 (21:02 +0100)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Sun, 5 Feb 2012 17:04:59 +0000 (18:04 +0100)
We define a new variable '$(am__make_dryrun)', that can be used
in recipes to determine whether make is running in "dry mode" (as
with "make -n") or not.  This is useful in rules that invoke make
recursively, and are thus executed also with "make -n" -- either
because they are declared as dependencies to '.MAKE' (NetBSD make)
or because their recipes contain the "$(MAKE)" string (GNU and
Solaris make).

* lib/am/header-vars.am (am__make_dryrun): New variable.
* lib/am/check.am (check-TESTS recheck): Use it, and simplify
recipe accordingly.
* lib/am/distdir.am (distdir): Likewise.
* lib/am/lisp.am ($(am__ELCFILES)): Likewise.

lib/am/check.am
lib/am/distdir.am
lib/am/header-vars.am
lib/am/lisp.am

index e0a453b..7e2e771 100644 (file)
@@ -272,11 +272,9 @@ check-TESTS recheck:
        done; \
 ## Under "make recheck", remove the logs of the files to recheck, so that
 ## those will be rerun by the "make test-suite.log" recursive invocation
-## below.  But use a proper hack to avoid extra files removal when running
-## under "make -n".
+## below.  But avoid extra files removal when running under "make -n".
        if test $@ = recheck && test -n "$$list"; then \
-         echo "am--clean: ; rm -f $$list" \
-           | $(MAKE) $(AM_MAKEFLAGS) -f - am--clean || exit 1; \
+         $(am__make_dryrun) || rm -f $$list || exit 1; \
        fi; \
        $(MAKE) $(AM_MAKEFLAGS) $(TEST_SUITE_LOG) TEST_LOGS="$$list"
 
index cd2e4bf..da9028b 100644 (file)
@@ -236,19 +236,13 @@ endif %?TOPDIR_P%
 ## at the top level do the right thing.  If we're in the topmost
 ## directory, then we use `distdir' instead of `top_distdir'; this lets
 ## us work correctly with an enclosing package.
-##
-## Split the loop for the directory creation and the one for recursion,
-## so that with GNU make -n, only the latter is executed.
 if %?SUBDIRS%
        @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
          if test "$$subdir" = .; then :; else \
-           test -d "$(distdir)/$$subdir" \
-           || $(MKDIR_P) "$(distdir)/$$subdir" \
-           || exit 1; \
-         fi; \
-       done
-       @list='$(DIST_SUBDIRS)'; for subdir in $$list; do \
-         if test "$$subdir" = .; then :; else \
+           $(am__make_dryrun) \
+             || test -d "$(distdir)/$$subdir" \
+             || $(MKDIR_P) "$(distdir)/$$subdir" \
+             || exit 1; \
            dir1=$$subdir; dir2="$(distdir)/$$subdir"; \
            $(am__relativize); \
            new_distdir=$$reldir; \
index d1cd76e..0f05731 100644 (file)
@@ -27,6 +27,23 @@ VPATH = @srcdir@
 ## a vendor make.
 ## DESTDIR =
 
+## Shell code that determines whether make is running in "dry mode"
+## ("make -n") or not.  Useful in rules that invoke make recursively,
+## and are thus executed also with "make -n" -- either because they
+## are declared as dependencies to '.MAKE' (NetBSD make), or because
+## their recipes contain the "$(MAKE)" string (GNU and Solari make).
+am__make_dryrun = \
+  { \
+    am__dry=no; \
+    for am__flg in $$MAKEFLAGS; do \
+      case $$am__flg in \
+        *=*|--*) ;; \
+        *n*) am__dry=yes; break;; \
+      esac; \
+    done; \
+    test $$am__dry = yes; \
+  }
+
 ## Some derived variables that have been found to be useful.
 pkgdatadir = $(datadir)/@PACKAGE@
 pkgincludedir = $(includedir)/@PACKAGE@
index 6ffcdbf..0194c1b 100644 (file)
@@ -52,12 +52,7 @@ $(am__ELCFILES): elc-stamp
 ##
 ## If `make -n' is called, do not execute any command in the recipe that
 ## changes the tree; however, invoke the recursive make for debuggability.
-       @dry=; for f in x $$MAKEFLAGS; do \
-         case $$f in \
-           *=*|--*);; \
-           *n*) dry=:;; \
-         esac; \
-       done; \
+       @if $(am__make_dryrun); then dry=:; else dry=; fi; \
        if test "$(EMACS)" != no && test ! -f $@; then \
 ## If `make -j' is used and more than one file has been erased, several
 ## processes can execute this block.  We have to make sure that only