1#-------------------------------------------------------------------------
2#
3# Makefile for the postgres backend
4#
5# Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
6# Portions Copyright (c) 1994, Regents of the University of California
7#
8# src/backend/Makefile
9#
10#-------------------------------------------------------------------------
11
12PGFILEDESC = "PostgreSQL Server"
13# This is a daemon process, which is why it is not labeled as an executable
14#PGAPPICON=win32
15
16subdir = src/backend
17top_builddir = ../..
18include $(top_builddir)/src/Makefile.global
19
20SUBDIRS = 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
23
24include $(srcdir)/common.mk
25
26# As of 1/2010:
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.
32ifneq ($(PORTNAME), darwin)
33ifeq ($(enable_dtrace), yes)
34LOCALOBJS += utils/probes.o
35endif
36endif
37
38OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a \
39       $(top_builddir)/src/common/libpgcommon_srv.a
40
41# We put libpgport and libpgcommon into OBJS, so remove it from LIBS; also add
42# libldap
43LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE)
44
45# The backend doesn't need everything that's in LIBS, however
46LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
47
48ifeq ($(with_systemd),yes)
49LIBS += -lsystemd
50endif
51
52##########################################################################
53
54all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
55
56ifneq ($(PORTNAME), cygwin)
57ifneq ($(PORTNAME), win32)
58ifneq ($(PORTNAME), aix)
59
60postgres: $(OBJS)
61	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
62
63endif
64endif
65endif
66
67ifeq ($(PORTNAME), cygwin)
68
69postgres: $(OBJS)
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 $@
71
72# libpostgres.a is actually built in the preceding rule, but we need this to
73# ensure it's newer than postgres; see notes in src/backend/parser/Makefile
74libpostgres.a: postgres
75	touch $@
76
77endif # cygwin
78
79ifeq ($(PORTNAME), win32)
80LIBS += -lsecur32
81
82postgres: $(OBJS) $(WIN32RES)
83	$(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
85# libpostgres.a is actually built in the preceding rule, but we need this to
86# ensure it's newer than postgres; see notes in src/backend/parser/Makefile
87libpostgres.a: postgres
88	touch $@
89
90endif # win32
91
92ifeq ($(PORTNAME), aix)
93
94postgres: $(POSTGRES_IMP)
95	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
96
97$(POSTGRES_IMP): $(OBJS)
98	$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
99ifeq ($(host_os), aix3.2.5)
100	$(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
101else
102ifneq (,$(findstring aix4.1, $(host_os)))
103	$(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
104else
105	$(MKLDEXPORT) SUBSYS.o . > $@
106endif
107endif
108	@rm -f SUBSYS.o
109
110endif # aix
111
112# Update the commonly used headers before building the subdirectories
113$(SUBDIRS:%=%-recursive): | generated-headers
114
115# src/port needs a convenient way to force just errcodes.h to get built
116submake-errcodes: $(top_builddir)/src/include/utils/errcodes.h
117
118.PHONY: submake-errcodes
119
120$(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
121
122symlinks: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/utils/fmgroids.h $(top_builddir)/src/include/utils/probes.h $(top_builddir)/src/include/storage/lwlocknames.h
123
124
125# The postgres.o target is needed by the rule in Makefile.global that
126# creates the exports file when MAKE_EXPORTS = true.
127postgres.o: $(OBJS)
128	$(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@
129
130
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!
134# Also, in cases where a subdirectory makefile generates two files in
135# what's really one step, such as bison producing both gram.h and gram.c,
136# we must request making the one that is shown as the secondary (dependent)
137# output, else the timestamp on it might be wrong.  By project convention,
138# the .h file is the dependent one for bison output, so we need only request
139# that; but in other cases, request both for safety.
140
141parser/gram.h: parser/gram.y
142	$(MAKE) -C parser gram.h
143
144storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt
145	$(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
146
147utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
148	$(MAKE) -C utils errcodes.h
149
150utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
151	$(MAKE) -C utils fmgroids.h
152
153utils/probes.h: utils/probes.d
154	$(MAKE) -C utils probes.h
155
156# run this unconditionally to avoid needing to know its dependencies here:
157catalog/schemapg.h: | submake-schemapg
158
159submake-schemapg:
160	$(MAKE) -C catalog schemapg.h
161
162.PHONY: submake-schemapg
163
164# Make symlinks for these headers in the include directory. That way
165# we can cut down on the -I options. Also, a symlink is automatically
166# up to date when we update the base file.
167#
168# The point of the prereqdir incantation in some of the rules below is to
169# force the symlink to use an absolute path rather than a relative path.
170# For headers which are generated by make distprep, the actual header within
171# src/backend will be in the source tree, while the symlink in src/include
172# will be in the build tree, so a simple ../.. reference won't work.
173# For headers generated during regular builds, we prefer a relative symlink.
174
175.PHONY: generated-headers
176
177generated-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/probes.h
178
179$(top_builddir)/src/include/parser/gram.h: parser/gram.h
180	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
181	  cd '$(dir $@)' && rm -f $(notdir $@) && \
182	  $(LN_S) "$$prereqdir/$(notdir $<)" .
183
184$(top_builddir)/src/include/catalog/schemapg.h: catalog/schemapg.h
185	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
186	  cd '$(dir $@)' && rm -f $(notdir $@) && \
187	  $(LN_S) "$$prereqdir/$(notdir $<)" .
188
189$(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h
190	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
191	  cd '$(dir $@)' && rm -f $(notdir $@) && \
192	  $(LN_S) "$$prereqdir/$(notdir $<)" .
193
194$(top_builddir)/src/include/utils/errcodes.h: utils/errcodes.h
195	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
196	  cd '$(dir $@)' && rm -f $(notdir $@) && \
197	  $(LN_S) "$$prereqdir/$(notdir $<)" .
198
199$(top_builddir)/src/include/utils/fmgroids.h: utils/fmgroids.h
200	prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
201	  cd '$(dir $@)' && rm -f $(notdir $@) && \
202	  $(LN_S) "$$prereqdir/$(notdir $<)" .
203
204$(top_builddir)/src/include/utils/probes.h: utils/probes.h
205	cd '$(dir $@)' && rm -f $(notdir $@) && \
206	    $(LN_S) "../../../$(subdir)/utils/probes.h" .
207
208
209utils/probes.o: utils/probes.d $(SUBDIROBJS)
210	$(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@
211
212
213##########################################################################
214
215# Be sure that these files get removed by the maintainer-clean target
216distprep:
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 lwlocknames.c
222	$(MAKE) -C utils	fmgrtab.c fmgroids.h errcodes.h
223	$(MAKE) -C utils/misc	guc-file.c
224	$(MAKE) -C utils/sort	qsort_tuple.c
225
226
227##########################################################################
228
229install: all installdirs install-bin
230ifeq ($(PORTNAME), cygwin)
231ifeq ($(MAKE_DLL), true)
232	$(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
233endif
234endif
235ifeq ($(PORTNAME), win32)
236ifeq ($(MAKE_DLL), true)
237	$(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
238endif
239endif
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'
246
247install-bin: postgres $(POSTGRES_IMP) installdirs
248	$(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
249ifneq ($(PORTNAME), win32)
250	@rm -f '$(DESTDIR)$(bindir)/postmaster$(X)'
251	ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
252else
253	$(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
254endif
255ifeq ($(MAKE_EXPORTS), true)
256	$(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
257	$(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
258endif
259
260.PHONY: install-bin
261
262installdirs:
263	$(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
264ifeq ($(PORTNAME), cygwin)
265ifeq ($(MAKE_DLL), true)
266	$(MKDIR_P) '$(DESTDIR)$(libdir)'
267endif
268endif
269ifeq ($(PORTNAME), win32)
270ifeq ($(MAKE_DLL), true)
271	$(MKDIR_P) '$(DESTDIR)$(libdir)'
272endif
273endif
274ifeq ($(MAKE_EXPORTS), true)
275	$(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
276	$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
277endif
278
279
280##########################################################################
281
282uninstall:
283	rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster'
284ifeq ($(MAKE_EXPORTS), true)
285	rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
286	rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
287endif
288ifeq ($(PORTNAME), cygwin)
289ifeq ($(MAKE_DLL), true)
290	rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
291endif
292endif
293ifeq ($(PORTNAME), win32)
294ifeq ($(MAKE_DLL), true)
295	rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
296endif
297endif
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'
304
305
306##########################################################################
307
308clean:
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/probes.h
315ifeq ($(PORTNAME), cygwin)
316	rm -f postgres.dll libpostgres.a
317endif
318ifeq ($(PORTNAME), win32)
319	rm -f postgres.dll libpostgres.a $(WIN32RES)
320endif
321
322distclean: clean
323	rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
324
325maintainer-clean: distclean
326	rm -f bootstrap/bootparse.c \
327	      bootstrap/bootscanner.c \
328	      parser/gram.c \
329	      parser/gram.h \
330	      parser/scan.c \
331	      catalog/schemapg.h \
332	      catalog/postgres.bki \
333	      catalog/postgres.description \
334	      catalog/postgres.shdescription \
335	      replication/repl_gram.c \
336	      replication/repl_scanner.c \
337	      replication/syncrep_gram.c \
338	      replication/syncrep_scanner.c \
339	      storage/lmgr/lwlocknames.c \
340	      storage/lmgr/lwlocknames.h \
341	      utils/fmgroids.h \
342	      utils/fmgrtab.c \
343	      utils/errcodes.h \
344	      utils/misc/guc-file.c \
345	      utils/sort/qsort_tuple.c
346
347
348##########################################################################
349#
350# Support for code development.
351#
352# Use target "quick" to build "postgres" when you know all the subsystems
353# are up to date.  It saves the time of doing all the submakes.
354.PHONY: quick
355quick: $(OBJS)
356	$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres
357