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
10 #-------------------------------------------------------------------------
12 PGFILEDESC
= "PostgreSQL Server"
13 # This is a daemon process, which is why it is not labeled as an executable
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 \
26 include $(srcdir)/common.mk
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
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
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
)
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
)
66 $(CC
) $(CFLAGS
) $(call expand_subsys
,$^
) $(LDFLAGS
) $(LDFLAGS_EX
) $(export_dynamic
) $(LIBS
) -o
$@
72 ifeq ($(PORTNAME
), cygwin
)
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
84 ifeq ($(PORTNAME
), win32
)
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
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
> $@
107 ifneq (,$(findstring aix4.1
, $(host_os
)))
108 $(MKLDEXPORT
) SUBSYS.o
$(bindir)/postgres
> $@
110 $(MKLDEXPORT
) SUBSYS.o .
> $@
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.
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
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'
203 ifeq ($(PORTNAME
), win32
)
204 ifeq ($(MAKE_DLL
), true
)
205 $(INSTALL_DATA
) libpostgres.a
'$(DESTDIR)$(libdir)/libpostgres.a'
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
))))
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)'
228 $(INSTALL_PROGRAM
) postgres
$(X
) '$(DESTDIR)$(bindir)/postmaster$(X)'
230 ifeq ($(MAKE_EXPORTS
), true
)
231 $(INSTALL_DATA
) $(POSTGRES_IMP
) '$(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)'
232 $(INSTALL_PROGRAM
) $(MKLDEXPORT
) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)/mkldexport.sh'
238 $(MKDIR_P
) '$(DESTDIR)$(bindir)' '$(DESTDIR)$(datadir)'
239 ifeq ($(PORTNAME
), cygwin
)
240 ifeq ($(MAKE_DLL
), true
)
241 $(MKDIR_P
) '$(DESTDIR)$(libdir)'
244 ifeq ($(PORTNAME
), win32
)
245 ifeq ($(MAKE_DLL
), true
)
246 $(MKDIR_P
) '$(DESTDIR)$(libdir)'
249 ifeq ($(MAKE_EXPORTS
), true
)
250 $(MKDIR_P
) '$(DESTDIR)$(pkglibdir)'
251 $(MKDIR_P
) '$(DESTDIR)$(pgxsdir)/$(MKLDEXPORT_DIR)'
255 ##########################################################################
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'
263 ifeq ($(PORTNAME
), cygwin
)
264 ifeq ($(MAKE_DLL
), true
)
265 rm -f
'$(DESTDIR)$(libdir)/libpostgres.a'
268 ifeq ($(PORTNAME
), win32
)
269 ifeq ($(MAKE_DLL
), true
)
270 rm -f
'$(DESTDIR)$(libdir)/libpostgres.a'
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
)
284 ##########################################################################
287 rm -f
$(LOCALOBJS
) postgres
$(X
) $(POSTGRES_IMP
)
288 ifeq ($(PORTNAME
), cygwin
)
289 rm -f postgres.dll libpostgres.a
291 ifeq ($(PORTNAME
), win32
)
292 rm -f postgres.dll libpostgres.a
$(WIN32RES
)
296 rm -f port
/tas.s port
/pg_sema.c port
/pg_shmem.c
298 maintainer-clean
: distclean
299 $(MAKE
) -C catalog
$@
301 rm -f bootstrap
/bootparse.c \
302 bootstrap
/bootscanner.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.
325 $(CC
) $(CFLAGS
) $(call expand_subsys
,$^
) $(LDFLAGS
) $(LDFLAGS_EX
) $(export_dynamic
) $(LIBS
) -o postgres