summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAkim Demaille <akim@gnu.org>2020-05-28 17:45:15 -0700
committerKarl Berry <karl@freefriends.org>2020-05-28 17:45:15 -0700
commit660dfaeb24e5a17e6f2ef9baf53e0c90f6324daa (patch)
tree2abe464c2caf003fe6e8113e9d7b3391ab373af5 /doc
parentc838e0428cd4c1566b78fb0d1aab398e86c37d6f (diff)
downloadautomake-660dfaeb24e5a17e6f2ef9baf53e0c90f6324daa.tar.gz
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.
Diffstat (limited to 'doc')
-rw-r--r--doc/automake.texi38
1 files changed, 24 insertions, 14 deletions
diff --git a/doc/automake.texi b/doc/automake.texi
index b2afca962..232721e11 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