Skip to content

Commit 3b8f6e7

Browse files
committed
Fix partial-build problems introduced by having more generated headers.
Commit 372728b 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
1 parent 468abb8 commit 3b8f6e7

File tree

10 files changed

+36
-42
lines changed

10 files changed

+36
-42
lines changed

doc/src/sgml/Makefile

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# to want to use.
1818
html:
1919

20+
# We don't need the tree-wide headers or install support here.
21+
NO_GENERATED_HEADERS=yes
2022
NO_TEMP_INSTALL=yes
2123

2224
subdir = doc/src/sgml

src/Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ endif
4141

4242
$(recurse)
4343

44-
# Update the commonly used headers before building the subdirectories;
45-
# otherwise, in a parallel build, several different sub-jobs will try to
46-
# remake them concurrently
47-
$(SUBDIRS:%=all-%-recurse): | submake-generated-headers
48-
4944
install: install-local
5045

5146
install-local: installdirs-local

src/Makefile.global.in

+33-6
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,39 @@ XGETTEXT = @XGETTEXT@
348348
GZIP = gzip
349349
BZIP2 = bzip2
350350

351+
352+
# Tree-wide build support
353+
354+
# Just about every code subdirectory wants to have the generated headers
355+
# available before building, but we don't want parallel makes all trying
356+
# to build the same headers. These rules, together with the recursion rules
357+
# below, ensure that we update the generated headers once, if needed,
358+
# at the top level of any "make all" or "make install" request. If a
359+
# particular subdirectory knows this isn't needed in itself or its children,
360+
# it can set NO_GENERATED_HEADERS.
361+
362+
all install: submake-generated-headers
363+
364+
.PHONY: submake-generated-headers
365+
366+
submake-generated-headers:
367+
ifndef NO_GENERATED_HEADERS
368+
ifeq ($(MAKELEVEL),0)
369+
$(MAKE) -C $(top_builddir)/src/backend generated-headers
370+
endif
371+
endif
372+
373+
351374
# Testing
352375

376+
# In much the same way as above, these rules ensure that we build a temp
377+
# install tree just once in any recursive "make check". The additional test
378+
# on abs_top_builddir prevents doing anything foolish to the root directory.
379+
353380
check: temp-install
354381

355382
.PHONY: temp-install
383+
356384
temp-install:
357385
ifndef NO_TEMP_INSTALL
358386
ifneq ($(abs_top_builddir),)
@@ -544,10 +572,7 @@ submake-libpgfeutils:
544572
$(MAKE) -C $(top_builddir)/src/common all
545573
$(MAKE) -C $(top_builddir)/src/fe_utils all
546574

547-
submake-generated-headers:
548-
$(MAKE) -C $(top_builddir)/src/backend generated-headers
549-
550-
.PHONY: submake-libpq submake-libpgport submake-libpgfeutils submake-generated-headers
575+
.PHONY: submake-libpq submake-libpgport submake-libpgfeutils
551576

552577

553578
##########################################################################
@@ -782,7 +807,9 @@ endif
782807

783808
# This function is only for internal use below. It should be called
784809
# using $(eval). It will set up a target so that it recurses into
785-
# a given subdirectory. Note that to avoid a nasty bug in make 3.80,
810+
# a given subdirectory. For the tree-wide all/install/check cases,
811+
# ensure we do our one-time tasks before recursing (see targets above).
812+
# Note that to avoid a nasty bug in make 3.80,
786813
# this function has to avoid using any complicated constructs (like
787814
# multiple targets on a line) and also not contain any lines that expand
788815
# to more than about 200 bytes. This is why we make it apply to just one
@@ -793,7 +820,7 @@ endif
793820
define _create_recursive_target
794821
.PHONY: $(1)-$(2)-recurse
795822
$(1): $(1)-$(2)-recurse
796-
$(1)-$(2)-recurse: $(if $(filter check, $(3)), temp-install)
823+
$(1)-$(2)-recurse: $(if $(filter all install, $(3)), submake-generated-headers) $(if $(filter check, $(3)), temp-install)
797824
$$(MAKE) -C $(2) $(3)
798825
endef
799826
# Note that the use of $$ on the last line above is important; we want

src/backend/Makefile

-8
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,6 @@ endif
111111

112112
endif # aix
113113

114-
# Update the commonly used headers before building the subdirectories
115-
$(SUBDIRS:%=%-recursive): | generated-headers
116-
117-
# src/port needs a convenient way to force just errcodes.h to get built
118-
submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h
119-
120-
.PHONY: submake-errcodes
121-
122114
$(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
123115

124116

src/backend/jit/llvm/Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ CFLAGS += $(LLVM_CFLAGS)
2727
CXXFLAGS += $(LLVM_CXXFLAGS)
2828
override CPPFLAGS := $(LLVM_CPPFLAGS) $(CPPFLAGS)
2929
SHLIB_LINK += $(LLVM_LIBS)
30-
SHLIB_PREREQS += submake-generated-headers
3130

3231
# Because this module includes C++ files, we need to use a C++
3332
# compiler for linking. Makefile.shlib uses $(COMPILER) to build

src/common/Makefile

-7
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,6 @@ libpgcommon_srv.a: $(OBJS_SRV)
8888
%_srv.o: %.c %.o
8989
$(CC) $(CFLAGS) $(subst -DFRONTEND ,, $(CPPFLAGS)) -c $< -o $@
9090

91-
$(OBJS_SRV): | submake-errcodes
92-
93-
.PHONY: submake-errcodes
94-
95-
submake-errcodes:
96-
$(MAKE) -C ../backend submake-errcodes
97-
9891
# Dependencies of keywords.o need to be managed explicitly to make sure
9992
# that you don't get broken parsing code, even in a non-enable-depend build.
10093
# Note that gram.h isn't required for the frontend version of keywords.o.

src/pl/plpython/Makefile

-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ include $(top_srcdir)/src/Makefile.shlib
9999

100100
all: all-lib
101101

102-
$(OBJS): | submake-generated-headers
103-
104-
105102
install: all install-lib install-data
106103

107104
installdirs: installdirs-lib

src/port/Makefile

-7
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ libpgport_srv.a: $(OBJS_SRV)
8787
%_srv.o: %.c %.o
8888
$(CC) $(CFLAGS) $(subst -DFRONTEND,, $(CPPFLAGS)) -c $< -o $@
8989

90-
$(OBJS_SRV): | submake-errcodes
91-
92-
.PHONY: submake-errcodes
93-
94-
submake-errcodes:
95-
$(MAKE) -C ../backend submake-errcodes
96-
9790
# Dependency is to ensure that path changes propagate
9891

9992
path.o: path.c pg_config_paths.h

src/test/modules/Makefile

-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,4 @@ SUBDIRS = \
2020
test_shm_mq \
2121
worker_spi
2222

23-
all: submake-generated-headers
24-
2523
$(recurse)

src/test/regress/GNUmakefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ include $(top_srcdir)/src/Makefile.shlib
6565

6666
all: all-lib
6767

68-
$(OBJS): | submake-generated-headers
69-
7068
# Test input and expected files. These are created by pg_regress itself, so we
7169
# don't have a rule to create them. We do need rules to clean them however.
7270
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 ;
107105

108106
$(top_builddir)/contrib/spi/autoinc$(DLSUFFIX): | submake-contrib-spi ;
109107

110-
submake-contrib-spi: | submake-libpgport submake-generated-headers
108+
submake-contrib-spi: | submake-libpgport
111109
$(MAKE) -C $(top_builddir)/contrib/spi
112110

113111
.PHONY: submake-contrib-spi

0 commit comments

Comments
 (0)