| 1 |
#------------------------------------------------------------------------- |
| 2 |
# |
| 3 |
# Makefile for the postgres backend |
| 4 |
# |
| 5 |
# Portions Copyright (c) 1996-2025, 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 |
PGAPPICON=win32 |
| 14 |
|
| 15 |
subdir = src/backend |
| 16 |
top_builddir = ../.. |
| 17 |
include $(top_builddir)/src/Makefile.global |
| 18 |
|
| 19 |
SUBDIRS = access archive backup bootstrap catalog parser commands executor \ |
| 20 |
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 |
|
| 26 |
include $(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. |
| 34 |
ifneq ($(PORTNAME), darwin) |
| 35 |
ifeq ($(enable_dtrace), yes) |
| 36 |
LOCALOBJS += utils/probes.o |
| 37 |
endif |
| 38 |
endif |
| 39 |
|
| 40 |
OBJS = \ |
| 41 |
$(LOCALOBJS) \ |
| 42 |
$(SUBDIROBJS) \ |
| 43 |
$(top_builddir)/src/common/libpgcommon_srv.a \ |
| 44 |
$(top_builddir)/src/port/libpgport_srv.a |
| 45 |
|
| 46 |
# We put libpgport and libpgcommon into OBJS, so remove it from LIBS. |
| 47 |
LIBS := $(filter-out -lpgport -lpgcommon, $(LIBS)) |
| 48 |
# The backend conditionally needs libraries that most executables don't need. |
| 49 |
LIBS += $(LDAP_LIBS_BE) $(ICU_LIBS) $(LIBURING_LIBS) |
| 50 |
|
| 51 |
# The backend doesn't need everything that's in LIBS, however |
| 52 |
LIBS := $(filter-out -lreadline -ledit -ltermcap -lncurses -lcurses, $(LIBS)) |
| 53 |
|
| 54 |
ifeq ($(with_systemd),yes) |
| 55 |
LIBS += -lsystemd |
| 56 |
endif |
| 57 |
|
| 58 |
override LDFLAGS := $(LDFLAGS) $(LDFLAGS_EX) $(LDFLAGS_EX_BE) |
| 59 |
|
| 60 |
########################################################################## |
| 61 |
|
| 62 |
all: submake-libpgport submake-catalog-headers submake-utils-headers postgres $(POSTGRES_IMP) |
| 63 |
|
| 64 |
ifneq ($(PORTNAME), cygwin) |
| 65 |
ifneq ($(PORTNAME), win32) |
| 66 |
|
| 67 |
postgres: $(OBJS) |
| 68 |
$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o $@ |
| 69 |
|
| 70 |
endif |
| 71 |
endif |
| 72 |
|
| 73 |
ifeq ($(PORTNAME), cygwin) |
| 74 |
|
| 75 |
postgres: $(OBJS) |
| 76 |
$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) -Wl,--stack,$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@ |
| 77 |
|
| 78 |
# libpostgres.a is actually built in the preceding rule, but we need this to |
| 79 |
# ensure it's newer than postgres; see notes in src/backend/parser/Makefile |
| 80 |
libpostgres.a: postgres |
| 81 |
touch $@ |
| 82 |
|
| 83 |
endif # cygwin |
| 84 |
|
| 85 |
ifeq ($(PORTNAME), win32) |
| 86 |
LIBS += -lsecur32 |
| 87 |
|
| 88 |
postgres: $(OBJS) $(WIN32RES) |
| 89 |
$(CC) $(CFLAGS) $(call expand_subsys,$(OBJS)) $(WIN32RES) $(LDFLAGS) -Wl,--stack=$(WIN32_STACK_RLIMIT) -Wl,--export-all-symbols -Wl,--out-implib=libpostgres.a $(LIBS) -o $@$(X) |
| 90 |
|
| 91 |
# libpostgres.a is actually built in the preceding rule, but we need this to |
| 92 |
# ensure it's newer than postgres; see notes in src/backend/parser/Makefile |
| 93 |
libpostgres.a: postgres |
| 94 |
touch $@ |
| 95 |
|
| 96 |
endif # win32 |
| 97 |
|
| 98 |
$(top_builddir)/src/port/libpgport_srv.a: | submake-libpgport |
| 99 |
|
| 100 |
|
| 101 |
# The following targets are specified in make commands that appear in |
| 102 |
# the make files in our subdirectories. Note that it's important we |
| 103 |
# match the dependencies shown in the subdirectory makefiles! |
| 104 |
# Also, in cases where a subdirectory makefile generates two files in |
| 105 |
# what's really one step, such as bison producing both gram.h and gram.c, |
| 106 |
# we must request making the one that is shown as the secondary (dependent) |
| 107 |
# output, else the timestamp on it might be wrong. By project convention, |
| 108 |
# the .h file is the dependent one for bison output, so we need only request |
| 109 |
# that; but in other cases, request both for safety. |
| 110 |
|
| 111 |
parser/gram.h: parser/gram.y |
| 112 |
$(MAKE) -C parser gram.h |
| 113 |
|
| 114 |
storage/lmgr/lwlocknames.h: storage/lmgr/generate-lwlocknames.pl ../include/storage/lwlocklist.h utils/activity/wait_event_names.txt |
| 115 |
$(MAKE) -C storage/lmgr lwlocknames.h |
| 116 |
|
| 117 |
# run this unconditionally to avoid needing to know its dependencies here: |
| 118 |
submake-catalog-headers: |
| 119 |
$(MAKE) -C ../include/catalog generated-headers |
| 120 |
|
| 121 |
# run this unconditionally to avoid needing to know its dependencies here: |
| 122 |
submake-nodes-headers: |
| 123 |
$(MAKE) -C nodes generated-header-symlinks |
| 124 |
|
| 125 |
# run this unconditionally to avoid needing to know its dependencies here: |
| 126 |
submake-utils-headers: |
| 127 |
$(MAKE) -C utils generated-header-symlinks |
| 128 |
|
| 129 |
.PHONY: submake-catalog-headers submake-nodes-headers submake-utils-headers |
| 130 |
|
| 131 |
# Make symlinks for these headers in the include directory. That way |
| 132 |
# we can cut down on the -I options. Also, a symlink is automatically |
| 133 |
# up to date when we update the base file. |
| 134 |
# |
| 135 |
# The point of the prereqdir incantation in some of the rules below is to |
| 136 |
# force the symlink to use an absolute path rather than a relative path. |
| 137 |
# This is needed to support platforms without ln -s. |
| 138 |
|
| 139 |
.PHONY: generated-headers |
| 140 |
|
| 141 |
generated-headers: $(top_builddir)/src/include/storage/lwlocknames.h submake-catalog-headers submake-nodes-headers submake-utils-headers parser/gram.h |
| 142 |
|
| 143 |
$(top_builddir)/src/include/storage/lwlocknames.h: storage/lmgr/lwlocknames.h |
| 144 |
prereqdir=`cd '$(dir $<)' >/dev/null && pwd` && \ |
| 145 |
cd '$(dir $@)' && rm -f $(notdir $@) && \ |
| 146 |
$(LN_S) "$$prereqdir/$(notdir $<)" . |
| 147 |
|
| 148 |
utils/probes.o: utils/probes.d $(SUBDIROBJS) |
| 149 |
$(DTRACE) $(DTRACEFLAGS) -C -G -s $(call expand_subsys,$^) -o $@ |
| 150 |
|
| 151 |
|
| 152 |
########################################################################## |
| 153 |
|
| 154 |
# This target is only needed by nls.mk. |
| 155 |
.PHONY: generated-parser-sources |
| 156 |
generated-parser-sources: |
| 157 |
$(MAKE) -C parser gram.c gram.h scan.c |
| 158 |
$(MAKE) -C bootstrap bootparse.c bootparse.h bootscanner.c |
| 159 |
$(MAKE) -C replication repl_gram.c repl_gram.h repl_scanner.c syncrep_gram.c syncrep_gram.h syncrep_scanner.c |
| 160 |
$(MAKE) -C utils/adt jsonpath_gram.c jsonpath_gram.h jsonpath_scan.c |
| 161 |
$(MAKE) -C utils/misc guc-file.c |
| 162 |
|
| 163 |
|
| 164 |
########################################################################## |
| 165 |
|
| 166 |
install: all installdirs install-bin |
| 167 |
ifeq ($(PORTNAME), cygwin) |
| 168 |
ifeq ($(MAKE_DLL), true) |
| 169 |
$(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a' |
| 170 |
endif |
| 171 |
endif |
| 172 |
ifeq ($(PORTNAME), win32) |
| 173 |
ifeq ($(MAKE_DLL), true) |
| 174 |
$(INSTALL_DATA) libpostgres.a '$(DESTDIR)$(libdir)/libpostgres.a' |
| 175 |
endif |
| 176 |
endif |
| 177 |
$(MAKE) -C catalog install-data |
| 178 |
$(MAKE) -C tsearch install-data |
| 179 |
$(MAKE) -C utils install-data |
| 180 |
$(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample '$(DESTDIR)$(datadir)/pg_hba.conf.sample' |
| 181 |
$(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample '$(DESTDIR)$(datadir)/pg_ident.conf.sample' |
| 182 |
$(INSTALL_DATA) $(srcdir)/utils/misc/postgresql.conf.sample '$(DESTDIR)$(datadir)/postgresql.conf.sample' |
| 183 |
|
| 184 |
ifeq ($(with_llvm), yes) |
| 185 |
install-bin: install-postgres-bitcode |
| 186 |
|
| 187 |
install-postgres-bitcode: $(OBJS) all |
| 188 |
$(call install_llvm_module,postgres,$(call expand_subsys, $(filter-out $(top_builddir)/src/timezone/objfiles.txt, $(SUBDIROBJS)))) |
| 189 |
endif |
| 190 |
|
| 191 |
install-bin: postgres $(POSTGRES_IMP) installdirs |
| 192 |
$(INSTALL_PROGRAM) postgres$(X) '$(DESTDIR)$(bindir)/postgres$(X)' |
| 193 |
ifeq ($(MAKE_EXPORTS), true) |
| 194 |
$(INSTALL_DATA) $(POSTGRES_IMP) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)' |
| 195 |
$(INSTALL_PROGRAM) $(MKLDEXPORT) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh' |
| 196 |
endif |
| 197 |
|
| 198 |
.PHONY: install-bin |
| 199 |
|
| 200 |
installdirs: |
| 201 |
$(MKDIR_P) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)' |
| 202 |
ifeq ($(PORTNAME), cygwin) |
| 203 |
ifeq ($(MAKE_DLL), true) |
| 204 |
$(MKDIR_P) '$(DESTDIR)$(libdir)' |
| 205 |
endif |
| 206 |
endif |
| 207 |
ifeq ($(PORTNAME), win32) |
| 208 |
ifeq ($(MAKE_DLL), true) |
| 209 |
$(MKDIR_P) '$(DESTDIR)$(libdir)' |
| 210 |
endif |
| 211 |
endif |
| 212 |
ifeq ($(MAKE_EXPORTS), true) |
| 213 |
$(MKDIR_P) '$(DESTDIR)$(pkglibdir)' |
| 214 |
$(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)' |
| 215 |
endif |
| 216 |
|
| 217 |
|
| 218 |
########################################################################## |
| 219 |
|
| 220 |
uninstall: |
| 221 |
rm -f '$(DESTDIR)$(bindir)/postgres$(X)' |
| 222 |
ifeq ($(MAKE_EXPORTS), true) |
| 223 |
rm -f '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)' |
| 224 |
rm -f '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh' |
| 225 |
endif |
| 226 |
ifeq ($(PORTNAME), cygwin) |
| 227 |
ifeq ($(MAKE_DLL), true) |
| 228 |
rm -f '$(DESTDIR)$(libdir)/libpostgres.a' |
| 229 |
endif |
| 230 |
endif |
| 231 |
ifeq ($(PORTNAME), win32) |
| 232 |
ifeq ($(MAKE_DLL), true) |
| 233 |
rm -f '$(DESTDIR)$(libdir)/libpostgres.a' |
| 234 |
endif |
| 235 |
endif |
| 236 |
$(MAKE) -C catalog uninstall-data |
| 237 |
$(MAKE) -C tsearch uninstall-data |
| 238 |
$(MAKE) -C utils uninstall-data |
| 239 |
rm -f '$(DESTDIR)$(datadir)/pg_hba.conf.sample' \ |
| 240 |
'$(DESTDIR)$(datadir)/pg_ident.conf.sample' \ |
| 241 |
'$(DESTDIR)$(datadir)/postgresql.conf.sample' |
| 242 |
ifeq ($(with_llvm), yes) |
| 243 |
$(call uninstall_llvm_module,postgres) |
| 244 |
endif |
| 245 |
|
| 246 |
|
| 247 |
########################################################################## |
| 248 |
|
| 249 |
clean: |
| 250 |
rm -f $(LOCALOBJS) postgres$(X) $(POSTGRES_IMP) |
| 251 |
ifeq ($(PORTNAME), cygwin) |
| 252 |
rm -f postgres.dll libpostgres.a |
| 253 |
endif |
| 254 |
ifeq ($(PORTNAME), win32) |
| 255 |
rm -f postgres.dll libpostgres.a $(WIN32RES) |
| 256 |
endif |
| 257 |
|
| 258 |
distclean: clean |
| 259 |
# generated by configure |
| 260 |
rm -f port/tas.s port/pg_sema.c port/pg_shmem.c |
| 261 |
|
| 262 |
|
| 263 |
########################################################################## |
| 264 |
# |
| 265 |
# Support for code development. |
| 266 |
# |
| 267 |
# Use target "quick" to build "postgres" when you know all the subsystems |
| 268 |
# are up to date. It saves the time of doing all the submakes. |
| 269 |
.PHONY: quick |
| 270 |
quick: $(OBJS) |
| 271 |
$(CC) $(CFLAGS) $(call expand_subsys,$^) $(LDFLAGS) $(LIBS) -o postgres |