build: fix race in parallel builds
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 23 Aug 2014 14:55:28 +0000 (07:55 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 23 Aug 2014 14:55:54 +0000 (07:55 -0700)
Reported by Friedrich Beckmann in: http://bugs.gnu.org/18301
* lib/am/texi-vers.am (?DIRSTAMP?): Put the process-ID into the
temporary file name.  Use a similar temporary in the source dir.

lib/am/texi-vers.am

index bddf3827d85483a4b0b3c8b4349e8b152907a83c..e98bb8234979433e2443416ff9f9358f4e445287 100644 (file)
@@ -31,25 +31,25 @@ DIST_COMMON += %VTEXI% %STAMPVTI%
 ## %STAMPVTI% is distributed and %DIRSTAMP% isn't: a distributed file
 ## should never be dependent upon a non-distributed built file.
 ## Therefore we ensure that %DIRSTAMP% exists in the rule.
+## Use cp + mv so that the update of %VTEXI% is atomic even if
+## the source directory is on a different file system.
 ?DIRSTAMP?     @test -f %DIRSTAMP% || $(MAKE) $(AM_MAKEFLAGS) %DIRSTAMP%
        @(dir=.; test -f ./%TEXI% || dir=$(srcdir); \
        set `$(SHELL) %MDDIR%mdate-sh $$dir/%TEXI%`; \
        echo "@set UPDATED $$1 $$2 $$3"; \
        echo "@set UPDATED-MONTH $$2 $$3"; \
        echo "@set EDITION $(VERSION)"; \
-       echo "@set VERSION $(VERSION)") > %VTI%.tmp
-## Use cp and rm here because some older "mv"s can't move across
-## filesystems.  Furthermore, GNU "mv" in the AmigaDOS environment
-## can't handle this.
-       @cmp -s %VTI%.tmp %VTEXI% \
-         || (echo "Updating %VTEXI%"; \
-             cp %VTI%.tmp %VTEXI%)
-       -@rm -f %VTI%.tmp
+       echo "@set VERSION $(VERSION)") > %VTI%.tmp$$$$ && \
+       (cmp -s %VTI%.tmp$$$$ %VTEXI% \
+         || (echo "Updating %VTEXI%" && \
+             cp %VTI%.tmp$$$$ %VTEXI%.tmp$$$$ && \
+             mv %VTEXI%.tmp$$$$ %VTEXI%)) && \
+       rm -f %VTI%.tmp$$$$ %VTEXI%.$$$$
        @cp %VTEXI% $@
 
 mostlyclean-am: mostlyclean-%VTI%
 mostlyclean-%VTI%:
-       -rm -f %VTI%.tmp
+       -rm -f %VTI%.tmp* %VTEXI%.tmp*
 
 maintainer-clean-am: maintainer-clean-%VTI%
 maintainer-clean-%VTI%: