automake-commit
[Top][All Lists]
Advanced

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

[automake-commit] branch master updated: docs: promote Makefile snippets


From: Karl Berry
Subject: [automake-commit] branch master updated: docs: promote Makefile snippets that work properly with make -n.
Date: Thu, 28 May 2020 20:45:26 -0400

This is an automated email from the git hooks/post-receive script.

karl pushed a commit to branch master
in repository automake.

View the commit online:
https://git.savannah.gnu.org/gitweb/?p=automake.git;a=commitdiff;h=660dfaeb24e5a17e6f2ef9baf53e0c90f6324daa

The following commit(s) were added to refs/heads/master by this push:
     new 660dfae  docs: promote Makefile snippets that work properly with make 
-n.
660dfae is described below

commit 660dfaeb24e5a17e6f2ef9baf53e0c90f6324daa
Author: Akim Demaille <akim@gnu.org>
AuthorDate: Thu May 28 17:45:15 2020 -0700

    docs: promote Makefile snippets that work properly with make -n.
    
    This change handles https://bugs.gnu.org/10852.
    
    * doc/automake.texi (Multiple Outputs): Split commands than
    reinvoke $(MAKE) to avoid file removals during dry runs.
---
 doc/automake.texi | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

diff --git a/doc/automake.texi b/doc/automake.texi
index b2afca9..232721e 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -12750,12 +12750,29 @@ data.c: data.foo
         foo data.foo
 data.h: data.c
 ## Recover from the removal of $@@
+        @@test -f $@@ || rm -f data.c
+        @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.c
+@end example
+
+It is tempting to use a single test as follows:
+
+@example
+data.h: data.c
+## Recover from the removal of $@@
         @@if test -f $@@; then :; else \
           rm -f data.c; \
           $(MAKE) $(AM_MAKEFLAGS) data.c; \
         fi
 @end example
 
+@noindent
+but that would break @samp{make -n}: at least GNU @command{make} and
+Solaris @command{make} execute recipes containing the @samp{$(MAKE)}
+string even when they are running in dry mode.  So if we didn't break
+the recipe above in two invocations, the file @file{data.c} would be
+removed even upon @samp{make -n}.  Not nice.
+
+
 The above scheme can be extended to handle more outputs and more
 inputs.  One of the outputs is selected to serve as a witness to the
 successful completion of the command, it depends upon all inputs, and
@@ -12768,10 +12785,8 @@ data.c: data.foo data.bar
         foo data.foo data.bar
 data.h data.w data.x: data.c
 ## Recover from the removal of $@@
-        @@if test -f $@@; then :; else \
-          rm -f data.c; \
-          $(MAKE) $(AM_MAKEFLAGS) data.c; \
-        fi
+        @@test -f $@@ || rm -f data.c
+        @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.c
 @end example
 
 However there are now three minor problems in this setup.  One is related
@@ -12801,13 +12816,10 @@ A simple riposte is to fix the timestamps when this 
happens.
 data.c: data.foo data.bar
         foo data.foo data.bar
 data.h data.w data.x: data.c
-        @@if test -f $@@; then \
-          touch $@@; \
-        else \
+        @@test ! -f $@@ || touch $@@
 ## Recover from the removal of $@@
-          rm -f data.c; \
-          $(MAKE) $(AM_MAKEFLAGS) data.c; \
-        fi
+        @@test -f $@@ || rm -f data.c
+        @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.c
 @end example
 
 Another solution is to use a different and dedicated file as witness,
@@ -12821,10 +12833,8 @@ data.stamp: data.foo data.bar
         @@mv -f data.tmp $@@
 data.c data.h data.w data.x: data.stamp
 ## Recover from the removal of $@@
-        @@if test -f $@@; then :; else \
-          rm -f data.stamp; \
-          $(MAKE) $(AM_MAKEFLAGS) data.stamp; \
-        fi
+        @@test -f $@@ || rm -f data.stamp
+        @@test -f $@@ || $(MAKE) $(AM_MAKEFLAGS) data.stamp
 @end example
 
 @file{data.tmp} is created before @command{foo} is run, so it has a



reply via email to

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