src/libpspp/Makefile.am: Fix atomicity of version.c generation.
authorBen Pfaff <blp@cs.stanford.edu>
Fri, 27 Nov 2020 23:05:55 +0000 (15:05 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Fri, 27 Nov 2020 23:11:21 +0000 (15:11 -0800)
If the Makefile has a bug, or someone runs two "make"s in parallel, the
approach of truncating version.c then appending to it line by line,
reopening the file each time, can wind up with a nasty partial result.  By
generating it in a single go, and then replacing the file atomically, we
avoid that problem.

src/libpspp/automake.mk

index 0cde825f5b52d5aa1c220a35bc65b4af80eeecbb..99b6bed70020c19e233440cec50d569ac5f0d2ff 100644 (file)
@@ -128,26 +128,27 @@ nodist_src_libpspp_liblibpspp_la_SOURCES = src/libpspp/version.c
 
 src/libpspp/version.c: $(top_srcdir)/AUTHORS Makefile
        @$(MKDIR_P) src/libpspp
-       $(AM_V_GEN)echo "/*     -*- mode: c; buffer-read-only: t -*-" > $@,tmp
-       $(AM_V_at)echo "   Generated by src/libpspp/automake.mk --- Do not edit.">> $@,tmp
-       $(AM_V_at)echo "" >> $@,tmp
-       $(AM_V_at)echo "   The following line is for the benefit of the perl module" >>$@,tmp
-       $(AM_V_at)echo "\$$VERSION='$(VERSION_FOR_PERL)';" >> $@,tmp
-       $(AM_V_at)echo "*/" >> $@,tmp
-       $(AM_V_at)echo "#include \"version.h\"" >> $@,tmp
-       $(AM_V_at)echo "const char bare_version[] = \"$(VERSION)\";" >> $@,tmp
-       $(AM_V_at)echo "const char version[] = \"GNU $(PACKAGE) $(VERSION)\";" >> $@,tmp
-       $(AM_V_at)printf "const char announced_version[] = \"GNU $(PACKAGE) $(VERSION)\"" >> $@,tmp
-       @case `echo $(VERSION) | $(SED) -e 's/[0-9][0-9]*\.[0-9]*\([0-9]\)\.[0-9][0-9]*/\1/'` in \
-         [13579]) printf "\"\\\nThis is an unreleased test version. It is not recommended for production use. Use at your own risk\"" >> $@,tmp \
-       ;;\
-       esac
-       $(AM_V_at)printf ";\n" >> $@,tmp
-       $(AM_V_at)echo "const char host_system[] = \"$(host_triplet)\";" >> $@,tmp
-       $(AM_V_at)echo "const char build_system[] = \"$(build_triplet)\";" >> $@,tmp
-       $(AM_V_at)echo "const char locale_dir[] = \"$(datadir)/locale\";" >> $@,tmp
-       $(AM_V_at)echo "const char examples_dir[] = \"$(examplesdir)\";" >> $@,tmp
-       $(AM_V_at)echo "const char *const authors[] = {" >> $@,tmp
-       $(AM_V_at)$(SED) -e 's/^/  \"/' -e 's/$$/\",/' $(top_srcdir)/AUTHORS >> $@,tmp
-       $(AM_V_at)echo "0 };" >> $@,tmp
-       $(AM_V_at)mv $@,tmp $@
+       { \
+         echo "/*      -*- mode: c; buffer-read-only: t -*-"; \
+         echo "   Generated by src/libpspp/automake.mk --- Do not edit."; \
+         echo; \
+         echo "   The following line is for the benefit of the perl module"; \
+         echo "\$$VERSION='$(VERSION_FOR_PERL)';"; \
+         echo "*/"; \
+         echo "#include \"version.h\""; \
+         echo "const char bare_version[] = \"$(VERSION)\";"; \
+         echo "const char version[] = \"GNU $(PACKAGE) $(VERSION)\";"; \
+         printf "const char announced_version[] = \"GNU $(PACKAGE) $(VERSION)\""; \
+         case `echo $(VERSION) | $(SED) -e 's/[0-9][0-9]*\.[0-9]*\([0-9]\)\.[0-9][0-9]*/\1/'` in \
+           [13579]) printf "\"\\\nThis is an unreleased test version. It is not recommended for production use. Use at your own risk\"" ;; \
+         esac; \
+         printf ";\n"; \
+         echo "const char host_system[] = \"$(host_triplet)\";"; \
+         echo "const char build_system[] = \"$(build_triplet)\";"; \
+         echo "const char locale_dir[] = \"$(datadir)/locale\";"; \
+         echo "const char examples_dir[] = \"$(examplesdir)\";"; \
+         echo "const char *const authors[] = {"; \
+         $(SED) -e 's/^/  \"/' -e 's/$$/\",/' $(top_srcdir)/AUTHORS; \
+         echo "  0"; \
+          echo "};"; \
+       } > $@,tmp && mv $@,tmp $@