[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
multiple outputs rule
From: |
Bruno Haible |
Subject: |
multiple outputs rule |
Date: |
Thu, 14 Dec 2006 15:04:20 +0100 |
User-agent: |
KMail/1.9.1 |
Hi,
The automake-1.10 documentation contains this sample rule:
data.c data.h data.w data.x: data.stamp
## Recover from the removal of $@
@if test -f $@; then :; else \
trap 'rm -rf data.lock data.stamp 1 2 13 15; \
## mkdir is a portable test-and-set
if mkdir data.lock 2>/dev/null; then \
## This code is being executed by the first process.
rm -f data.stamp; \
$(MAKE) $(AM_MAKEFLAGS) data.stamp; \
else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
while test -d data.lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
test -f data.stamp; exit $$?; \
fi; \
fi
Three things appear fishy here:
1) There's a single quote missing in the trap line.
2) When the first branch of the "if mkdir ..." is executed, the data.lock
directory is never removed. It should be removed after the recursive $(MAKE)
invocation, preserving the return code.
3) When the second branch of the "if mkdir ..." is executed, the "exit $?"
is unnecessary, since without it the return code of the "test -f data.stamp"
is the return code of the entire command anyway.
So it can be corrected/simplified like this:
data.c data.h data.w data.x: data.stamp
## Recover from the removal of $@
@if test -f $@; then :; else \
trap 'rm -rf data.lock data.stamp' 1 2 13 15; \
## mkdir is a portable test-and-set
if mkdir data.lock 2>/dev/null; then \
## This code is being executed by the first process.
rm -f data.stamp; \
$(MAKE) $(AM_MAKEFLAGS) data.stamp; \
result=$$?; rm -rf data.lock data.stamp; exit $$result; \
else \
## This code is being executed by the follower processes.
## Wait until the first process is done.
while test -d data.lock; do sleep 1; done; \
## Succeed if and only if the first process succeeded.
test -f data.stamp; \
fi; \
fi
Bruno
- multiple outputs rule,
Bruno Haible <=