1 #-------------------------------------------------------------------------
3 # Makefile for the postgres backend
5 # Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
6 # Portions Copyright (c) 1994, Regents of the University of California
8 # $PostgreSQL: pgsql/src/backend/Makefile,v 1.136 2009/09/05 21:14:04 tgl Exp $
10 #-------------------------------------------------------------------------
12 PGFILEDESC = "PostgreSQL Server"
15 include $(top_builddir)/src/Makefile.global
17 SUBDIRS = access bootstrap catalog parser commands executor foreign lib libpq \
18 main nodes optimizer port postmaster regex rewrite \
19 storage tcop tsearch utils $(top_builddir)/src/timezone
21 include $(srcdir)/common.mk
24 # * The probes.o file is necessary for dtrace support on Solaris.
25 # * OS X's dtrace doesn't use it and doesn't even recognize the -G option.
26 # * Systemtap's dtrace will take -G, but it produces a useless empty file.
27 # So, build probes.o only on Solaris.
28 # This will likely need adjustment as other platforms add dtrace support.
29 ifeq ($(PORTNAME), solaris)
30 ifeq ($(enable_dtrace), yes)
31 LOCALOBJS += utils/probes.o
35 OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
37 # We put libpgport into OBJS, so remove it from LIBS; also add libldap
38 LIBS := $(filter-out -lpgport, $(LIBS)) $(LDAP_LIBS_BE)
40 # The backend doesn't need everything that's in LIBS, however
41 LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
43 ##########################################################################
45 all: submake-libpgport postgres $(POSTGRES_IMP)
47 ifneq ($(PORTNAME), cygwin)
48 ifneq ($(PORTNAME), win32)
49 ifneq ($(PORTNAME), aix)
52 $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
58 ifeq ($(PORTNAME), cygwin)
60 postgres: $(OBJS) postgres.def libpostgres.a
61 $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
62 $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
63 $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
64 $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
68 $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
70 libpostgres.a: postgres.def
71 $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
75 ifeq ($(PORTNAME), win32)
78 postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
79 $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
80 $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
81 $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
82 $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
86 $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
88 libpostgres.a: postgres.def
89 $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
93 ifeq ($(PORTNAME), aix)
95 postgres: $(POSTGRES_IMP)
96 $(CC) $(CFLAGS) $(LDFLAGS) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
98 $(POSTGRES_IMP): $(OBJS)
99 $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
100 ifeq ($(host_os), aix3.2.5)
101 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
103 ifneq (,$(findstring aix4.1, $(host_os)))
104 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
106 $(MKLDEXPORT) SUBSYS.o . > $@
113 # Update the commonly used headers before building the subdirectories
114 $(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/probes.h
117 # The postgres.o target is needed by the rule in Makefile.global that
118 # creates the exports file when MAKE_EXPORTS = true.
120 $(CC) $(LDREL) $(LDFLAGS) $(call expand_subsys,$^) $(LIBS) -o $@
123 # The following targets are specified in make commands that appear in
124 # the make files in our subdirectories. Note that it's important we
125 # match the dependencies shown in the subdirectory makefiles!
127 parser/gram.h: parser/gram.y
128 $(MAKE) -C parser gram.h
130 utils/fmgroids.h: utils/Gen_fmgrtab.sh $(top_srcdir)/src/include/catalog/pg_proc.h
131 $(MAKE) -C utils fmgroids.h
133 utils/probes.h: utils/probes.d
134 $(MAKE) -C utils probes.h
136 # Make symlinks for these headers in the include directory. That way
137 # we can cut down on the -I options. Also, a symlink is automatically
138 # up to date when we update the base file.
140 $(top_builddir)/src/include/parser/gram.h: parser/gram.h
141 prereqdir=`cd $(dir $<) >/dev/null && pwd` && \
142 cd $(dir $@) && rm -f $(notdir $@) && \
143 $(LN_S) "$$prereqdir/$(notdir $<)" .
145 $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
146 cd $(dir $@) && rm -f $(notdir $@) && \
147 $(LN_S) ../../../$(subdir)/utils/fmgroids.h .
149 $(top_builddir)/src/include/utils/probes.h: utils/probes.h
150 cd $(dir $@) && rm -f $(notdir $@) && \
151 $(LN_S) ../../../$(subdir)/utils/probes.h .
154 utils/probes.o: utils/probes.d $(SUBDIROBJS)
155 $(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@
158 ##########################################################################
161 $(MAKE) -C parser gram.c gram.h scan.c
162 $(MAKE) -C bootstrap bootparse.c bootscanner.c
163 $(MAKE) -C utils/misc guc-file.c
166 ##########################################################################
168 install: all installdirs install-bin
169 ifeq ($(PORTNAME), cygwin)
170 ifeq ($(MAKE_DLL), true)
171 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
174 ifeq ($(PORTNAME), win32)
175 ifeq ($(MAKE_DLL), true)
176 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
179 $(MAKE) -C catalog install-data
180 $(MAKE) -C tsearch install-data
181 $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample'
182 $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample'
183 $(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample'
184 $(INSTALL_DATA) $(srcdir)/access/transam/recovery.conf.sample '$(DESTDIR)$(datadir)/recovery.conf.sample'
186 install-bin: postgres $(POSTGRES_IMP) installdirs
187 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
188 ifneq ($(PORTNAME), win32)
189 @rm -f '$(DESTDIR)$(bindir)/postmaster$(X)'
190 ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
192 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
194 ifeq ($(MAKE_EXPORTS), true)
195 $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
201 $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
202 ifeq ($(PORTNAME), cygwin)
203 ifeq ($(MAKE_DLL), true)
204 $(MKDIR_P) '$(DESTDIR)$(libdir)'
207 ifeq ($(PORTNAME), win32)
208 ifeq ($(MAKE_DLL), true)
209 $(MKDIR_P) '$(DESTDIR)$(libdir)'
212 ifeq ($(MAKE_EXPORTS), true)
213 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
217 ##########################################################################
220 rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster'
221 ifeq ($(MAKE_EXPORTS), true)
222 rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
224 ifeq ($(PORTNAME), cygwin)
225 ifeq ($(MAKE_DLL), true)
226 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
229 ifeq ($(PORTNAME), win32)
230 ifeq ($(MAKE_DLL), true)
231 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
234 $(MAKE) -C catalog uninstall-data
235 $(MAKE) -C tsearch uninstall-data
236 rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \
237 '$(DESTDIR)$(datadir)/pg_ident.conf.sample' \
238 '$(DESTDIR)$(datadir)/postgresql.conf.sample' \
239 '$(DESTDIR)$(datadir)/recovery.conf.sample'
242 ##########################################################################
245 rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
246 $(top_srcdir)/src/include/parser/gram.h \
247 $(top_builddir)/src/include/utils/fmgroids.h
248 ifeq ($(PORTNAME), cygwin)
249 rm -f postgres.dll postgres.def libpostgres.a
251 ifeq ($(PORTNAME), win32)
252 rm -f postgres.dll postgres.def libpostgres.a $(WIN32RES)
256 rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
258 maintainer-clean: distclean
259 rm -f bootstrap/bootparse.c \
260 bootstrap/bootscanner.c \
264 utils/misc/guc-file.c
267 ##########################################################################
269 # Support for code development.
271 # Use target "quick" to build "postgres" when you know all the subsystems
272 # are up to date. It saves the time of doing all the submakes.
275 $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres