]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix make rules that generate multiple output files.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 23 Mar 2018 17:45:38 +0000 (13:45 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 23 Mar 2018 17:45:38 +0000 (13:45 -0400)
For years, our makefiles have correctly observed that "there is no correct
way to write a rule that generates two files".  However, what we did is to
provide empty rules that "generate" the secondary output files from the
primary one, and that's not right either.  Depending on the details of
the creating process, the primary file might end up timestamped later than
one or more secondary files, causing subsequent make runs to consider the
secondary file(s) out of date.  That's harmless in a plain build, since
make will just re-execute the empty rule and nothing happens.  But it's
fatal in a VPATH build, since make will expect the secondary file to be
rebuilt in the build directory.  This would manifest as "file not found"
failures during VPATH builds from tarballs, if we were ever unlucky enough
to ship a tarball with apparently out-of-date secondary files.  (It's not
clear whether that has ever actually happened, but it definitely could.)

To ensure that secondary output files have timestamps >= their primary's,
change our makefile convention to be that we provide a "touch $@" action
not an empty rule.  Also, make sure that this rule actually gets invoked
during a distprep run, else the hazard remains.

It's been like this a long time, so back-patch to all supported branches.

In HEAD, I skipped the changes in src/backend/catalog/Makefile, because
those rules are due to get replaced soon in the bootstrap data format
patch, and there seems no need to create a merge issue for that patch.
If for some reason we fail to land that patch in v11, we'll need to
back-fill the changes in that one makefile from v10.

Discussion: https://postgr.es/m/18556.1521668179@sss.pgh.pa.us

src/Makefile.shlib
src/backend/Makefile
src/backend/catalog/Makefile
src/backend/parser/Makefile
src/backend/utils/Makefile
src/bin/psql/Makefile
src/interfaces/ecpg/preproc/Makefile
src/pl/plpgsql/src/Makefile
src/test/isolation/Makefile

index 508eb9e81ea501fe97d070a1ebfb2b3dd34985f7..935e9070a74a49ef3cd43e4a6bd809717169adbb 100644 (file)
@@ -358,13 +358,9 @@ else # PORTNAME == aix
 
 # AIX case
 
-# There is no correct way to write a rule that generates two files.
-# Rules with two targets don't have that meaning, they are merely
-# shorthand for two otherwise separate rules.  To be safe for parallel
-# make, we must chain the dependencies like this.  The semicolon is
-# important, otherwise make will choose some built-in rule.
-
-$(stlib): $(shlib) ;
+# See notes in src/backend/parser/Makefile about the following two rules
+$(stlib): $(shlib)
+       touch $@
 
 $(shlib): $(OBJS) | $(SHLIB_PREREQS)
        rm -f $(stlib)
index 1169bafb08cad95c32d587dfedc0247808434903..0986f8ce105f1a80c355ab442cf639dc4b32136f 100644 (file)
@@ -141,6 +141,12 @@ postgres.o: $(OBJS)
 # The following targets are specified in make commands that appear in
 # the make files in our subdirectories. Note that it's important we
 # match the dependencies shown in the subdirectory makefiles!
+# Also, in cases where a subdirectory makefile generates two files in
+# what's really one step, such as bison producing both gram.h and gram.c,
+# we must request making the one that is shown as the secondary (dependent)
+# output, else the timestamp on it might be wrong.  By project convention,
+# the .h file is the dependent one for bison output, so we need only request
+# that; but in other cases, request both for safety.
 
 parser/gram.h: parser/gram.y
        $(MAKE) -C parser gram.h
index c4d3f3c1dcc11a5d3fa87297b60199b5b082d16e..ab088ff22a5ea72ea5d4625617c5891ab1ef313a 100644 (file)
@@ -21,7 +21,7 @@ BKIFILES = postgres.bki postgres.description postgres.shdescription
 
 include $(top_srcdir)/src/backend/common.mk
 
-all: $(BKIFILES) schemapg.h
+all: $(BKIFILES) schemapg.h postgres.description postgres.shdescription
 
 # Note: there are some undocumented dependencies on the ordering in which
 # the catalog header files are assembled into postgres.bki.  In particular,
@@ -50,12 +50,15 @@ catalogdir = $(top_srcdir)/src/backend/catalog
 # locations of headers that genbki.pl needs to read
 pg_includes = -I$(top_srcdir)/src/include/catalog -I$(top_builddir)/src/include/catalog
 
-# see explanation in ../parser/Makefile
-postgres.description: postgres.bki ;
+# see notes in src/backend/parser/Makefile about multiple output files
+postgres.description: postgres.bki
+       touch $@
 
-postgres.shdescription: postgres.bki ;
+postgres.shdescription: postgres.bki
+       touch $@
 
-schemapg.h: postgres.bki ;
+schemapg.h: postgres.bki
+       touch $@
 
 # Technically, this should depend on Makefile.global, but then
 # postgres.bki would need to be rebuilt after every configure run,
index 9cc8946fa1bc3480b68ae0eedf0e8a77691187bd..b06d39cc84f2bb09dd1b2722e8df64c16c7ff413 100644 (file)
@@ -28,12 +28,17 @@ endif
 
 # There is no correct way to write a rule that generates two files.
 # Rules with two targets don't have that meaning, they are merely
-# shorthand for two otherwise separate rules.  To be safe for parallel
-# make, we must chain the dependencies like this.  The semicolon is
-# important, otherwise make will choose the built-in rule for
-# gram.y=>gram.c.
-
-gram.h: gram.c ;
+# shorthand for two otherwise separate rules.  If we have an action
+# that in fact generates two or more files, we must choose one of them
+# as primary and show it as the action's output, then make all of the
+# other output files dependent on the primary, like this.  Furthermore,
+# the "touch" action is essential, because it ensures that gram.h is
+# marked as newer than (or at least no older than) gram.c.  Without that,
+# make is likely to try to rebuild gram.h in subsequent runs, which causes
+# failures in VPATH builds from tarballs.
+
+gram.h: gram.c
+       touch $@
 
 gram.c: BISONFLAGS += -d
 gram.c: BISON_CHECK_CMD = $(PERL) $(srcdir)/check_keywords.pl $< $(top_srcdir)/src/include/parser/kwlist.h
index 837453371802fb2b2fb2f73ea9bc4044d6af779c..7540f10541fcc1eb9e0cbef50dee674b4ec7b7df 100644 (file)
@@ -20,8 +20,9 @@ all: errcodes.h fmgroids.h probes.h
 
 $(SUBDIRS:%=%-recursive): fmgroids.h
 
-# see explanation in ../parser/Makefile
-fmgroids.h: fmgrtab.c ;
+# see notes in src/backend/parser/Makefile
+fmgroids.h: fmgrtab.c
+       touch $@
 
 fmgrtab.c: Gen_fmgrtab.pl $(catalogdir)/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
        $(PERL) -I $(catalogdir) $< $(top_srcdir)/src/include/catalog/pg_proc.h
index 7878ca625892ad8185335da66e89b05756f8897d..33bcd14fe6504946ac45a56a0093115a0e418b4c 100644 (file)
@@ -40,7 +40,10 @@ dumputils.c keywords.c: % : $(top_srcdir)/src/bin/pg_dump/%
 kwlookup.c: % : $(top_srcdir)/src/backend/parser/%
        rm -f $@ && $(LN_S) $< .
 
-sql_help.c: sql_help.h ;
+# See notes in src/backend/parser/Makefile about the following two rules
+sql_help.c: sql_help.h
+       touch $@
+
 sql_help.h: create_help.pl $(wildcard $(REFDOCDIR)/*.sgml)
        $(PERL) $< $(REFDOCDIR) $*
 
@@ -50,7 +53,7 @@ mainloop.o: psqlscan.c
 psqlscan.c: FLEXFLAGS = -Cfe -p -p
 psqlscan.c: FLEX_NO_BACKUP=yes
 
-distprep: sql_help.h psqlscan.c
+distprep: sql_help.h sql_help.c psqlscan.c
 
 install: all installdirs
        $(INSTALL_PROGRAM) psql$(X) '$(DESTDIR)$(bindir)/psql$(X)'
index 8651f3011120b8af6bb8623aad77fe767fd7aace..15c6ed186f216e5d1dc19e914198de58ad34e2fa 100644 (file)
@@ -44,7 +44,10 @@ ecpg: $(OBJS) | submake-libpgport
 ../ecpglib/typename.o: ../ecpglib/typename.c
        $(MAKE) -C $(dir $@) $(notdir $@)
 
-preproc.h: preproc.c ;
+# See notes in src/backend/parser/Makefile about the following two rules
+preproc.h: preproc.c
+       touch $@
+
 preproc.c: BISONFLAGS += -d
 
 preproc.y: ../../../backend/parser/gram.y parse.pl ecpg.addons ecpg.header ecpg.tokens ecpg.trailer ecpg.type
index 852b0c7ae4928d1e12e85d5b43cd228839014af8..97e805774224a65cc8f98217e0917ddf08ce0c57 100644 (file)
@@ -55,7 +55,9 @@ uninstall-headers:
 pl_gram.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o pl_scanner.o: plpgsql.h pl_gram.h plerrcodes.h
 
 # See notes in src/backend/parser/Makefile about the following two rules
-pl_gram.h: pl_gram.c ;
+pl_gram.h: pl_gram.c
+       touch $@
+
 pl_gram.c: BISONFLAGS += -d
 
 # generate plerrcodes.h from src/backend/utils/errcodes.txt
index 5e5c9bb74eed097f14a81d58e2abfff882f6dc0f..ec1179e717e4fcd649633b1422b001c02ea005a2 100644 (file)
@@ -29,15 +29,6 @@ isolationtester$(X): $(OBJS) | submake-libpq submake-libpgport
 
 distprep: specparse.c specscanner.c
 
-# There is no correct way to write a rule that generates two files.
-# Rules with two targets don't have that meaning, they are merely
-# shorthand for two otherwise separate rules.  To be safe for parallel
-# make, we must chain the dependencies like this.  The semicolon is
-# important, otherwise make will choose the built-in rule for
-# gram.y=>gram.c.
-
-specparse.h: specparse.c ;
-
 # specscanner is compiled as part of specparse
 specparse.o: specscanner.c