]> granicus.if.org Git - postgresql/blob - src/backend/Makefile
Introduce convenience macros to hide JsonbContainer header accesses better.
[postgresql] / src / backend / Makefile
1 #-------------------------------------------------------------------------
2 #
3 # Makefile for the postgres backend
4 #
5 # Portions Copyright (c) 1996-2017, PostgreSQL Global Development Group
6 # Portions Copyright (c) 1994, Regents of the University of California
7 #
8 # src/backend/Makefile
9 #
10 #-------------------------------------------------------------------------
11
12 PGFILEDESC = "PostgreSQL Server"
13 # This is a daemon process, which is why it is not labeled as an executable
14 #PGAPPICON=win32
15
16 subdir = src/backend
17 top_builddir = ../..
18 include $(top_builddir)/src/Makefile.global
19
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
23
24 include $(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, 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
35 endif
36 endif
37
38 OBJS = $(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
43 LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE)
44
45 # The backend doesn't need everything that's in LIBS, however
46 LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
47
48 ifeq ($(with_systemd),yes)
49 LIBS += -lsystemd
50 endif
51
52 ##########################################################################
53
54 all: submake-libpgport submake-schemapg postgres $(POSTGRES_IMP)
55
56 ifneq ($(PORTNAME), cygwin)
57 ifneq ($(PORTNAME), win32)
58 ifneq ($(PORTNAME), aix)
59
60 postgres: $(OBJS)
61         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@
62
63 endif
64 endif
65 endif
66
67 ifeq ($(PORTNAME), cygwin)
68
69 postgres: $(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 # 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.
77
78 libpostgres.a: postgres ;
79
80 endif # cygwin
81
82 ifeq ($(PORTNAME), win32)
83 LIBS += -lsecur32
84
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)
87
88 libpostgres.a: postgres ;
89
90 endif # win32
91
92 ifeq ($(PORTNAME), aix)
93
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 $@
96
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 > $@
101 else
102 ifneq (,$(findstring aix4.1, $(host_os)))
103         $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
104 else
105         $(MKLDEXPORT) SUBSYS.o . > $@
106 endif
107 endif
108         @rm -f SUBSYS.o
109
110 endif # 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
116 submake-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
122
123 # The postgres.o target is needed by the rule in Makefile.global that
124 # creates the exports file when MAKE_EXPORTS = true.
125 postgres.o: $(OBJS)
126         $(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@
127
128
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!
132
133 parser/gram.h: parser/gram.y
134         $(MAKE) -C parser gram.h
135
136 storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt
137         $(MAKE) -C storage/lmgr lwlocknames.h
138
139 utils/errcodes.h: utils/generate-errcodes.pl utils/errcodes.txt
140         $(MAKE) -C utils errcodes.h
141
142 # see explanation in parser/Makefile
143 utils/fmgrprotos.h: utils/fmgroids.h ;
144
145 utils/fmgroids.h: utils/Gen_fmgrtab.pl catalog/Catalog.pm $(top_srcdir)/src/include/catalog/pg_proc.h
146         $(MAKE) -C utils $(notdir $@)
147
148 utils/probes.h: utils/probes.d
149         $(MAKE) -C utils probes.h
150
151 # run this unconditionally to avoid needing to know its dependencies here:
152 catalog/schemapg.h: | submake-schemapg
153
154 submake-schemapg:
155         $(MAKE) -C catalog schemapg.h
156
157 .PHONY: submake-schemapg
158
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.
162 #
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.
169
170 .PHONY: generated-headers
171
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
173
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 $<)" .
178
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 $<)" .
183
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 $<)" .
188
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 $<)" .
193
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 $<)" .
198
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 $<)" .
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
209 utils/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
216 distprep:
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
225
226
227 ##########################################################################
228
229 install: all installdirs install-bin
230 ifeq ($(PORTNAME), cygwin)
231 ifeq ($(MAKE_DLL), true)
232         $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
233 endif
234 endif
235 ifeq ($(PORTNAME), win32)
236 ifeq ($(MAKE_DLL), true)
237         $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
238 endif
239 endif
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
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)'
252 else
253         $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
254 endif
255 ifeq ($(MAKE_EXPORTS), true)
256         $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
257         $(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
258 endif
259
260 .PHONY: install-bin
261
262 installdirs:
263         $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
264 ifeq ($(PORTNAME), cygwin)
265 ifeq ($(MAKE_DLL), true)
266         $(MKDIR_P) '$(DESTDIR)$(libdir)'
267 endif
268 endif
269 ifeq ($(PORTNAME), win32)
270 ifeq ($(MAKE_DLL), true)
271         $(MKDIR_P) '$(DESTDIR)$(libdir)'
272 endif
273 endif
274 ifeq ($(MAKE_EXPORTS), true)
275         $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
276         $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
277 endif
278
279
280 ##########################################################################
281
282 uninstall:
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'
287 endif
288 ifeq ($(PORTNAME), cygwin)
289 ifeq ($(MAKE_DLL), true)
290         rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
291 endif
292 endif
293 ifeq ($(PORTNAME), win32)
294 ifeq ($(MAKE_DLL), true)
295         rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
296 endif
297 endif
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
308 clean:
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
318 endif
319 ifeq ($(PORTNAME), win32)
320         rm -f postgres.dll libpostgres.a $(WIN32RES)
321 endif
322
323 distclean: clean
324         rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c
325
326 maintainer-clean: distclean
327         rm -f bootstrap/bootparse.c \
328               bootstrap/bootscanner.c \
329               parser/gram.c \
330               parser/gram.h \
331               parser/scan.c \
332               catalog/schemapg.h \
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 \
342               utils/fmgroids.h \
343               utils/fmgrprotos.h \
344               utils/fmgrtab.c \
345               utils/errcodes.h \
346               utils/misc/guc-file.c \
347               utils/sort/qsort_tuple.c
348
349
350 ##########################################################################
351 #
352 # Support for code development.
353 #
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.
356 .PHONY: quick
357 quick: $(OBJS)
358         $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres