1#------------------------------------------------------------------------- 2# 3# Makefile for the postgres backend 4# 5# Portions Copyright (c) 1996-2018, 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 partitioning port postmaster \ 22 regex replication rewrite \ 23 statistics storage tcop tsearch utils $(top_builddir)/src/timezone \ 24 jit 25 26include $(srcdir)/common.mk 27 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. 34ifneq ($(PORTNAME), darwin) 35ifeq ($(enable_dtrace), yes) 36LOCALOBJS += utils/probes.o 37endif 38endif 39 40OBJS = $(SUBDIROBJS) $(LOCALOBJS) $(top_builddir)/src/port/libpgport_srv.a \ 41 $(top_builddir)/src/common/libpgcommon_srv.a 42 43# We put libpgport and libpgcommon into OBJS, so remove it from LIBS; also add 44# libldap and ICU 45LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) $(LDAP_LIBS_BE) $(ICU_LIBS) 46 47# The backend doesn't need everything that's in LIBS, however 48LIBS := $(filter-out -lz -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS)) 49 50ifeq ($(with_systemd),yes) 51LIBS += -lsystemd 52endif 53 54########################################################################## 55 56all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP) 57 58ifneq ($(PORTNAME), cygwin) 59ifneq ($(PORTNAME), win32) 60ifneq ($(PORTNAME), aix) 61 62postgres: $(OBJS) 63 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o $@ 64 65endif 66endif 67endif 68 69ifeq ($(PORTNAME), cygwin) 70 71postgres: $(OBJS) 72 $(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 $@ 73 74# libpostgres.a is actually built in the preceding rule, but we need this to 75# ensure it's newer than postgres; see notes in src/backend/parser/Makefile 76libpostgres.a: postgres 77 touch $@ 78 79endif # cygwin 80 81ifeq ($(PORTNAME), win32) 82LIBS += -lsecur32 83 84postgres: $(OBJS) $(WIN32RES) 85 $(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) 86 87# libpostgres.a is actually built in the preceding rule, but we need this to 88# ensure it's newer than postgres; see notes in src/backend/parser/Makefile 89libpostgres.a: postgres 90 touch $@ 91 92endif # win32 93 94ifeq ($(PORTNAME), aix) 95 96postgres: $(POSTGRES_IMP) 97 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$(OBJS)) -Wl,-bE:$(top_builddir)/src/backend/$(POSTGRES_IMP) $(LIBS) -Wl,-brtllib -o $@ 98 99$(POSTGRES_IMP): $(OBJS) 100 $(LD) $(LDREL) $(LDOUT) SUBSYS.o $(call expand_subsys,$^) 101ifeq ($(host_os), aix3.2.5) 102 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@ 103else 104ifneq (,$(findstring aix4.1, $(host_os))) 105 $(MKLDEXPORT) SUBSYS.o $(bindir)/postgres > $@ 106else 107 $(MKLDEXPORT) SUBSYS.o . > $@ 108endif 109endif 110 @rm -f SUBSYS.o 111 112endif # aix 113 114$(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport 115 116symlinks: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/storage/lwlocknames.h 117 118 119# The postgres.o target is needed by the rule in Makefile.global that 120# creates the exports file when MAKE_EXPORTS = true. 121postgres.o: $(OBJS) 122 $(CC) $(LDREL) $(LDFLAGS) $(LDFLAGS_EX) $(call expand_subsys,$^) $(LIBS) -o $@ 123 124 125# The following targets are specified in make commands that appear in 126# the make files in our subdirectories. Note that it's important we 127# match the dependencies shown in the subdirectory makefiles! 128# Also, in cases where a subdirectory makefile generates two files in 129# what's really one step, such as bison producing both gram.h and gram.c, 130# we must request making the one that is shown as the secondary (dependent) 131# output, else the timestamp on it might be wrong. By project convention, 132# the .h file is the dependent one for bison output, so we need only request 133# that; but in other cases, request both for safety. 134 135parser/gram.h: parser/gram.y 136 $(MAKE) -C parser gram.h 137 138storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl storage/lmgr/lwlocknames.txt 139 $(MAKE) -C storage/lmgr lwlocknames.h lwlocknames.c 140 141# run this unconditionally to avoid needing to know its dependencies here: 142submake-catalog-headers: 143 $(MAKE) -C catalog distprep generated-header-symlinks 144 145# run this unconditionally to avoid needing to know its dependencies here: 146submake-utils-headers: 147 $(MAKE) -C utils distprep generated-header-symlinks 148 149.PHONY: submake-catalog-headers submake-utils-headers 150 151# Make symlinks for these headers in the include directory. That way 152# we can cut down on the -I options. Also, a symlink is automatically 153# up to date when we update the base file. 154# 155# The point of the prereqdir incantation in some of the rules below is to 156# force the symlink to use an absolute path rather than a relative path. 157# For headers which are generated by make distprep, the actual header within 158# src/backend will be in the source tree, while the symlink in src/include 159# will be in the build tree, so a simple ../.. reference won't work. 160# For headers generated during regular builds, we prefer a relative symlink. 161 162.PHONY: generated-headers 163 164generated-headers: $(top_builddir)/src/include/parser/gram.h $(top_builddir)/src/include/storage/lwlocknames.h submake-catalog-headers submake-utils-headers 165 166$(top_builddir)/src/include/parser/gram.h: parser/gram.h 167 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \ 168 cd '$(dir $@)' && rm -f $(notdir $@) && \ 169 $(LN_S) "$$prereqdir/$(notdir $<)" . 170 171$(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h 172 prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \ 173 cd '$(dir $@)' && rm -f $(notdir $@) && \ 174 $(LN_S) "$$prereqdir/$(notdir $<)" . 175 176 177utils/probes.o: utils/probes.d $(SUBDIROBJS) 178 $(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@ 179 180 181########################################################################## 182 183# Be sure that these files get removed by the maintainer-clean target 184distprep: 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/misc guc-file.c 192 $(MAKE) -C utils/sort qsort_tuple.c 193 194 195########################################################################## 196 197install: all installdirs install-bin 198ifeq ($(PORTNAME), cygwin) 199ifeq ($(MAKE_DLL), true) 200 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a' 201endif 202endif 203ifeq ($(PORTNAME), win32) 204ifeq ($(MAKE_DLL), true) 205 $(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a' 206endif 207endif 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' 214 $(INSTALL_DATA) $(srcdir)/access/transam/recovery.conf.sample '$(DESTDIR)$(datadir)/recovery.conf.sample' 215 216ifeq ($(with_llvm), yes) 217install-bin: install-postgres-bitcode 218 219install-postgres-bitcode: $(OBJS) all 220 $(call install_llvm_module,postgres,$(call expand_subsys, $(filter-out $(top_builddir)/src/timezone/objfiles.txt, $(SUBDIROBJS)))) 221endif 222 223install-bin: postgres $(POSTGRES_IMP) installdirs 224 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)' 225ifneq ($(PORTNAME), win32) 226 @rm -f '$(DESTDIR)$(bindir)/postmaster$(X)' 227 ln -s postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)' 228else 229 $(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postmaster$(X)' 230endif 231ifeq ($(MAKE_EXPORTS), true) 232 $(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)' 233 $(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh' 234endif 235 236.PHONY: install-bin 237 238installdirs: 239 $(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)' 240ifeq ($(PORTNAME), cygwin) 241ifeq ($(MAKE_DLL), true) 242 $(MKDIR_P) '$(DESTDIR)$(libdir)' 243endif 244endif 245ifeq ($(PORTNAME), win32) 246ifeq ($(MAKE_DLL), true) 247 $(MKDIR_P) '$(DESTDIR)$(libdir)' 248endif 249endif 250ifeq ($(MAKE_EXPORTS), true) 251 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)' 252 $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)' 253endif 254 255 256########################################################################## 257 258uninstall: 259 rm -f '$(DESTDIR)$(bindir)/postgres$(X)' '$(DESTDIR)$(bindir)/postmaster' 260ifeq ($(MAKE_EXPORTS), true) 261 rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)' 262 rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh' 263endif 264ifeq ($(PORTNAME), cygwin) 265ifeq ($(MAKE_DLL), true) 266 rm -f '$(DESTDIR)$(libdir)/libpostgres.a' 267endif 268endif 269ifeq ($(PORTNAME), win32) 270ifeq ($(MAKE_DLL), true) 271 rm -f '$(DESTDIR)$(libdir)/libpostgres.a' 272endif 273endif 274 $(MAKE) -C catalog uninstall-data 275 $(MAKE) -C tsearch uninstall-data 276 $(MAKE) -C utils uninstall-data 277 rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \ 278 '$(DESTDIR)$(datadir)/pg_ident.conf.sample' \ 279 '$(DESTDIR)$(datadir)/postgresql.conf.sample' \ 280 '$(DESTDIR)$(datadir)/recovery.conf.sample' 281ifeq ($(with_llvm), yes) 282 $(call uninstall_llvm_module,postgres) 283endif 284 285 286########################################################################## 287 288clean: 289 rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) 290ifeq ($(PORTNAME), cygwin) 291 rm -f postgres.dll libpostgres.a 292endif 293ifeq ($(PORTNAME), win32) 294 rm -f postgres.dll libpostgres.a $(WIN32RES) 295endif 296 297distclean: clean 298 rm -f port/tas.s port/dynloader.c port/pg_sema.c port/pg_shmem.c 299 300maintainer-clean: distclean 301 $(MAKE) -C catalog $@ 302 $(MAKE) -C utils $@ 303 rm -f bootstrap/bootparse.c \ 304 bootstrap/bootscanner.c \ 305 parser/gram.c \ 306 parser/gram.h \ 307 parser/scan.c \ 308 replication/repl_gram.c \ 309 replication/repl_scanner.c \ 310 replication/syncrep_gram.c \ 311 replication/syncrep_scanner.c \ 312 storage/lmgr/lwlocknames.c \ 313 storage/lmgr/lwlocknames.h \ 314 utils/misc/guc-file.c \ 315 utils/sort/qsort_tuple.c 316 317 318########################################################################## 319# 320# Support for code development. 321# 322# Use target "quick" to build "postgres" when you know all the subsystems 323# are up to date. It saves the time of doing all the submakes. 324.PHONY: quick 325quick: $(OBJS) 326 $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_EX) $(export_dynamic) $(call expand_subsys,$^) $(LIBS) -o postgres 327