postgres_fdw: Refactor transaction rollback code to avoid code duplication.
[pgsql.git] / src / backend / Makefile
blob0da848b1fd3dafeebf4c9fe0d4ff3e5e2c8c5e22
1 #-------------------------------------------------------------------------
3 # Makefile for the postgres backend
5 # Portions Copyright (c) 1996-2021, PostgreSQL Global Development Group
6 # Portions Copyright (c) 1994, Regents of the University of California
8 # src/backend/Makefile
10 #-------------------------------------------------------------------------
12 PGFILEDESC = "PostgreSQL Server"
13 # This is a daemon process, which is why it is not labeled as an executable
14 #PGAPPICON=win32
16 subdir = src/backend
17 top_builddir = ../..
18 include $(top_builddir)/src/Makefile.global
20 SUBDIRS = access bootstrap catalog parser commands executor foreign lib libpq \
21 main nodes optimizer partitioning port postmaster \
22 regex replication rewrite \
23 statistics storage tcop tsearch utils $(top_builddir)/src/timezone \
24 jit
26 include $(srcdir)/common.mk
28 # As of 1/2010:
29 # The probes.o file is necessary for dtrace support on Solaris, and on recent
30 # versions of systemtap. (Older systemtap releases just produce an empty
31 # file, but that's okay.) However, macOS's dtrace doesn't use it and doesn't
32 # even recognize the -G option. So, build probes.o except on macOS.
33 # This might need adjustment as other platforms add dtrace support.
34 ifneq ($(PORTNAME), darwin)
35 ifeq ($(enable_dtrace), yes)
36 LOCALOBJS += utils/probes.o
37 endif
38 endif
40 OBJS = \
41 $(LOCALOBJS) \
42 $(SUBDIROBJS) \
43 $(top_builddir)/src/common/libpgcommon_srv.a \
44 $(top_builddir)/src/port/libpgport_srv.a
46 # We put libpgport and libpgcommon into OBJS, so remove it from LIBS; also add
47 # libldap and ICU
48 LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE) $(ICU_LIBS)
50 # The backend doesn't need everything that's in LIBS, however
51 LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS))
53 ifeq ($(with_systemd),yes)
54 LIBS += -lsystemd
55 endif
57 ##########################################################################
59 all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP)
61 ifneq ($(PORTNAME), cygwin)
62 ifneq ($(PORTNAME), win32)
63 ifneq ($(PORTNAME), aix)
65 postgres: $(OBJS)
66 $(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) -o $@
68 endif
69 endif
70 endif
72 ifeq ($(PORTNAME), cygwin)
74 postgres: $(OBJS)
75 $(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) -Wl,--stack,$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@
77 # libpostgres.a is actually built in the preceding rule, but we need this to
78 # ensure it's newer than postgres; see notes in src/backend/parser/Makefile
79 libpostgres.a: postgres
80 touch $@
82 endif # cygwin
84 ifeq ($(PORTNAME), win32)
85 LIBS += -lsecur32
87 postgres: $(OBJS) $(WIN32RES)
88 $(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LDFLAGS) $(LDFLAGS_EX) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@$(X)
90 # libpostgres.a is actually built in the preceding rule, but we need this to
91 # ensure it's newer than postgres; see notes in src/backend/parser/Makefile
92 libpostgres.a: postgres
93 touch $@
95 endif # win32
97 ifeq ($(PORTNAME), aix)
99 postgres: $(POSTGRES_IMP)
100 $(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(LDFLAGS) $(LDFLAGS_EX) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@
102 $(POSTGRES_IMP): $(OBJS)
103 $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^)
104 ifeq ($(host_os), aix3.2.5)
105 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
106 else
107 ifneq (,$(findstring aix4.1, $(host_os)))
108 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@
109 else
110 $(MKLDEXPORT) SUBSYS.o . > $@
111 endif
112 endif
113 @rm -f SUBSYS.o
115 endif # aix
117 $(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport
120 # The postgres.o target is needed by the rule in Makefile.global that
121 # creates the exports file when MAKE_EXPORTS = true.
122 postgres.o: $(OBJS)
123 $(CC) $(LDREL) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@
126 # The following targets are specified in make commands that appear in
127 # the make files in our subdirectories. Note that it's important we
128 # match the dependencies shown in the subdirectory makefiles!
129 # Also, in cases where a subdirectory makefile generates two files in
130 # what's really one step, such as bison producing both gram.h and gram.c,
131 # we must request making the one that is shown as the secondary (dependent)
132 # output, else the timestamp on it might be wrong. By project convention,
133 # the .h file is the dependent one for bison output, so we need only request
134 # that; but in other cases, request both for safety.
136 parser/gram.h: parser/gram.y
137 $(MAKE) -C parser gram.h
139 storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt
140 $(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
142 # run this unconditionally to avoid needing to know its dependencies here:
143 submake-catalog-headers:
144 $(MAKE) -C catalog distprep generated-header-symlinks
146 # run this unconditionally to avoid needing to know its dependencies here:
147 submake-utils-headers:
148 $(MAKE) -C utils distprep generated-header-symlinks
150 .PHONY: submake-catalog-headers submake-utils-headers
152 # Make symlinks for these headers in the include directory. That way
153 # we can cut down on the -I options. Also, a symlink is automatically
154 # up to date when we update the base file.
156 # The point of the prereqdir incantation in some of the rules below is to
157 # force the symlink to use an absolute path rather than a relative path.
158 # For headers which are generated by make distprep, the actual header within
159 # src/backend will be in the source tree, while the symlink in src/include
160 # will be in the build tree, so a simple ../.. reference won't work.
161 # For headers generated during regular builds, we prefer a relative symlink.
163 .PHONY: generated-headers
165 generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/storage/lwlocknames.h submake-catalog-headers submake-utils-headers
167 $(top_builddir)/src/include/parser/gram.h: parser/gram.h
168 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
169 cd '$(dir $@)' && rm -f $(notdir $@) && \
170 $(LN_S) "$$prereqdir/$(notdir $<)" .
172 $(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h
173 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \
174 cd '$(dir $@)' && rm -f $(notdir $@) && \
175 $(LN_S) "$$prereqdir/$(notdir $<)" .
177 utils/probes.o: utils/probes.d $(SUBDIROBJS)
178 $(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@
181 ##########################################################################
183 # Be sure that these files get removed by the maintainer-clean target
184 distprep:
185 $(MAKE) -C parser gram.c gram.h scan.c
186 $(MAKE) -C bootstrap bootparse.c bootscanner.c
187 $(MAKE) -C catalog distprep
188 $(MAKE) -C replication repl_gram.c repl_scanner.c syncrep_gram.c syncrep_scanner.c
189 $(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c
190 $(MAKE) -C utils distprep
191 $(MAKE) -C utils/adt jsonpath_gram.c jsonpath_scan.c
192 $(MAKE) -C utils/misc guc-file.c
195 ##########################################################################
197 install: all installdirs install-bin
198 ifeq ($(PORTNAME), cygwin)
199 ifeq ($(MAKE_DLL), true)
200 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
201 endif
202 endif
203 ifeq ($(PORTNAME), win32)
204 ifeq ($(MAKE_DLL), true)
205 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a'
206 endif
207 endif
208 $(MAKE) -C catalog install-data
209 $(MAKE) -C tsearch install-data
210 $(MAKE) -C utils install-data
211 $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample'
212 $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample'
213 $(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample'
215 ifeq ($(with_llvm), yes)
216 install-bin: install-postgres-bitcode
218 install-postgres-bitcode: $(OBJS) all
219 $(call install_llvm_module,postgres,$(call expand_subsys, $(filter-out $(top_builddir)/src/timezone/objfiles.txt, $(SUBDIROBJS))))
220 endif
222 install-bin: postgres $(POSTGRES_IMP) installdirs
223 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)'
224 ifneq ($(PORTNAME), win32)
225 @rm -f '$(DESTDIR)$(bindir)/postmaster$(X)'
226 ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
227 else
228 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)'
229 endif
230 ifeq ($(MAKE_EXPORTS), true)
231 $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
232 $(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
233 endif
235 .PHONY: install-bin
237 installdirs:
238 $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
239 ifeq ($(PORTNAME), cygwin)
240 ifeq ($(MAKE_DLL), true)
241 $(MKDIR_P) '$(DESTDIR)$(libdir)'
242 endif
243 endif
244 ifeq ($(PORTNAME), win32)
245 ifeq ($(MAKE_DLL), true)
246 $(MKDIR_P) '$(DESTDIR)$(libdir)'
247 endif
248 endif
249 ifeq ($(MAKE_EXPORTS), true)
250 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
251 $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
252 endif
255 ##########################################################################
257 uninstall:
258 rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster'
259 ifeq ($(MAKE_EXPORTS), true)
260 rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
261 rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
262 endif
263 ifeq ($(PORTNAME), cygwin)
264 ifeq ($(MAKE_DLL), true)
265 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
266 endif
267 endif
268 ifeq ($(PORTNAME), win32)
269 ifeq ($(MAKE_DLL), true)
270 rm -f '$(DESTDIR)$(libdir)/libpostgres.a'
271 endif
272 endif
273 $(MAKE) -C catalog uninstall-data
274 $(MAKE) -C tsearch uninstall-data
275 $(MAKE) -C utils uninstall-data
276 rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \
277 '$(DESTDIR)$(datadir)/pg_ident.conf.sample' \
278 '$(DESTDIR)$(datadir)/postgresql.conf.sample'
279 ifeq ($(with_llvm), yes)
280 $(call uninstall_llvm_module,postgres)
281 endif
284 ##########################################################################
286 clean:
287 rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP)
288 ifeq ($(PORTNAME), cygwin)
289 rm -f postgres.dll libpostgres.a
290 endif
291 ifeq ($(PORTNAME), win32)
292 rm -f postgres.dll libpostgres.a $(WIN32RES)
293 endif
295 distclean: clean
296 rm -f port/tas.s port/pg_sema.c port/pg_shmem.c
298 maintainer-clean: distclean
299 $(MAKE) -C catalog $@
300 $(MAKE) -C utils $@
301 rm -f bootstrap/bootparse.c \
302 bootstrap/bootscanner.c \
303 parser/gram.c \
304 parser/gram.h \
305 parser/scan.c \
306 replication/repl_gram.c \
307 replication/repl_scanner.c \
308 replication/syncrep_gram.c \
309 replication/syncrep_scanner.c \
310 storage/lmgr/lwlocknames.c \
311 storage/lmgr/lwlocknames.h \
312 utils/adt/jsonpath_gram.c \
313 utils/adt/jsonpath_scan.c \
314 utils/misc/guc-file.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.
323 .PHONY: quick
324 quick: $(OBJS)
325 $(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(LIBS) -o postgres