]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
docs: promote Makefile snippets that work properly with make -n.
authorAkim Demaille <akim@gnu.org>
Fri, 29 May 2020 00:45:15 +0000 (17:45 -0700)
committerKarl Berry <karl@freefriends.org>
Fri, 29 May 2020 00:45:15 +0000 (17:45 -0700)
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

index b2afca9622c8fdc5ea2f08b9d77f0c5905603589..232721e110842995d787e8ba109f25391810b59f 100644 (file)
@@ -12749,6 +12749,15 @@ missing.  Here it is:
 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; \
@@ -12756,6 +12765,14 @@ data.h: 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