Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 19e231b

Browse files
committed
Improved parallel make support
Replace for loops in makefiles with proper dependencies. Parallel make can now span across directories. Also, make -k and make -q work properly. GNU make 3.80 or newer is now required.
1 parent d6754f6 commit 19e231b

File tree

30 files changed

+156
-179
lines changed

30 files changed

+156
-179
lines changed

GNUmakefile.in

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,39 @@ subdir =
88
top_builddir = .
99
include $(top_builddir)/src/Makefile.global
1010

11+
$(call recurse,all install,src config)
12+
1113
all:
12-
$(MAKE) -C src all
13-
$(MAKE) -C config all
14-
@echo "All of PostgreSQL successfully made. Ready to install."
14+
+@echo "All of PostgreSQL successfully made. Ready to install."
1515

1616
docs:
1717
$(MAKE) -C doc all
1818

19+
$(call recurse,world,doc src config contrib,all)
1920
world:
20-
$(MAKE) -C doc all
21-
$(MAKE) -C src all
22-
$(MAKE) -C config all
23-
$(MAKE) -C contrib all
24-
@echo "PostgreSQL, contrib, and documentation successfully made. Ready to install."
21+
+@echo "PostgreSQL, contrib, and documentation successfully made. Ready to install."
2522

2623
html man:
2724
$(MAKE) -C doc $@
2825

2926
install:
30-
$(MAKE) -C src $@
31-
$(MAKE) -C config $@
32-
@echo "PostgreSQL installation complete."
27+
+@echo "PostgreSQL installation complete."
3328

3429
install-docs:
3530
$(MAKE) -C doc install
3631

32+
$(call recurse,install-world,doc src config contrib,install)
3733
install-world:
38-
$(MAKE) -C doc install
39-
$(MAKE) -C src install
40-
$(MAKE) -C config install
41-
$(MAKE) -C contrib install
42-
@echo "PostgreSQL, contrib, and documentation installation complete."
34+
+@echo "PostgreSQL, contrib, and documentation installation complete."
4335

44-
installdirs uninstall coverage:
45-
$(MAKE) -C doc $@
46-
$(MAKE) -C src $@
47-
$(MAKE) -C config $@
36+
$(call recurse,installdirs uninstall coverage,doc src config)
4837

49-
distprep:
50-
$(MAKE) -C doc $@
51-
$(MAKE) -C src $@
52-
$(MAKE) -C config $@
53-
$(MAKE) -C contrib $@
38+
$(call recurse,distprep,doc src config contrib)
5439

5540
# clean, distclean, etc should apply to contrib too, even though
5641
# it's not built by default
42+
$(call recurse,clean,doc contrib src config)
5743
clean:
58-
$(MAKE) -C doc $@
59-
$(MAKE) -C contrib $@
60-
$(MAKE) -C src $@
61-
$(MAKE) -C config $@
6244
# Garbage from autoconf:
6345
@rm -rf autom4te.cache/
6446

@@ -78,11 +60,7 @@ check: all
7860
check installcheck installcheck-parallel:
7961
$(MAKE) -C src/test $@
8062

81-
installcheck-world:
82-
$(MAKE) -C src/test installcheck
83-
$(MAKE) -C src/pl installcheck
84-
$(MAKE) -C src/interfaces/ecpg installcheck
85-
$(MAKE) -C contrib installcheck
63+
$(call recurse,installcheck-world,src/test src/pl src/interfaces/ecpg contrib,installcheck)
8664

8765
GNUmakefile: GNUmakefile.in $(top_builddir)/config.status
8866
./config.status $@
@@ -143,12 +121,4 @@ distcheck: dist
143121
rm -rf $(distdir) $(dummy)
144122
@echo "Distribution integrity checks out."
145123

146-
.PHONY: dist distdir distcheck docs install-docs
147-
148-
149-
# Temporary measure to explore whether we can start requiring GNU make
150-
# 3.80. That version also happens to be the version where the
151-
# .VARIABLES variable was introduced, so this is a simple check.
152-
ifndef .VARIABLES
153-
$(warning warning: GNU make 3.80 or newer might become required soon. You are using version $(MAKE_VERSION).)
154-
endif
124+
.PHONY: dist distdir distcheck docs install-docs world install-world installcheck-world

contrib/Makefile

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,4 @@ endif
6363
# start-scripts \ (does not have a makefile)
6464

6565

66-
all install installdirs uninstall distprep clean distclean maintainer-clean:
67-
@for dir in $(SUBDIRS); do \
68-
$(MAKE) -C $$dir $@ || exit; \
69-
done
70-
71-
# We'd like check operations to run all the subtests before failing.
72-
check installcheck:
73-
@CHECKERR=0; for dir in $(SUBDIRS); do \
74-
$(MAKE) -C $$dir $@ || CHECKERR=$$?; \
75-
done; \
76-
exit $$CHECKERR
66+
$(recurse)

contrib/dblink/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ MODULE_big = dblink
44
PG_CPPFLAGS = -I$(libpq_srcdir)
55
OBJS = dblink.o
66
SHLIB_LINK = $(libpq)
7+
SHLIB_PREREQS = submake-libpq
78

89
DATA_built = dblink.sql
910
DATA = uninstall_dblink.sql

doc/src/sgml/installation.sgml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ su - postgres
6868
<primary>make</primary>
6969
</indexterm>
7070

71-
<acronym>GNU</> <application>make</> is required; other
72-
<application>make</> programs will <emphasis>not</> work.
71+
<acronym>GNU</> <application>make</> version 3.80 or newer is required; other
72+
<application>make</> programs or older <acronym>GNU</> <application>make</> versions will <emphasis>not</> work.
7373
<acronym>GNU</> <application>make</> is often installed under
7474
the name <filename>gmake</filename>; this document will always
7575
refer to it by that name. (On some systems
@@ -79,7 +79,6 @@ su - postgres
7979
<screen>
8080
<userinput>gmake --version</userinput>
8181
</screen>
82-
It is recommended to use version 3.79.1 or later.
8382
</para>
8483
</listitem>
8584

src/Makefile

Lines changed: 14 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,21 @@ subdir = src
1212
top_builddir = ..
1313
include Makefile.global
1414

15+
SUBDIRS = \
16+
port \
17+
timezone \
18+
backend \
19+
backend/utils/mb/conversion_procs \
20+
backend/snowball \
21+
include \
22+
interfaces \
23+
backend/replication/libpqwalreceiver \
24+
bin \
25+
pl \
26+
makefiles \
27+
test/regress
1528

16-
all install installdirs uninstall distprep:
17-
$(MAKE) -C port $@
18-
$(MAKE) -C timezone $@
19-
$(MAKE) -C backend $@
20-
$(MAKE) -C backend/utils/mb/conversion_procs $@
21-
$(MAKE) -C backend/snowball $@
22-
$(MAKE) -C include $@
23-
$(MAKE) -C interfaces $@
24-
$(MAKE) -C backend/replication/libpqwalreceiver $@
25-
$(MAKE) -C bin $@
26-
$(MAKE) -C pl $@
27-
$(MAKE) -C makefiles $@
28-
$(MAKE) -C test/regress $@
29+
$(recurse)
2930

3031
install: install-local
3132

@@ -46,31 +47,11 @@ uninstall-local:
4647
rm -f $(addprefix '$(DESTDIR)$(pgxsdir)/$(subdir)'/, Makefile.global Makefile.port Makefile.shlib nls-global.mk)
4748

4849
clean:
49-
$(MAKE) -C port $@
50-
$(MAKE) -C timezone $@
51-
$(MAKE) -C backend $@
52-
$(MAKE) -C backend/snowball $@
53-
$(MAKE) -C include $@
54-
$(MAKE) -C interfaces $@
55-
$(MAKE) -C backend/replication/libpqwalreceiver $@
56-
$(MAKE) -C bin $@
57-
$(MAKE) -C pl $@
58-
$(MAKE) -C makefiles $@
5950
$(MAKE) -C test $@
6051
$(MAKE) -C tutorial NO_PGXS=1 $@
6152
$(MAKE) -C test/thread $@
6253

6354
distclean maintainer-clean:
64-
$(MAKE) -C port $@
65-
$(MAKE) -C timezone $@
66-
$(MAKE) -C backend $@
67-
$(MAKE) -C backend/snowball $@
68-
$(MAKE) -C include $@
69-
$(MAKE) -C interfaces $@
70-
$(MAKE) -C backend/replication/libpqwalreceiver $@
71-
$(MAKE) -C bin $@
72-
$(MAKE) -C pl $@
73-
$(MAKE) -C makefiles $@
7455
$(MAKE) -C test $@
7556
$(MAKE) -C tutorial NO_PGXS=1 $@
7657
$(MAKE) -C test/thread $@

src/Makefile.global.in

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
#
1919
# Meta configuration
2020

21-
.PHONY: all install install-strip installdirs uninstall clean distclean maintainer-clean distprep check installcheck maintainer-check coverage html man installcheck-parallel world install-world installcheck-world
21+
standard_targets = all install installdirs uninstall distprep clean distclean maintainer-clean coverage check installcheck
22+
23+
.PHONY: $(standard_targets) install-strip maintainer-check html man installcheck-parallel
2224

2325
# make `all' the default target
2426
all:
@@ -538,6 +540,48 @@ install-strip:
538540
install
539541

540542

543+
##########################################################################
544+
#
545+
# Recursive make support
546+
# ----------------------
547+
# Instead of recursing through subdirectories with a for loop or
548+
# repeated $(MAKE) -C whatever calls, this is a little smarter: it
549+
# allows parallel make across directories and lets make -k and -q work
550+
# correctly.
551+
552+
# This function is only for internal use below. It should be called
553+
# with $(eval). It will set up a target so that it recurses into
554+
# subdirectories.
555+
# $1: target name, e.g., all
556+
# $2: list of subdirs
557+
# $3: target to run in subdir, usually same as $1
558+
define _create_recursive_target
559+
.PHONY: $(patsubst %,$(1)-%-recursive,$(2))
560+
$(1): $(patsubst %,$(1)-%-recursive,$(2))
561+
$(2:%=$(1)-%-recursive):
562+
$$(MAKE) -C $$(patsubst $(1)-%-recursive,%,$$@) $(3)
563+
endef
564+
# Note that the use of $$ on the last line above is important; we want
565+
# those variables/functions to be evaluated when the rule is run, not
566+
# when the $(eval) is run to create the rule. In the case of
567+
# $$(MAKE), this is necessary to get make -q working.
568+
569+
# Call this function in a makefile. In the normal case it doesn't
570+
# need any arguments.
571+
# $1: targets to make recursive (defaults to list of standard targets)
572+
# $2: list of subdirs (defaults to SUBDIRS variable)
573+
# $3: target to run in subdir (defaults to $1)
574+
recurse = $(foreach target,$(if $1,$1,$(standard_targets)),$(eval $(call _create_recursive_target,$(target),$(if $2,$2,$(SUBDIRS)),$(if $3,$3,$(target)))))
575+
576+
# We need the $(eval) function and order-only prerequisites, which are
577+
# available in GNU make 3.80. That also happens to be the version
578+
# where the .VARIABLES variable was introduced, so this is a simple
579+
# check.
580+
ifndef .VARIABLES
581+
$(error GNU make 3.80 or newer is required. You are using version $(MAKE_VERSION))
582+
endif
583+
584+
541585
##########################################################################
542586
#
543587
# Automatic dependency generation
@@ -640,7 +684,6 @@ lcov.info: $(gcda_files)
640684
$(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
641685

642686
coverage: $(gcda_files:.gcda=.c.gcov) lcov.info
643-
$(if $(SUBDIRS),for dir in $(SUBDIRS); do $(MAKE) -C $$dir coverage || exit; done)
644687

645688
.PHONY: coverage-html
646689
coverage-html: coverage

src/Makefile.shlib

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
# OBJS List of object files to include in library
2323
# SHLIB_LINK If shared library relies on other libraries,
2424
# additional stuff to put in its link command
25+
# SHLIB_PREREQS Order-only prerequisites for library build target
2526
# SHLIB_EXPORTS (optional) Name of file containing list of symbols to
2627
# export, in the format "function_name number"
2728
#
@@ -340,7 +341,7 @@ all-static-lib: $(stlib)
340341
all-shared-lib: $(shlib)
341342

342343
ifndef haslibarule
343-
$(stlib): $(OBJS)
344+
$(stlib): $(OBJS) | $(SHLIB_PREREQS)
344345
$(LINK.static) $@ $^
345346
$(RANLIB) $@
346347
endif #haslibarule
@@ -351,7 +352,7 @@ ifeq (,$(filter cygwin win32,$(PORTNAME)))
351352
ifneq ($(PORTNAME), aix)
352353

353354
# Normal case
354-
$(shlib): $(OBJS)
355+
$(shlib): $(OBJS) | $(SHLIB_PREREQS)
355356
$(LINK.shared) -o $@ $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
356357
ifdef shlib_major
357358
# If we're using major and minor versions, then make a symlink to major-version-only.
@@ -382,7 +383,7 @@ endif
382383
else # PORTNAME == aix
383384

384385
# AIX case
385-
$(shlib) $(stlib): $(OBJS)
386+
$(shlib) $(stlib): $(OBJS) | $(SHLIB_PREREQS)
386387
$(LINK.static) $(stlib) $^
387388
$(RANLIB) $(stlib)
388389
$(MKLDEXPORT) $(stlib) >$(exports_file)
@@ -408,10 +409,10 @@ else
408409
DLL_DEFFILE = lib$(NAME)dll.def
409410
endif
410411

411-
$(shlib): $(OBJS) $(DLL_DEFFILE)
412+
$(shlib): $(OBJS) $(DLL_DEFFILE) | $(SHLIB_PREREQS)
412413
$(DLLWRAP) -o $@ --dllname $(shlib) $(DLLWRAP_FLAGS) --def $(DLL_DEFFILE) $(OBJS) $(LDFLAGS) $(LDFLAGS_SL) $(SHLIB_LINK)
413414

414-
$(stlib): $(shlib) $(DLL_DEFFILE)
415+
$(stlib): $(shlib) $(DLL_DEFFILE) | $(SHLIB_PREREQS)
415416
$(DLLTOOL) --dllname $(shlib) $(DLLTOOL_LIBFLAGS) --def $(DLL_DEFFILE) --output-lib $@
416417

417418
endif # PORTNAME == cygwin || PORTNAME == win32

src/backend/Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,9 @@ submake-schemapg:
122122

123123
.PHONY: submake-schemapg
124124

125-
catalog/schemapg.h: submake-schemapg
125+
catalog/schemapg.h: | submake-schemapg
126+
127+
$(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
126128

127129

128130
# The postgres.o target is needed by the rule in Makefile.global that

src/backend/common.mk

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,13 @@ objfiles.txt: Makefile $(SUBDIROBJS) $(OBJS)
3434
expand_subsys = $(foreach file,$(1),$(if $(filter %/objfiles.txt,$(file)),$(patsubst ../../src/backend/%,%,$(addprefix $(top_builddir)/,$(shell cat $(file)))),$(file)))
3535

3636
# Parallel make trickery
37-
$(SUBDIROBJS): $(SUBDIRS:%=%-recursive) ;
37+
$(SUBDIROBJS): | $(SUBDIRS:%=%-recursive) ;
3838

3939
.PHONY: $(SUBDIRS:%=%-recursive)
4040
$(SUBDIRS:%=%-recursive):
4141
$(MAKE) -C $(subst -recursive,,$@) all
4242

43+
$(call recurse,clean)
4344
clean: clean-local
4445
clean-local:
45-
ifdef SUBDIRS
46-
for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean || exit; done
47-
endif
4846
rm -f $(subsysfilename) $(OBJS)

src/backend/replication/libpqwalreceiver/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ override CPPFLAGS := -I$(srcdir) -I$(libpq_srcdir) $(CPPFLAGS)
1616

1717
OBJS = libpqwalreceiver.o
1818
SHLIB_LINK = $(libpq)
19+
SHLIB_PREREQS = submake-libpq
1920
NAME = libpqwalreceiver
2021

21-
all: submake-libpq all-shared-lib
22+
all: all-shared-lib
2223

2324
include $(top_srcdir)/src/Makefile.shlib
2425

0 commit comments

Comments
 (0)