1 #-------------------------------------------------------------------------
3 # Makefile for the postgres backend
5 # Portions Copyright (c) 1996-2014, 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 \
39 $(top_builddir)/src/common/libpgcommon_srv.a
41 # We put libpgport and libpgcommon into OBJS, so remove it from LIBS; also add
43 LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE)
45 # The backend doesn't need everything that's in LIBS, however
46 LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
48 ##########################################################################
50 all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
52 ifneq ($(PORTNAME), cygwin)
53 ifneq ($(PORTNAME), win32)
54 ifneq ($(PORTNAME), aix)
57 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
63 ifeq ($(PORTNAME), cygwin)
66 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) -Wl,--stack,$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(call expand_subsys,$^) $(LIBS) -o $@
68 # There is no correct way to write a rule that generates two files.
69 # Rules with two targets don't have that meaning, they are merely
70 # shorthand for two otherwise separate rules. To be safe for parallel
71 # make, we must chain the dependencies like this. The semicolon is
72 # important, otherwise make will choose some built-in rule.
74 libpostgres.a: postgres ;
78 ifeq ($(PORTNAME), win32)
81 postgres: $(OBJS) $(WIN32RES)
82 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LIBS) -o $@$(X)
84 libpostgres.a: postgres ;
88 ifeq ($(PORTNAME), aix)
90 postgres: $(POSTGRES_IMP)
91 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -o $@
93 $(POSTGRES_IMP): $(OBJS)
94 $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
95 ifeq ($(host_os), aix3.2.5)
96 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
98 ifneq (,$(findstring aix4.1, $(host_os)))
99 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
101 $(MKLDEXPORT) SUBSYS.o . > $@
108 # Update the commonly used headers before building the subdirectories
109 $(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/errcodes.h $(top_builddir)/src/include/utils/probes.h
111 # run this unconditionally to avoid needing to know its dependencies here:
113 $(MAKE) -C catalog schemapg.h
115 # src/port needs a convenient way to force errcodes.h to get built
116 submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h
118 .PHONY: submake-schemapg submake-errcodes
120 catalog/schemapg.h: | submake-schemapg
122 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
125 # The postgres.o target is needed by the rule in Makefile.global that
126 # creates the exports file when MAKE_EXPORTS = true.
128 $(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@
131 # The following targets are specified in make commands that appear in
132 # the make files in our subdirectories. Note that it's important we
133 # match the dependencies shown in the subdirectory makefiles!
135 parser/gram.h: parser/gram.y
136 $(MAKE) -C parser gram.h
138 utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
139 $(MAKE) -C utils fmgroids.h
141 utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
142 $(MAKE) -C utils errcodes.h
144 utils/probes.h: utils/probes.d
145 $(MAKE) -C utils probes.h
147 # Make symlinks for these headers in the include directory. That way
148 # we can cut down on the -I options. Also, a symlink is automatically
149 # up to date when we update the base file.
151 # The point of the prereqdir incantation in some of the rules below is to
152 # force the symlink to use an absolute path rather than a relative path.
153 # For headers which are generated by make distprep, the actual header within
154 # src/backend will be in the source tree, while the symlink in src/include
155 # will be in the build tree, so a simple ../.. reference won't work.
156 # For headers generated during regular builds, we prefer a relative symlink.
158 $(top_builddir)/src/include/parser/gram.h: parser/gram.h
159 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
160 cd '$(dir $@)' && rm -f $(notdir $@) && \
161 $(LN_S) "$$prereqdir/$(notdir $<)" .
163 $(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
164 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
165 cd '$(dir $@)' && rm -f $(notdir $@) && \
166 $(LN_S) "$$prereqdir/$(notdir $<)" .
168 $(top_builddir)/src/include/utils/errcodes.h: utils/errcodes.h
169 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
170 cd '$(dir $@)' && rm -f $(notdir $@) && \
171 $(LN_S) "$$prereqdir/$(notdir $<)" .
173 $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
174 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
175 cd '$(dir $@)' && rm -f $(notdir $@) && \
176 $(LN_S) "$$prereqdir/$(notdir $<)" .
178 $(top_builddir)/src/include/utils/probes.h: utils/probes.h
179 cd '$(dir $@)' && rm -f $(notdir $@) && \
180 $(LN_S) "../../../$(subdir)/utils/probes.h" .
183 utils/probes.o: utils/probes.d $(SUBDIROBJS)
184 $(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@
187 ##########################################################################
189 # Be sure that these files get removed by the maintainer-clean target
191 $(MAKE) -C parser gram.c gram.h scan.c
192 $(MAKE) -C bootstrap bootparse.c bootscanner.c
193 $(MAKE) -C catalog schemapg.h postgres.bki postgres.description postgres.shdescription
194 $(MAKE) -C replication repl_gram.c repl_scanner.c
195 $(MAKE) -C utils fmgrtab.c fmgroids.h errcodes.h
196 $(MAKE) -C utils/misc guc-file.c
197 $(MAKE) -C utils/sort qsort_tuple.c
200 ##########################################################################
202 install: all installdirs install-bin
203 ifeq ($(PORTNAME), cygwin)
204 ifeq ($(MAKE_DLL), true)
205 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
208 ifeq ($(PORTNAME), win32)
209 ifeq ($(MAKE_DLL), true)
210 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
213 $(MAKE) -C catalog install-data
214 $(MAKE) -C tsearch install-data
215 $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample'
216 $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample'
217 $(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample'
218 $(INSTALL_DATA) $(srcdir)/access/transam/recovery.conf.sample '$(DESTDIR)$(datadir)/recovery.conf.sample'
220 install-bin: postgres $(POSTGRES_IMP) installdirs
221 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
222 ifneq ($(PORTNAME), win32)
223 @rm -f '$(DESTDIR)$(bindir)/postmaster$(X)'
224 ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
226 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
228 ifeq ($(MAKE_EXPORTS), true)
229 $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
230 $(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
236 $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
237 ifeq ($(PORTNAME), cygwin)
238 ifeq ($(MAKE_DLL), true)
239 $(MKDIR_P) '$(DESTDIR)$(libdir)'
242 ifeq ($(PORTNAME), win32)
243 ifeq ($(MAKE_DLL), true)
244 $(MKDIR_P) '$(DESTDIR)$(libdir)'
247 ifeq ($(MAKE_EXPORTS), true)
248 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
249 $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
253 ##########################################################################
256 rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster'
257 ifeq ($(MAKE_EXPORTS), true)
258 rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
259 rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
261 ifeq ($(PORTNAME), cygwin)
262 ifeq ($(MAKE_DLL), true)
263 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
266 ifeq ($(PORTNAME), win32)
267 ifeq ($(MAKE_DLL), true)
268 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
271 $(MAKE) -C catalog uninstall-data
272 $(MAKE) -C tsearch uninstall-data
273 rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \
274 '$(DESTDIR)$(datadir)/pg_ident.conf.sample' \
275 '$(DESTDIR)$(datadir)/postgresql.conf.sample' \
276 '$(DESTDIR)$(datadir)/recovery.conf.sample'
279 ##########################################################################
282 rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
283 $(top_builddir)/src/include/parser/gram.h \
284 $(top_builddir)/src/include/catalog/schemapg.h \
285 $(top_builddir)/src/include/utils/fmgroids.h \
286 $(top_builddir)/src/include/utils/probes.h
287 ifeq ($(PORTNAME), cygwin)
288 rm -f postgres.dll libpostgres.a
290 ifeq ($(PORTNAME), win32)
291 rm -f postgres.dll libpostgres.a $(WIN32RES)
295 rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c \
298 maintainer-clean: distclean
299 rm -f bootstrap/bootparse.c \
300 bootstrap/bootscanner.c \
305 catalog/postgres.bki \
306 catalog/postgres.description \
307 catalog/postgres.shdescription \
308 replication/repl_gram.c \
309 replication/repl_scanner.c \
313 utils/misc/guc-file.c \
314 utils/sort/qsort_tuple.c
317 ##########################################################################
319 # Support for code development.
321 # Use target "quick" to build "postgres" when you know all the subsystems
322 # are up to date. It saves the time of doing all the submakes.
325 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres