Re: gettext-0.14.2 fails on parallel build

From:

Bruno Haible

Subject:

Re: gettext-0.14.2 fails on parallel build

Date:

Wed, 16 Mar 2005 15:08:06 +0100

User-agent:

KMail/1.5

Alexandre Duret-Lutz wrote:
> Thanks, I'm installing the following fix on HEAD and branch-1-9.
> ...
> -## Recover from the removal of $@
> - @if test ! -f $@; then \
> +## Recover from the removal of address@hidden
> +##
> +## Make sure not to call `make elc-stamp' if emacs is not available,
> +## because as all *.elc files appear as missing, a parallel make would
> +## attempt to build elc-stamp several times.
> + @if test "$(EMACS)" != no && test ! -f $@; then \
IMO this does not fix the bug. It only makes it less likely to appear.
What happened was: In the rules
elc-stamp: $(LISP)
@rm -f elc-temp && touch elc-temp
...
@mv -f elc-temp $@
3 independent 'make' processes started working on this rule.
Process 1 created elc-temp.
Process 2 re-created elc-temp.
Then process 1 and process 2 performed the "..." task.
Process 1 moved elc-temp to elc-stemp.
Process 2 attempted to do so as well, but elc-temp was already gone.
For this to happen, the contents of the "..." task is irrelevant.
Adding "test "$(EMACS)" != no" doesn't change the problem.
The bug could still occur when the "..." task is very quick.
The fix I would propose instead is to change
mv -f elc-temp $@
to
mv -f elc-temp $@ || { touch $@; rm -f elc-temp; }
This will ensure that the process which comes too late succeeds nevertheless.
Bruno