1 #-------------------------------------------------------------------------
3 # Makefile for the postgres backend
5 # Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group
6 # Portions Copyright (c) 1994, Regents of the University of California
10 #-------------------------------------------------------------------------
12 PGFILEDESC = "PostgreSQL Server"
13 # This is a daemon process, which is why it is not labeled as an executable
18 include $(top_builddir)/src/Makefile.global
20 SUBDIRS = access bootstrap catalog parser commands executor foreign lib libpq \
21 main nodes optimizer port postmaster regex replication rewrite \
22 storage tcop tsearch utils $(top_builddir)/src/timezone
24 include $(srcdir)/common.mk
27 # The probes.o file is necessary for dtrace support on Solaris, and on recent
28 # versions of systemtap. (Older systemtap releases just produce an empty
29 # file, but that's okay.) However, OS X's dtrace doesn't use it and doesn't
30 # even recognize the -G option. So, build probes.o except on Darwin.
31 # This might need adjustment as other platforms add dtrace support.
32 ifneq ($(PORTNAME), darwin)
33 ifeq ($(enable_dtrace), yes)
34 LOCALOBJS += utils/probes.o
38 OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a
40 # We put libpgport into OBJS, so remove it from LIBS; also add libldap
41 LIBS := $(filter-out -lpgport, $(LIBS)) $(LDAP_LIBS_BE)
43 # The backend doesn't need everything that's in LIBS, however
44 LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
46 ##########################################################################
48 all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
50 ifneq ($(PORTNAME), cygwin)
51 ifneq ($(PORTNAME), win32)
52 ifneq ($(PORTNAME), aix)
55 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
61 ifeq ($(PORTNAME), cygwin)
63 postgres: $(OBJS) postgres.def libpostgres.a
64 $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
65 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
66 $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
67 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack,$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(LIBS)
71 $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
73 libpostgres.a: postgres.def
74 $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
78 ifeq ($(PORTNAME), win32)
81 postgres: $(OBJS) postgres.def libpostgres.a $(WIN32RES)
82 $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
83 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
84 $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
85 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -o $@$(X) $@.exp $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS)
89 $(DLLTOOL) --export-all --output-def $@ $(call expand_subsys,$^)
91 libpostgres.a: postgres.def
92 $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
96 ifeq ($(PORTNAME), aix)
98 postgres: $(POSTGRES_IMP)
99 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
101 $(POSTGRES_IMP): $(OBJS)
102 $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
103 ifeq ($(host_os), aix3.2.5)
104 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
106 ifneq (,$(findstring aix4.1, $(host_os)))
107 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
109 $(MKLDEXPORT) SUBSYS.o . > $@
116 # Update the commonly used headers before building the subdirectories
117 $(SUBDIRS:%=%-recursive): $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/probes.h
119 # run this unconditionally to avoid needing to know its dependencies here:
121 $(MAKE) -C catalog schemapg.h
123 .PHONY: submake-schemapg
125 catalog/schemapg.h: | submake-schemapg
127 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
130 # The postgres.o target is needed by the rule in Makefile.global that
131 # creates the exports file when MAKE_EXPORTS = true.
133 $(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@
136 # The following targets are specified in make commands that appear in
137 # the make files in our subdirectories. Note that it's important we
138 # match the dependencies shown in the subdirectory makefiles!
140 parser/gram.h: parser/gram.y
141 $(MAKE) -C parser gram.h
143 utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
144 $(MAKE) -C utils fmgroids.h
146 utils/probes.h: utils/probes.d
147 $(MAKE) -C utils probes.h
149 # Make symlinks for these headers in the include directory. That way
150 # we can cut down on the -I options. Also, a symlink is automatically
151 # up to date when we update the base file.
153 # The point of the prereqdir incantation in some of the rules below is to
154 # force the symlink to use an absolute path rather than a relative path.
155 # For headers which are generated by make distprep, the actual header within
156 # src/backend will be in the source tree, while the symlink in src/include
157 # will be in the build tree, so a simple ../.. reference won't work.
158 # For headers generated during regular builds, we prefer a relative symlink.
160 $(top_builddir)/src/include/parser/gram.h: parser/gram.h
161 prereqdir=`cd $(dir $<) >/dev/null && pwd` && \
162 cd $(dir $@) && rm -f $(notdir $@) && \
163 $(LN_S) "$$prereqdir/$(notdir $<)" .
165 $(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
166 prereqdir=`cd $(dir $<) >/dev/null && pwd` && \
167 cd $(dir $@) && rm -f $(notdir $@) && \
168 $(LN_S) "$$prereqdir/$(notdir $<)" .
170 $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
171 prereqdir=`cd $(dir $<) >/dev/null && pwd` && \
172 cd $(dir $@) && rm -f $(notdir $@) && \
173 $(LN_S) "$$prereqdir/$(notdir $<)" .
175 $(top_builddir)/src/include/utils/probes.h: utils/probes.h
176 cd $(dir $@) && rm -f $(notdir $@) && \
177 $(LN_S) ../../../$(subdir)/utils/probes.h .
180 utils/probes.o: utils/probes.d $(SUBDIROBJS)
181 $(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@
184 ##########################################################################
187 $(MAKE) -C parser gram.c gram.h scan.c
188 $(MAKE) -C bootstrap bootparse.c bootscanner.c
189 $(MAKE) -C catalog schemapg.h postgres.bki postgres.description postgres.shdescription
190 $(MAKE) -C utils fmgrtab.c fmgroids.h
191 $(MAKE) -C utils/misc guc-file.c
194 ##########################################################################
196 install: all installdirs install-bin
197 ifeq ($(PORTNAME), cygwin)
198 ifeq ($(MAKE_DLL), true)
199 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
202 ifeq ($(PORTNAME), win32)
203 ifeq ($(MAKE_DLL), true)
204 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
207 $(MAKE) -C catalog install-data
208 $(MAKE) -C tsearch install-data
209 $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample'
210 $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample'
211 $(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample'
212 $(INSTALL_DATA) $(srcdir)/access/transam/recovery.conf.sample '$(DESTDIR)$(datadir)/recovery.conf.sample'
214 install-bin: postgres $(POSTGRES_IMP) installdirs
215 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
216 ifneq ($(PORTNAME), win32)
217 @rm -f '$(DESTDIR)$(bindir)/postmaster$(X)'
218 ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
220 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
222 ifeq ($(MAKE_EXPORTS), true)
223 $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
229 $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
230 ifeq ($(PORTNAME), cygwin)
231 ifeq ($(MAKE_DLL), true)
232 $(MKDIR_P) '$(DESTDIR)$(libdir)'
235 ifeq ($(PORTNAME), win32)
236 ifeq ($(MAKE_DLL), true)
237 $(MKDIR_P) '$(DESTDIR)$(libdir)'
240 ifeq ($(MAKE_EXPORTS), true)
241 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
245 ##########################################################################
248 rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster'
249 ifeq ($(MAKE_EXPORTS), true)
250 rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
252 ifeq ($(PORTNAME), cygwin)
253 ifeq ($(MAKE_DLL), true)
254 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
257 ifeq ($(PORTNAME), win32)
258 ifeq ($(MAKE_DLL), true)
259 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
262 $(MAKE) -C catalog uninstall-data
263 $(MAKE) -C tsearch uninstall-data
264 rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \
265 '$(DESTDIR)$(datadir)/pg_ident.conf.sample' \
266 '$(DESTDIR)$(datadir)/postgresql.conf.sample' \
267 '$(DESTDIR)$(datadir)/recovery.conf.sample'
270 ##########################################################################
273 rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
274 $(top_builddir)/src/include/parser/gram.h \
275 $(top_builddir)/src/include/catalog/schemapg.h \
276 $(top_builddir)/src/include/utils/fmgroids.h \
277 $(top_builddir)/src/include/utils/probes.h
278 ifeq ($(PORTNAME), cygwin)
279 rm -f postgres.dll postgres.def libpostgres.a
281 ifeq ($(PORTNAME), win32)
282 rm -f postgres.dll postgres.def libpostgres.a $(WIN32RES)
286 rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c \
289 maintainer-clean: distclean
290 rm -f bootstrap/bootparse.c \
291 bootstrap/bootscanner.c \
296 catalog/postgres.bki \
297 catalog/postgres.description \
298 catalog/postgres.shdescription \
301 utils/misc/guc-file.c
304 ##########################################################################
306 # Support for code development.
308 # Use target "quick" to build "postgres" when you know all the subsystems
309 # are up to date. It saves the time of doing all the submakes.
312 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres