From 3b8f6e75f3c8c6d192621f21624cc8cee04ec3cb Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 9 Apr 2018 16:42:02 -0400 Subject: [PATCH] Fix partial-build problems introduced by having more generated headers. Commit 372728b0d created some problems for usages like building a subdirectory without having first done "make all" at the top level, or for proceeding directly to "make install" without "make all". The only reasonably clean way to fix this seems to be to force the submake-generated-headers rule to fire in *any* "make all" or "make install" command anywhere in the tree. To avoid lots of redundant work, as well as parallel make jobs possibly clobbering each others' output, we still need to be sure that the rule fires only once in a recursive build. For that, adopt the same MAKELEVEL hack previously used for "temp-install". But try to document it a bit better. The submake-errcodes mechanism previously used in src/port/ and src/common/ is subsumed by this, so we can get rid of those special cases. It was inadequate for src/common/ anyway after the aforesaid commit, and it always risked parallel attempts to build errcodes.h. Discussion: https://postgr.es/m/E1f5FAB-0006LU-MB@gemulon.postgresql.org --- doc/src/sgml/Makefile | 2 ++ src/Makefile | 5 ----- src/Makefile.global.in | 39 +++++++++++++++++++++++++++++------ src/backend/Makefile | 8 ------- src/backend/jit/llvm/Makefile | 1 - src/common/Makefile | 7 ------- src/pl/plpython/Makefile | 3 --- src/port/Makefile | 7 ------- src/test/modules/Makefile | 2 -- src/test/regress/GNUmakefile | 4 +--- 10 files changed, 36 insertions(+), 42 deletions(-) diff --git a/doc/src/sgml/Makefile b/doc/src/sgml/Makefile index f122b4187f..74aac01c39 100644 --- a/doc/src/sgml/Makefile +++ b/doc/src/sgml/Makefile @@ -17,6 +17,8 @@ # to want to use. html: +# We don't need the tree-wide headers or install support here. +NO_GENERATED_HEADERS=yes NO_TEMP_INSTALL=yes subdir = doc/src/sgml diff --git a/src/Makefile b/src/Makefile index 0e56399cb9..bcdbd9588a 100644 --- a/src/Makefile +++ b/src/Makefile @@ -41,11 +41,6 @@ endif $(recurse) -# Update the commonly used headers before building the subdirectories; -# otherwise, in a parallel build, several different sub-jobs will try to -# remake them concurrently -$(SUBDIRS:%=all-%-recurse): | submake-generated-headers - install: install-local install-local: installdirs-local diff --git a/src/Makefile.global.in b/src/Makefile.global.in index 19c9c1e11e..20090b360e 100644 --- a/src/Makefile.global.in +++ b/src/Makefile.global.in @@ -348,11 +348,39 @@ XGETTEXT = @XGETTEXT@ GZIP = gzip BZIP2 = bzip2 + +# Tree-wide build support + +# Just about every code subdirectory wants to have the generated headers +# available before building, but we don't want parallel makes all trying +# to build the same headers. These rules, together with the recursion rules +# below, ensure that we update the generated headers once, if needed, +# at the top level of any "make all" or "make install" request. If a +# particular subdirectory knows this isn't needed in itself or its children, +# it can set NO_GENERATED_HEADERS. + +all install: submake-generated-headers + +.PHONY: submake-generated-headers + +submake-generated-headers: +ifndef NO_GENERATED_HEADERS +ifeq ($(MAKELEVEL),0) + $(MAKE) -C $(top_builddir)/src/backend generated-headers +endif +endif + + # Testing +# In much the same way as above, these rules ensure that we build a temp +# install tree just once in any recursive "make check". The additional test +# on abs_top_builddir prevents doing anything foolish to the root directory. + check: temp-install .PHONY: temp-install + temp-install: ifndef NO_TEMP_INSTALL ifneq ($(abs_top_builddir),) @@ -544,10 +572,7 @@ submake-libpgfeutils: $(MAKE) -C $(top_builddir)/src/common all $(MAKE) -C $(top_builddir)/src/fe_utils all -submake-generated-headers: - $(MAKE) -C $(top_builddir)/src/backend generated-headers - -.PHONY: submake-libpq submake-libpgport submake-libpgfeutils submake-generated-headers +.PHONY: submake-libpq submake-libpgport submake-libpgfeutils ########################################################################## @@ -782,7 +807,9 @@ endif # This function is only for internal use below. It should be called # using $(eval). It will set up a target so that it recurses into -# a given subdirectory. Note that to avoid a nasty bug in make 3.80, +# a given subdirectory. For the tree-wide all/install/check cases, +# ensure we do our one-time tasks before recursing (see targets above). +# Note that to avoid a nasty bug in make 3.80, # this function has to avoid using any complicated constructs (like # multiple targets on a line) and also not contain any lines that expand # to more than about 200 bytes. This is why we make it apply to just one @@ -793,7 +820,7 @@ endif define _create_recursive_target .PHONY: $(1)-$(2)-recurse $(1): $(1)-$(2)-recurse -$(1)-$(2)-recurse: $(if $(filter check, $(3)), temp-install) +$(1)-$(2)-recurse: $(if $(filter all install, $(3)), submake-generated-headers) $(if $(filter check, $(3)), temp-install) $$(MAKE) -C $(2) $(3) endef # Note that the use of $$ on the last line above is important; we want diff --git a/src/backend/Makefile b/src/backend/Makefile index 82a59eac2d..1aaf1ec2f5 100644 --- a/src/backend/Makefile +++ b/src/backend/Makefile @@ -111,14 +111,6 @@ endif endif # aix -# Update the commonly used headers before building the subdirectories -$(SUBDIRS:%=%-recursive): | generated-headers - -# src/port needs a convenient way to force just errcodes.h to get built -submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h - -.PHONY: submake-errcodes - $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport diff --git a/src/backend/jit/llvm/Makefile b/src/backend/jit/llvm/Makefile index d7a36d7371..e2db4cea65 100644 --- a/src/backend/jit/llvm/Makefile +++ b/src/backend/jit/llvm/Makefile @@ -27,7 +27,6 @@ CFLAGS += $(LLVM_CFLAGS) CXXFLAGS += $(LLVM_CXXFLAGS) override CPPFLAGS := $(LLVM_CPPFLAGS) $(CPPFLAGS) SHLIB_LINK += $(LLVM_LIBS) -SHLIB_PREREQS += submake-generated-headers # Because this module includes C++ files, we need to use a C++ # compiler for linking. Makefile.shlib uses $(COMPILER) to build diff --git a/src/common/Makefile b/src/common/Makefile index e9e75867f3..1fc2c66225 100644 --- a/src/common/Makefile +++ b/src/common/Makefile @@ -88,13 +88,6 @@ libpgcommon_srv.a: $(OBJS_SRV) %_srv.o: %.c %.o $(CC) $(CFLAGS) $(subst -DFRONTEND ,, $(CPPFLAGS)) -c $< -o $@ -$(OBJS_SRV): | submake-errcodes - -.PHONY: submake-errcodes - -submake-errcodes: - $(MAKE) -C ../backend submake-errcodes - # Dependencies of keywords.o need to be managed explicitly to make sure # that you don't get broken parsing code, even in a non-enable-depend build. # Note that gram.h isn't required for the frontend version of keywords.o. diff --git a/src/pl/plpython/Makefile b/src/pl/plpython/Makefile index d09910835d..fb785496ea 100644 --- a/src/pl/plpython/Makefile +++ b/src/pl/plpython/Makefile @@ -99,9 +99,6 @@ include $(top_srcdir)/src/Makefile.shlib all: all-lib -$(OBJS): | submake-generated-headers - - install: all install-lib install-data installdirs: installdirs-lib diff --git a/src/port/Makefile b/src/port/Makefile index f328b705e4..d7467fb078 100644 --- a/src/port/Makefile +++ b/src/port/Makefile @@ -87,13 +87,6 @@ libpgport_srv.a: $(OBJS_SRV) %_srv.o: %.c %.o $(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@ -$(OBJS_SRV): | submake-errcodes - -.PHONY: submake-errcodes - -submake-errcodes: - $(MAKE) -C ../backend submake-errcodes - # Dependency is to ensure that path changes propagate path.o: path.c pg_config_paths.h diff --git a/src/test/modules/Makefile b/src/test/modules/Makefile index a9b8377acf..19d60a506e 100644 --- a/src/test/modules/Makefile +++ b/src/test/modules/Makefile @@ -20,6 +20,4 @@ SUBDIRS = \ test_shm_mq \ worker_spi -all: submake-generated-headers - $(recurse) diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile index deef08dfc1..7ba4e9c5ab 100644 --- a/src/test/regress/GNUmakefile +++ b/src/test/regress/GNUmakefile @@ -65,8 +65,6 @@ include $(top_srcdir)/src/Makefile.shlib all: all-lib -$(OBJS): | submake-generated-headers - # Test input and expected files. These are created by pg_regress itself, so we # don't have a rule to create them. We do need rules to clean them however. input_files = $(patsubst $(srcdir)/input/%.source,sql/%.sql, $(wildcard $(srcdir)/input/*.source)) @@ -107,7 +105,7 @@ $(top_builddir)/contrib/spi/refint$(DLSUFFIX): | submake-contrib-spi ; $(top_builddir)/contrib/spi/autoinc$(DLSUFFIX): | submake-contrib-spi ; -submake-contrib-spi: | submake-libpgport submake-generated-headers +submake-contrib-spi: | submake-libpgport $(MAKE) -C $(top_builddir)/contrib/spi .PHONY: submake-contrib-spi