From da0964eb751461516bda1a38b8423cb412b601d6 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Mon, 23 Jan 2012 21:02:05 +0100 Subject: [PATCH] refactor: new variable telling whether make is running in "dry mode" 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 | 6 ++---- lib/am/distdir.am | 14 ++++---------- lib/am/header-vars.am | 17 +++++++++++++++++ lib/am/lisp.am | 7 +------ 4 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/am/check.am b/lib/am/check.am index e0a453b..7e2e771 100644 --- a/lib/am/check.am +++ b/lib/am/check.am @@ -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" diff --git a/lib/am/distdir.am b/lib/am/distdir.am index cd2e4bf..da9028b 100644 --- a/lib/am/distdir.am +++ b/lib/am/distdir.am @@ -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; \ diff --git a/lib/am/header-vars.am b/lib/am/header-vars.am index d1cd76e..0f05731 100644 --- a/lib/am/header-vars.am +++ b/lib/am/header-vars.am @@ -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@ diff --git a/lib/am/lisp.am b/lib/am/lisp.am index 6ffcdbf..0194c1b 100644 --- a/lib/am/lisp.am +++ b/lib/am/lisp.am @@ -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 -- 2.7.4