# Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California
#
-# $PostgreSQL: pgsql/src/backend/Makefile,v 1.125 2008/01/01 19:45:45 momjian Exp $
+# $PostgreSQL: pgsql/src/backend/Makefile,v 1.126 2008/02/25 17:55:42 petere Exp $
#
#-------------------------------------------------------------------------
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)
ifneq ($(PORTNAME), aix)
postgres: $(OBJS)
- $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@
+ $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
endif
endif
postgres: $(OBJS) postgres.def libpostgres.a
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
$(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(OBJS) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
rm -f $@.exp $@.base
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 $@
postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(WIN32RES) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
$(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
- $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(OBJS) $(WIN32RES) $(LIBS)
+ $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
rm -f $@.exp $@.base
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 $@
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
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
$(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 $@
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
# 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
#
# Common make rules for backend
#
-# $PostgreSQL: pgsql/src/backend/common.mk,v 1.1 2008/02/19 10:30:06 petere Exp $
+# $PostgreSQL: pgsql/src/backend/common.mk,v 1.2 2008/02/25 17:55:42 petere Exp $
#
-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)