summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Eisentraut2008-02-25 17:55:42 +0000
committerPeter Eisentraut2008-02-25 17:55:42 +0000
commite61e976cd89ebba7ede635518d4963cb0014a409 (patch)
tree4b2f35bceda8f1ab9d24443cb3ad87a489668b8e
parent6d530226f1cf34fe58b062085e67822490f9205f (diff)
Link postgres from all object files at once, to avoid the error-prone
SUBSYS.o step and allow for better optimization by the linker. Instead of partial linking into SUBSYS.o, the list of object files is assembled in objfiles.txt files that are expanded when the final linking is done. Because we are not yet sure how long command lines different platforms can handle, the old way of linking is still available, by defining the make variable PARTIAL_LINKING (e.g., make all PARTIAL_LINKING=1). If we determine that this is necessary for some platforms, then we will document this in a more prominent place.
-rw-r--r--src/backend/Makefile38
-rw-r--r--src/backend/common.mk30
2 files changed, 42 insertions, 26 deletions
diff --git a/src/backend/Makefile b/src/backend/Makefile
index e79359af5a..4362dd51b8 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -14,17 +14,17 @@ subdir = src/backend
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
-DIRS = access bootstrap catalog parser commands executor lib libpq \
+SUBDIRS = access bootstrap catalog parser commands executor lib libpq \
main nodes optimizer port postmaster regex rewrite \
storage tcop tsearch utils $(top_builddir)/src/timezone
-SUBSYSOBJS = $(DIRS:%=%/SUBSYS.o)
+include $(srcdir)/common.mk
ifeq ($(enable_dtrace), yes)
LOCALOBJS += utils/probes.o
endif
-OBJS = $(SUBSYSOBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
+OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
# We put libpgport into OBJS, so remove it from LIBS; also add libldap
LIBS := $(filter-out -lpgport, $(LIBS)) $(LDAP_LIBS_BE)
@@ -41,7 +41,7 @@ ifneq ($(PORTNAME), win32)
ifneq ($(PORTNAME), aix)
postgres: $(OBJS)
- $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
endif
endif
@@ -51,13 +51,13 @@ ifeq ($(PORTNAME), cygwin)
postgres: $(OBJS) postgres.def libpostgres.a
$(DLLTOOL) --dllname $@$(X) --output-exp [email protected] --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,[email protected] [email protected] $(OBJS) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,[email protected] [email protected] $(call expand_subsys,$(OBJS)) $(LIBS)
$(DLLTOOL) --dllname $@$(X) --base-file [email protected] --output-exp [email protected] --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) [email protected] $(OBJS) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) [email protected] $(call expand_subsys,$(OBJS)) $(LIBS)
postgres.def: $(OBJS)
- $(DLLTOOL) --export-all --output-def $@ $^
+ $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
libpostgres.a: postgres.def
$(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
@@ -69,13 +69,13 @@ LIBS += -lsecur32
postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
$(DLLTOOL) --dllname $@$(X) --output-exp [email protected] --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,[email protected] [email protected] $(OBJS) $(WIN32RES) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,[email protected] [email protected] $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
$(DLLTOOL) --dllname $@$(X) --base-file [email protected] --output-exp [email protected] --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) [email protected] $(OBJS) $(WIN32RES) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) [email protected] $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
postgres.def: $(OBJS)
- $(DLLTOOL) --export-all --output-def $@ $^
+ $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
libpostgres.a: postgres.def
$(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
@@ -85,10 +85,10 @@ endif # win32
ifeq ($(PORTNAME), aix)
postgres: $(POSTGRES_IMP)
- $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
$(POSTGRES_IMP): $(OBJS)
- $(LD) $(LDREL) $(LDOUT) SUBSYS.o $^
+ $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
ifeq ($(host_os), aix3.2.5)
$(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
else
@@ -102,19 +102,14 @@ endif
endif # aix
-# Parallel make trickery
-$(SUBSYSOBJS): $(DIRS:%=%-recursive) ;
-
-.PHONY: $(DIRS:%=%-recursive)
# Update the commonly used headers before building the subdirectories
-$(DIRS:%=%-recursive): $(top_builddir)/src/include/parser/parse.h $(top_builddir)/src/include/utils/fmgroids.h
- $(MAKE) -C $(subst -recursive,,$@) all
+$(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/parse.h $(top_builddir)/src/include/utils/fmgroids.h
# The postgres.o target is needed by the rule in Makefile.global that
# creates the exports file when MAKE_EXPORTS = true.
postgres.o: $(OBJS)
- $(CC) $(LDREL) $(LDFLAGS) $^ $(LIBS) -o $@
+ $(CC) $(LDREL) $(LDFLAGS) $(call expand_subsys,$^) $(LIBS) -o $@
# The following targets are specified in make commands that appear in
@@ -141,7 +136,7 @@ $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
$(LN_S) ../../../$(subdir)/utils/fmgroids.h .
-utils/probes.o: utils/probes.d $(SUBSYSOBJS)
+utils/probes.o: utils/probes.d $(SUBDIROBJS)
$(DTRACE) $(DTRACEFLAGS) -G -s $^ -o $@
@@ -241,7 +236,6 @@ endif
ifeq ($(PORTNAME), win32)
rm -f postgres.dll postgres.def libpostgres.a $(WIN32RES)
endif
- for i in $(DIRS); do $(MAKE) -C $$i clean || exit; done
distclean: clean
rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
@@ -264,4 +258,4 @@ maintainer-clean: distclean
# are up to date. It saves the time of doing all the submakes.
.PHONY: quick
quick: $(OBJS)
- $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o postgres
+ $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres
diff --git a/src/backend/common.mk b/src/backend/common.mk
index 17eec6f8da..46c75bd17a 100644
--- a/src/backend/common.mk
+++ b/src/backend/common.mk
@@ -4,22 +4,44 @@
# $PostgreSQL$
#
-SUBDIROBJS = $(SUBDIRS:%=%/SUBSYS.o)
+# When including this file, set OBJS to the object files created in
+# this directory and SUBDIRS to subdirectories containing more things
+# to build.
-all: SUBSYS.o
+ifdef PARTIAL_LINKING
+# old style: linking using SUBSYS.o
+subsysfilename = SUBSYS.o
+else
+# new style: linking all object files at once
+subsysfilename = objfiles.txt
+endif
+
+SUBDIROBJS = $(SUBDIRS:%=%/$(subsysfilename))
+
+# top-level backend directory obviously has its own "all" target
+ifneq ($(subdir), src/backend)
+all: $(subsysfilename)
+endif
SUBSYS.o: $(SUBDIROBJS) $(OBJS)
$(LD) $(LDREL) $(LDOUT) $@ $^
+objfiles.txt: $(SUBDIROBJS) $(OBJS)
+ ( $(if $(SUBDIROBJS),cat $(SUBDIROBJS); )echo $(addprefix $(subdir)/,$(OBJS)) ) >$@
+
+# make function to expand objfiles.txt contents
+expand_subsys = $(foreach file,$(filter %/objfiles.txt,$(1)),$(patsubst ../../src/backend/%,%,$(addprefix $(top_builddir)/,$(shell cat $(file))))) $(filter-out %/objfiles.txt,$(1))
+
+# Parallel make trickery
$(SUBDIROBJS): $(SUBDIRS:%=%-recursive) ;
.PHONY: $(SUBDIRS:%=%-recursive)
$(SUBDIRS:%=%-recursive):
- $(MAKE) -C $(subst -recursive,,$@) SUBSYS.o
+ $(MAKE) -C $(subst -recursive,,$@) all
clean: clean-local
clean-local:
ifdef SUBDIRS
for dir in $(SUBDIRS); do $(MAKE) -C $$dir clean || exit; done
endif
- rm -f SUBSYS.o $(OBJS)
+ rm -f $(subsysfilename) $(OBJS)