1 #-------------------------------------------------------------------------
3 # Makefile for the postgres backend
5 # Portions Copyright (c) 1996-2017, 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, macOS's dtrace doesn't use it and doesn't
30 # even recognize the -G option. So, build probes.o except on macOS.
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 ifeq ($(with_systemd),yes)
52 ##########################################################################
54 all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
56 ifneq ($(PORTNAME), cygwin)
57 ifneq ($(PORTNAME), win32)
58 ifneq ($(PORTNAME), aix)
61 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
67 ifeq ($(PORTNAME), cygwin)
70 $(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 $@
72 # There is no correct way to write a rule that generates two files.
73 # Rules with two targets don't have that meaning, they are merely
74 # shorthand for two otherwise separate rules. To be safe for parallel
75 # make, we must chain the dependencies like this. The semicolon is
76 # important, otherwise make will choose some built-in rule.
78 libpostgres.a: postgres ;
82 ifeq ($(PORTNAME), win32)
85 postgres: $(OBJS) $(WIN32RES)
86 $(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)
88 libpostgres.a: postgres ;
92 ifeq ($(PORTNAME), aix)
94 postgres: $(POSTGRES_IMP)
95 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
97 $(POSTGRES_IMP): $(OBJS)
98 $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
99 ifeq ($(host_os), aix3.2.5)
100 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
102 ifneq (,$(findstring aix4.1, $(host_os)))
103 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
105 $(MKLDEXPORT) SUBSYS.o . > $@
112 # Update the commonly used headers before building the subdirectories
113 $(SUBDIRS:%=%-recursive): | generated-headers
115 # src/port needs a convenient way to force just errcodes.h to get built
116 submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h
118 .PHONY: submake-errcodes
120 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
123 # The postgres.o target is needed by the rule in Makefile.global that
124 # creates the exports file when MAKE_EXPORTS = true.
126 $(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@
129 # The following targets are specified in make commands that appear in
130 # the make files in our subdirectories. Note that it's important we
131 # match the dependencies shown in the subdirectory makefiles!
133 parser/gram.h: parser/gram.y
134 $(MAKE) -C parser gram.h
136 storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt
137 $(MAKE) -C storage/lmgr lwlocknames.h
139 utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
140 $(MAKE) -C utils errcodes.h
142 # see explanation in parser/Makefile
143 utils/fmgrprotos.h: utils/fmgroids.h ;
145 utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
146 $(MAKE) -C utils $(notdir $@)
148 utils/probes.h: utils/probes.d
149 $(MAKE) -C utils probes.h
151 # run this unconditionally to avoid needing to know its dependencies here:
152 catalog/schemapg.h: | submake-schemapg
155 $(MAKE) -C catalog schemapg.h
157 .PHONY: submake-schemapg
159 # Make symlinks for these headers in the include directory. That way
160 # we can cut down on the -I options. Also, a symlink is automatically
161 # up to date when we update the base file.
163 # The point of the prereqdir incantation in some of the rules below is to
164 # force the symlink to use an absolute path rather than a relative path.
165 # For headers which are generated by make distprep, the actual header within
166 # src/backend will be in the source tree, while the symlink in src/include
167 # will be in the build tree, so a simple ../.. reference won't work.
168 # For headers generated during regular builds, we prefer a relative symlink.
170 .PHONY: generated-headers
172 generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/catalog/schemapg.h $(top_builddir)/src/include/storage/lwlocknames.h $(top_builddir)/src/include/utils/errcodes.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/fmgrprotos.h $(top_builddir)/src/include/utils/probes.h
174 $(top_builddir)/src/include/parser/gram.h: parser/gram.h
175 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
176 cd '$(dir $@)' && rm -f $(notdir $@) && \
177 $(LN_S) "$$prereqdir/$(notdir $<)" .
179 $(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
180 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
181 cd '$(dir $@)' && rm -f $(notdir $@) && \
182 $(LN_S) "$$prereqdir/$(notdir $<)" .
184 $(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h
185 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
186 cd '$(dir $@)' && rm -f $(notdir $@) && \
187 $(LN_S) "$$prereqdir/$(notdir $<)" .
189 $(top_builddir)/src/include/utils/errcodes.h: utils/errcodes.h
190 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
191 cd '$(dir $@)' && rm -f $(notdir $@) && \
192 $(LN_S) "$$prereqdir/$(notdir $<)" .
194 $(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
195 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
196 cd '$(dir $@)' && rm -f $(notdir $@) && \
197 $(LN_S) "$$prereqdir/$(notdir $<)" .
199 $(top_builddir)/src/include/utils/fmgrprotos.h: utils/fmgrprotos.h
200 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
201 cd '$(dir $@)' && rm -f $(notdir $@) && \
202 $(LN_S) "$$prereqdir/$(notdir $<)" .
204 $(top_builddir)/src/include/utils/probes.h: utils/probes.h
205 cd '$(dir $@)' && rm -f $(notdir $@) && \
206 $(LN_S) "../../../$(subdir)/utils/probes.h" .
209 utils/probes.o: utils/probes.d $(SUBDIROBJS)
210 $(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@
213 ##########################################################################
215 # Be sure that these files get removed by the maintainer-clean target
217 $(MAKE) -C parser gram.c gram.h scan.c
218 $(MAKE) -C bootstrap bootparse.c bootscanner.c
219 $(MAKE) -C catalog schemapg.h postgres.bki postgres.description postgres.shdescription
220 $(MAKE) -C replication repl_gram.c repl_scanner.c syncrep_gram.c syncrep_scanner.c
221 $(MAKE) -C storage/lmgr lwlocknames.h
222 $(MAKE) -C utils fmgrtab.c fmgroids.h fmgrprotos.h errcodes.h
223 $(MAKE) -C utils/misc guc-file.c
224 $(MAKE) -C utils/sort qsort_tuple.c
227 ##########################################################################
229 install: all installdirs install-bin
230 ifeq ($(PORTNAME), cygwin)
231 ifeq ($(MAKE_DLL), true)
232 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
235 ifeq ($(PORTNAME), win32)
236 ifeq ($(MAKE_DLL), true)
237 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
240 $(MAKE) -C catalog install-data
241 $(MAKE) -C tsearch install-data
242 $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample'
243 $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample'
244 $(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample'
245 $(INSTALL_DATA) $(srcdir)/access/transam/recovery.conf.sample '$(DESTDIR)$(datadir)/recovery.conf.sample'
247 install-bin: postgres $(POSTGRES_IMP) installdirs
248 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
249 ifneq ($(PORTNAME), win32)
250 @rm -f '$(DESTDIR)$(bindir)/postmaster$(X)'
251 ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
253 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
255 ifeq ($(MAKE_EXPORTS), true)
256 $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
257 $(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
263 $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
264 ifeq ($(PORTNAME), cygwin)
265 ifeq ($(MAKE_DLL), true)
266 $(MKDIR_P) '$(DESTDIR)$(libdir)'
269 ifeq ($(PORTNAME), win32)
270 ifeq ($(MAKE_DLL), true)
271 $(MKDIR_P) '$(DESTDIR)$(libdir)'
274 ifeq ($(MAKE_EXPORTS), true)
275 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
276 $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
280 ##########################################################################
283 rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster'
284 ifeq ($(MAKE_EXPORTS), true)
285 rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
286 rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
288 ifeq ($(PORTNAME), cygwin)
289 ifeq ($(MAKE_DLL), true)
290 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
293 ifeq ($(PORTNAME), win32)
294 ifeq ($(MAKE_DLL), true)
295 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
298 $(MAKE) -C catalog uninstall-data
299 $(MAKE) -C tsearch uninstall-data
300 rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \
301 '$(DESTDIR)$(datadir)/pg_ident.conf.sample' \
302 '$(DESTDIR)$(datadir)/postgresql.conf.sample' \
303 '$(DESTDIR)$(datadir)/recovery.conf.sample'
306 ##########################################################################
309 rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) \
310 $(top_builddir)/src/include/parser/gram.h \
311 $(top_builddir)/src/include/catalog/schemapg.h \
312 $(top_builddir)/src/include/storage/lwlocknames.h \
313 $(top_builddir)/src/include/utils/fmgroids.h \
314 $(top_builddir)/src/include/utils/fmgrprotos.h \
315 $(top_builddir)/src/include/utils/probes.h
316 ifeq ($(PORTNAME), cygwin)
317 rm -f postgres.dll libpostgres.a
319 ifeq ($(PORTNAME), win32)
320 rm -f postgres.dll libpostgres.a $(WIN32RES)
324 rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
326 maintainer-clean: distclean
327 rm -f bootstrap/bootparse.c \
328 bootstrap/bootscanner.c \
333 catalog/postgres.bki \
334 catalog/postgres.description \
335 catalog/postgres.shdescription \
336 replication/repl_gram.c \
337 replication/repl_scanner.c \
338 replication/syncrep_gram.c \
339 replication/syncrep_scanner.c \
340 storage/lmgr/lwlocknames.c \
341 storage/lmgr/lwlocknames.h \
346 utils/misc/guc-file.c \
347 utils/sort/qsort_tuple.c
350 ##########################################################################
352 # Support for code development.
354 # Use target "quick" to build "postgres" when you know all the subsystems
355 # are up to date. It saves the time of doing all the submakes.
358 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres