doc PG 17 relnotes: add FETCH_COUNT item
[pgsql.git] / src / Makefile.global.in
bloba00c909681eb163d31986123790add1b4181606e
1 # -*-makefile-*-
2 # src/Makefile.global.in
3 # @configure_input@
5 #------------------------------------------------------------------------------
6 # All PostgreSQL makefiles include this file and use the variables it sets,
7 # which in turn are put here by the configure script. There is no need for
8 # users to edit this file -- if it turns out to be necessary then that's a
9 # bug.
11 # A makefile that includes this file needs to set the variable `subdir' to
12 # the relative path from the top to itself and `top_builddir' to the relative
13 # path from itself to the top before including this file. (The "top" is the
14 # parent directory of the directory this file is in.)
15 #------------------------------------------------------------------------------
18 ##########################################################################
20 # Meta configuration
22 standard_targets = all install installdirs uninstall clean distclean coverage check checkprep installcheck init-po update-po
23 # these targets should recurse even into subdirectories not being built:
24 standard_always_targets = clean distclean
26 .PHONY: $(standard_targets) maintainer-clean install-strip html man installcheck-parallel update-unicode
28 # make `all' the default target
29 all:
31 # Delete target files if the command fails after it has
32 # started to update the file.
33 .DELETE_ON_ERROR:
35 # Never delete any intermediate files automatically.
36 .SECONDARY:
38 maintainer-clean: distclean
40 # PostgreSQL version number
41 VERSION = @PACKAGE_VERSION@
42 MAJORVERSION = @PG_MAJORVERSION@
43 VERSION_NUM = @PG_VERSION_NUM@
45 PACKAGE_URL = @PACKAGE_URL@
47 # Set top_srcdir, srcdir, and VPATH.
48 ifdef PGXS
49 top_srcdir = $(top_builddir)
51 # If VPATH is set or Makefile is not in current directory we are building
52 # the extension with VPATH so we set the variable here.
53 ifdef VPATH
54 srcdir = $(VPATH)
55 else
56 ifeq ($(CURDIR),$(dir $(firstword $(MAKEFILE_LIST))))
57 srcdir = .
58 VPATH =
59 else
60 srcdir = $(dir $(firstword $(MAKEFILE_LIST)))
61 VPATH = $(srcdir)
62 endif
63 endif
64 else # not PGXS
65 vpath_build = @vpath_build@
66 abs_top_builddir = @abs_top_builddir@
67 abs_top_srcdir = @abs_top_srcdir@
69 ifneq ($(vpath_build),yes)
70 top_srcdir = $(top_builddir)
71 srcdir = .
72 else # vpath_build = yes
73 top_srcdir = $(abs_top_srcdir)
74 srcdir = $(top_srcdir)/$(subdir)
75 VPATH = $(srcdir)
76 endif
77 endif # not PGXS
80 ##########################################################################
82 # Installation directories
84 # These are set by the equivalent --xxxdir configure options.  We
85 # append "postgresql" to some of them, if the string does not already
86 # contain "pgsql" or "postgres", in order to avoid directory clutter.
88 # In a PGXS build, we cannot use the values inserted into Makefile.global
89 # by configure, since the installation tree may have been relocated.
90 # Instead get the path values from pg_config.
92 ifndef PGXS
94 # Note that prefix, exec_prefix, and datarootdir aren't defined in a PGXS build;
95 # makefiles may only use the derived variables such as bindir.
97 prefix := @prefix@
98 exec_prefix := @exec_prefix@
99 datarootdir := @datarootdir@
101 bindir := @bindir@
103 datadir := @datadir@
104 ifeq "$(findstring pgsql, $(datadir))" ""
105 ifeq "$(findstring postgres, $(datadir))" ""
106 override datadir := $(datadir)/postgresql
107 endif
108 endif
110 sysconfdir := @sysconfdir@
111 ifeq "$(findstring pgsql, $(sysconfdir))" ""
112 ifeq "$(findstring postgres, $(sysconfdir))" ""
113 override sysconfdir := $(sysconfdir)/postgresql
114 endif
115 endif
117 libdir := @libdir@
119 pkglibdir = $(libdir)
120 ifeq "$(findstring pgsql, $(pkglibdir))" ""
121 ifeq "$(findstring postgres, $(pkglibdir))" ""
122 override pkglibdir := $(pkglibdir)/postgresql
123 endif
124 endif
126 includedir := @includedir@
128 pkgincludedir = $(includedir)
129 ifeq "$(findstring pgsql, $(pkgincludedir))" ""
130 ifeq "$(findstring postgres, $(pkgincludedir))" ""
131 override pkgincludedir := $(pkgincludedir)/postgresql
132 endif
133 endif
135 mandir := @mandir@
137 docdir := @docdir@
138 ifeq "$(findstring pgsql, $(docdir))" ""
139 ifeq "$(findstring postgres, $(docdir))" ""
140 override docdir := $(docdir)/postgresql
141 endif
142 endif
144 htmldir := @htmldir@
146 localedir := @localedir@
148 else # PGXS case
150 # Extension makefiles should set PG_CONFIG, but older ones might not
151 ifndef PG_CONFIG
152 PG_CONFIG = pg_config
153 endif
155 bindir := $(shell $(PG_CONFIG) --bindir)
156 datadir := $(shell $(PG_CONFIG) --sharedir)
157 sysconfdir := $(shell $(PG_CONFIG) --sysconfdir)
158 libdir := $(shell $(PG_CONFIG) --libdir)
159 pkglibdir := $(shell $(PG_CONFIG) --pkglibdir)
160 includedir := $(shell $(PG_CONFIG) --includedir)
161 pkgincludedir := $(shell $(PG_CONFIG) --pkgincludedir)
162 mandir := $(shell $(PG_CONFIG) --mandir)
163 docdir := $(shell $(PG_CONFIG) --docdir)
164 localedir := $(shell $(PG_CONFIG) --localedir)
166 endif # PGXS
168 # These derived path variables aren't separately configurable.
170 includedir_server = $(pkgincludedir)/server
171 includedir_internal = $(pkgincludedir)/internal
172 pgxsdir = $(pkglibdir)/pgxs
173 bitcodedir = $(pkglibdir)/bitcode
176 ##########################################################################
178 # Features
180 # Records the choice of the various --enable-xxx and --with-xxx options.
182 with_icu        = @with_icu@
183 with_perl       = @with_perl@
184 with_python     = @with_python@
185 with_tcl        = @with_tcl@
186 with_ssl        = @with_ssl@
187 with_readline   = @with_readline@
188 with_selinux    = @with_selinux@
189 with_systemd    = @with_systemd@
190 with_gssapi     = @with_gssapi@
191 with_krb_srvnam = @with_krb_srvnam@
192 with_ldap       = @with_ldap@
193 with_libxml     = @with_libxml@
194 with_libxslt    = @with_libxslt@
195 with_llvm       = @with_llvm@
196 with_system_tzdata = @with_system_tzdata@
197 with_uuid       = @with_uuid@
198 with_zlib       = @with_zlib@
199 enable_rpath    = @enable_rpath@
200 enable_nls      = @enable_nls@
201 enable_debug    = @enable_debug@
202 enable_dtrace   = @enable_dtrace@
203 enable_coverage = @enable_coverage@
204 enable_injection_points = @enable_injection_points@
205 enable_tap_tests        = @enable_tap_tests@
207 python_includespec      = @python_includespec@
208 python_libdir           = @python_libdir@
209 python_libspec          = @python_libspec@
210 python_additional_libs  = @python_additional_libs@
211 python_majorversion     = @python_majorversion@
212 python_version          = @python_version@
214 krb_srvtab = @krb_srvtab@
216 ICU_CFLAGS              = @ICU_CFLAGS@
217 ICU_LIBS                = @ICU_LIBS@
219 TCLSH                   = @TCLSH@
220 TCL_LIBS                = @TCL_LIBS@
221 TCL_LIB_SPEC            = @TCL_LIB_SPEC@
222 TCL_INCLUDE_SPEC        = @TCL_INCLUDE_SPEC@
223 TCL_SHARED_BUILD        = @TCL_SHARED_BUILD@
225 PTHREAD_CFLAGS          = @PTHREAD_CFLAGS@
226 PTHREAD_LIBS            = @PTHREAD_LIBS@
228 LLVM_BINPATH = @LLVM_BINPATH@
229 CLANG = @CLANG@
230 BITCODE_CFLAGS = @BITCODE_CFLAGS@
231 BITCODE_CXXFLAGS = @BITCODE_CXXFLAGS@
233 ##########################################################################
235 # Programs and flags
237 # Compilers
239 CPP = @CPP@
240 CPPFLAGS = @CPPFLAGS@
241 PG_SYSROOT = @PG_SYSROOT@
243 override CPPFLAGS := $(ICU_CFLAGS) $(CPPFLAGS)
245 ifdef PGXS
246 override CPPFLAGS := -I$(includedir_server) -I$(includedir_internal) $(CPPFLAGS)
247 else # not PGXS
248 override CPPFLAGS := -I$(top_srcdir)/src/include $(CPPFLAGS)
249 ifdef VPATH
250 override CPPFLAGS := -I$(top_builddir)/src/include $(CPPFLAGS)
251 endif
252 endif # not PGXS
254 CC = @CC@
255 GCC = @GCC@
256 SUN_STUDIO_CC = @SUN_STUDIO_CC@
257 CXX = @CXX@
258 CFLAGS = @CFLAGS@
259 CFLAGS_SL = @CFLAGS_SL@
260 # *_MODULE are for flags applied to extension libraries
261 CFLAGS_SL_MODULE = @CFLAGS_SL_MODULE@
262 CXXFLAGS_SL_MODULE = @CXXFLAGS_SL_MODULE@
263 CFLAGS_UNROLL_LOOPS = @CFLAGS_UNROLL_LOOPS@
264 CFLAGS_VECTORIZE = @CFLAGS_VECTORIZE@
265 CFLAGS_POPCNT = @CFLAGS_POPCNT@
266 CFLAGS_CRC = @CFLAGS_CRC@
267 CFLAGS_XSAVE = @CFLAGS_XSAVE@
268 PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@
269 CXXFLAGS = @CXXFLAGS@
271 LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
272 LLVM_CFLAGS = @LLVM_CFLAGS@
273 LLVM_CXXFLAGS = @LLVM_CXXFLAGS@
275 # Kind-of compilers
277 BISON = @BISON@
278 BISONFLAGS = @BISONFLAGS@ $(YFLAGS)
279 FLEX = @FLEX@
280 FLEXFLAGS = @FLEXFLAGS@ $(LFLAGS)
281 DTRACE = @DTRACE@
282 DTRACEFLAGS = @DTRACEFLAGS@
283 ZIC = @ZIC@
285 # Linking
287 AR = @AR@
288 AROPT = crs
289 LIBS = @LIBS@
290 LDAP_LIBS_FE = @LDAP_LIBS_FE@
291 LDAP_LIBS_BE = @LDAP_LIBS_BE@
292 UUID_LIBS = @UUID_LIBS@
293 LLVM_LIBS=@LLVM_LIBS@
295 # It's critical that within LDFLAGS, all -L switches pointing to build-tree
296 # directories come before any -L switches pointing to external directories.
297 # Otherwise it's possible for, e.g., a platform-provided copy of libpq.so
298 # to get linked in place of the one we've built.  Therefore we adopt the
299 # convention that the first component of LDFLAGS is an extra variable
300 # LDFLAGS_INTERNAL, and -L and -l switches for PG's own libraries must be
301 # put into LDFLAGS_INTERNAL, so they will appear ahead of those for external
302 # libraries.
304 # We need LDFLAGS and LDFLAGS_INTERNAL to be "recursively expanded" variables,
305 # else adjustments to, e.g., rpathdir don't work right.  So we must NOT do
306 # "LDFLAGS := something" anywhere, ditto for LDFLAGS_INTERNAL.
307 # These initial assignments must be "=" type, and elsewhere we must only do
308 # "LDFLAGS += something" or "LDFLAGS_INTERNAL += something".
309 ifdef PGXS
310   LDFLAGS_INTERNAL = -L$(libdir)
311 else
312   LDFLAGS_INTERNAL = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
313 endif
314 LDFLAGS = $(LDFLAGS_INTERNAL) @LDFLAGS@
316 LDFLAGS_EX = @LDFLAGS_EX@
317 LDFLAGS_EX_BE = @LDFLAGS_EX_BE@
318 # LDFLAGS_SL might have already been assigned by calling makefile
319 LDFLAGS_SL += @LDFLAGS_SL@
320 WINDRES = @WINDRES@
321 X = @EXEEXT@
323 # Perl
325 # quoted to protect pathname with spaces
326 PERL            = '@PERL@'
327 perl_archlibexp         = @perl_archlibexp@
328 perl_privlibexp         = @perl_privlibexp@
329 perl_includespec        = @perl_includespec@
330 perl_embed_ccflags      = @perl_embed_ccflags@
331 perl_embed_ldflags      = @perl_embed_ldflags@
333 # Miscellaneous
335 AWK     = @AWK@
336 LN_S    = @LN_S@
337 MSGFMT  = @MSGFMT@
338 MSGFMT_FLAGS = @MSGFMT_FLAGS@
339 MSGMERGE = @MSGMERGE@
340 OPENSSL = @OPENSSL@
341 PYTHON  = @PYTHON@
342 TAR     = @TAR@
343 XGETTEXT = @XGETTEXT@
345 GZIP    = gzip
346 BZIP2   = bzip2
347 LZ4     = @LZ4@
348 ZSTD    = @ZSTD@
350 DOWNLOAD = wget -O $@ --no-use-server-timestamps
351 #DOWNLOAD = curl -o $@
354 # Unicode data information
356 # Before each major release, update these and run make update-unicode.
358 # Pick a release from here: <https://www.unicode.org/Public/>.  Note
359 # that the most recent release listed there is often a pre-release;
360 # don't pick that one, except for testing.
361 UNICODE_VERSION = 15.1.0
363 # Pick a release from here: <http://cldr.unicode.org/index/downloads>
364 CLDR_VERSION = 45
367 # Tree-wide build support
369 # Just about every code subdirectory wants to have the generated headers
370 # available before building, but we don't want parallel makes all trying
371 # to build the same headers.  These rules, together with the recursion rules
372 # below, ensure that we update the generated headers once, if needed,
373 # at the top level of any "make all/install/check/installcheck" request.
374 # If a particular subdirectory knows this isn't needed in itself or its
375 # children, it can set NO_GENERATED_HEADERS.
377 all install check installcheck: submake-generated-headers
379 .PHONY: submake-generated-headers
381 submake-generated-headers:
382 ifndef NO_GENERATED_HEADERS
383 ifeq ($(MAKELEVEL),0)
384         $(MAKE) -C $(top_builddir)/src/backend generated-headers
385 endif
386 endif
389 # Testing
391 # In much the same way as above, these rules ensure that we build a temp
392 # install tree just once in any recursive "make check".  The additional test
393 # on abs_top_builddir prevents doing anything foolish to the root directory.
395 check: temp-install
397 .PHONY: temp-install
400 # prepend to path if already set, else just set it
401 define add_to_path
402 $(1)="$(if $($(1)),$(2):$$$(1),$(2))"
403 endef
405 # platform-specific environment variable to set shared library path
406 # individual ports can override this later, this is the default name
407 ld_library_path_var = LD_LIBRARY_PATH
409 # with_temp_install_extra is for individual ports to define if they
410 # need something more here. If not defined then the expansion does
411 # nothing.
412 with_temp_install = \
413         PATH="$(abs_top_builddir)/tmp_install$(bindir):$(CURDIR):$$PATH" \
414         $(call add_to_path,$(strip $(ld_library_path_var)),$(abs_top_builddir)/tmp_install$(libdir)) \
415         INITDB_TEMPLATE='$(abs_top_builddir)'/tmp_install/initdb-template \
416         $(with_temp_install_extra)
418 temp-install: | submake-generated-headers
419 ifndef NO_TEMP_INSTALL
420 ifneq ($(abs_top_builddir),)
421 ifeq ($(MAKELEVEL),0)
422         rm -rf '$(abs_top_builddir)'/tmp_install
423         $(MKDIR_P) '$(abs_top_builddir)'/tmp_install/log
424         $(MAKE) -C '$(top_builddir)' DESTDIR='$(abs_top_builddir)'/tmp_install install >'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
425         $(MAKE) -j1 $(if $(CHECKPREP_TOP),-C $(CHECKPREP_TOP),) checkprep >>'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
427         $(with_temp_install) initdb --auth trust --no-sync --no-instructions --lc-messages=C --no-clean '$(abs_top_builddir)'/tmp_install/initdb-template >>'$(abs_top_builddir)'/tmp_install/log/initdb-template.log 2>&1
428 endif
429 endif
430 endif
432 # Tasks to run serially at the end of temp-install.  Some EXTRA_INSTALL
433 # entries appear more than once in the tree, and parallel installs of the same
434 # file can fail with EEXIST.
435 checkprep:
436         $(if $(EXTRA_INSTALL),for extra in $(EXTRA_INSTALL); do $(MAKE) -C '$(top_builddir)'/$$extra DESTDIR='$(abs_top_builddir)'/tmp_install install || exit; done)
438 PROVE = @PROVE@
439 # There are common routines in src/test/perl, and some test suites have
440 # extra perl modules in their own directory.
441 PG_PROVE_FLAGS = -I $(top_srcdir)/src/test/perl/ -I $(srcdir)
442 # User-supplied prove flags such as --verbose can be provided in PROVE_FLAGS.
443 PROVE_FLAGS =
445 ifeq ($(enable_tap_tests),yes)
447 ifndef PGXS
448 define prove_installcheck
449 echo "# +++ tap install-check in $(subdir) +++" && \
450 rm -rf '$(CURDIR)'/tmp_check && \
451 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
452 cd $(srcdir) && \
453    TESTLOGDIR='$(CURDIR)/tmp_check/log' \
454    TESTDATADIR='$(CURDIR)/tmp_check' \
455    PATH="$(bindir):$(CURDIR):$$PATH" \
456    PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' \
457    PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
458    $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
459 endef
460 else # PGXS case
461 define prove_installcheck
462 echo "# +++ tap install-check in $(subdir) +++" && \
463 rm -rf '$(CURDIR)'/tmp_check && \
464 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
465 cd $(srcdir) && \
466    TESTLOGDIR='$(CURDIR)/tmp_check/log' \
467    TESTDATADIR='$(CURDIR)/tmp_check' \
468    PATH="$(bindir):$(CURDIR):$$PATH" \
469    PGPORT='6$(DEF_PGPORT)' \
470    PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' \
471    $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
472 endef
473 endif # PGXS
475 define prove_check
476 echo "# +++ tap check in $(subdir) +++" && \
477 rm -rf '$(CURDIR)'/tmp_check && \
478 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
479 cd $(srcdir) && \
480    TESTLOGDIR='$(CURDIR)/tmp_check/log' \
481    TESTDATADIR='$(CURDIR)/tmp_check' \
482    $(with_temp_install) \
483    PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' \
484    PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
485    $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
486 endef
488 else
489 prove_installcheck = @echo "TAP tests not enabled. Try configuring with --enable-tap-tests"
490 prove_check = $(prove_installcheck)
491 endif
493 # Installation.
495 install_bin = @install_bin@
496 install_sh = $(SHELL) $(top_srcdir)/config/install-sh -c
497 INSTALL = $(if $(use_install_sh),$(install_sh),$(if $(install_bin),$(install_bin),$(install_sh)))
499 INSTALL_SCRIPT_MODE     = 755
500 INSTALL_DATA_MODE       = 644
501 INSTALL_PROGRAM = $(INSTALL_PROGRAM_ENV) $(INSTALL) $(INSTALL_STRIP_FLAG)
502 INSTALL_SCRIPT  = $(INSTALL) -m $(INSTALL_SCRIPT_MODE)
503 INSTALL_DATA    = $(INSTALL) -m $(INSTALL_DATA_MODE)
504 INSTALL_STLIB   = $(INSTALL_STLIB_ENV) $(INSTALL_DATA) $(INSTALL_STRIP_FLAG)
505 INSTALL_SHLIB   = $(INSTALL_SHLIB_ENV) $(INSTALL) $(INSTALL_SHLIB_OPTS) $(INSTALL_STRIP_FLAG)
506 # Override in Makefile.port if necessary
507 INSTALL_SHLIB_OPTS = -m 755
509 MKDIR_P = @MKDIR_P@
511 missing         = $(SHELL) $(top_srcdir)/config/missing
513 STRIP           = @STRIP@
514 STRIP_STATIC_LIB = @STRIP_STATIC_LIB@
515 STRIP_SHARED_LIB = @STRIP_SHARED_LIB@
517 # Documentation
519 DBTOEPUB        = @DBTOEPUB@
520 FOP                             = @FOP@
521 XMLLINT                 = @XMLLINT@
522 XSLTPROC                = @XSLTPROC@
524 # Code coverage
526 GCOV = @GCOV@
527 LCOV = @LCOV@
528 GENHTML = @GENHTML@
530 # Feature settings
532 DEF_PGPORT = @default_port@
533 WANTED_LANGUAGES = @WANTED_LANGUAGES@
536 ##########################################################################
538 # Additional platform-specific settings
541 # Name of the "template"
542 PORTNAME= @PORTNAME@
544 build_os = @build_os@
546 host_tuple = @host@
547 host_os = @host_os@
548 host_cpu = @host_cpu@
550 # Backend stack size limit has to be hard-wired on Windows (it's in bytes)
551 WIN32_STACK_RLIMIT=4194304
553 DLSUFFIX = @DLSUFFIX@
555 # Pull in platform-specific magic
556 include $(top_builddir)/src/Makefile.port
558 # Set up rpath if enabled.  By default it will point to our libdir,
559 # but individual Makefiles can force other rpath paths if needed.
560 rpathdir = $(libdir)
562 ifeq ($(enable_rpath), yes)
563 LDFLAGS += $(rpath)
564 endif
566 # Show the DLSUFFIX to build scripts (e.g. buildfarm)
567 .PHONY: show_dl_suffix
568 show_dl_suffix:
569         @echo $(DLSUFFIX)
572 ##########################################################################
574 # Some variables needed to find some client interfaces
576 ifdef PGXS
577 # some contribs assumes headers and libs are in the source tree...
578 libpq_srcdir = $(includedir)
579 libpq_builddir = $(libdir)
580 else
581 libpq_srcdir = $(top_srcdir)/src/interfaces/libpq
582 libpq_builddir = $(top_builddir)/src/interfaces/libpq
583 endif
585 # How to link to libpq.  (This macro may be used as-is by backend extensions.
586 # Client-side code should go through libpq_pgport or libpq_pgport_shlib,
587 # instead.)
588 libpq = -L$(libpq_builddir) -lpq
590 # libpq_pgport is for use by client executables (not libraries) that use libpq.
591 # We used to use this to force libpgport and libpgcommon to be linked before
592 # libpq, ensuring that clients would pull symbols from those libraries rather
593 # than possibly getting them from libpq (and thereby having an unwanted
594 # dependency on which symbols libpq uses).  However, now that we can prevent
595 # libpq from exporting those symbols on all platforms of interest, we don't
596 # worry about that anymore.  The previous technique resulted in duplicate
597 # libraries in link commands, since those libraries also appear in $(LIBS).
598 # Some platforms warn about that, so avoiding those warnings is now more
599 # important.  Hence, $(libpq_pgport) is now equivalent to $(libpq), but we
600 # still recommend using it for client executables in case some other reason
601 # appears to handle them differently.
602 libpq_pgport = $(libpq)
604 # libpq_pgport_shlib is the same idea, but for use in client shared libraries.
605 # We need those clients to use the shlib variants.  (Ideally, users of this
606 # macro would strip libpgport and libpgcommon from $(LIBS), but no harm is
607 # done if they don't, since they will have satisfied all their references
608 # from these libraries.)
609 ifdef PGXS
610 libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
611 else
612 libpq_pgport_shlib = -L$(top_builddir)/src/common -lpgcommon_shlib -L$(top_builddir)/src/port -lpgport_shlib $(libpq)
613 endif
615 # Cygwin seems to need ldap libraries to be mentioned here, too
616 ifeq ($(PORTNAME),cygwin)
617 libpq_pgport += $(LDAP_LIBS_FE)
618 endif
621 ##########################################################################
623 # Commonly used submake targets
625 submake-libpq: | submake-generated-headers
626         $(MAKE) -C $(libpq_builddir) all
628 submake-libpgport: | submake-generated-headers
629         $(MAKE) -C $(top_builddir)/src/port all
630         $(MAKE) -C $(top_builddir)/src/common all
632 submake-libpgfeutils: | submake-generated-headers
633         $(MAKE) -C $(top_builddir)/src/port all
634         $(MAKE) -C $(top_builddir)/src/common all
635         $(MAKE) -C $(top_builddir)/src/fe_utils all
637 .PHONY: submake-libpq submake-libpgport submake-libpgfeutils
640 ##########################################################################
642 # Testing support
644 ifneq ($(USE_MODULE_DB),)
645   PL_TESTDB = pl_regression_$(NAME)
646   ifneq ($(MODULE_big),)
647     CONTRIB_TESTDB=contrib_regression_$(MODULE_big)
648     ISOLATION_TESTDB=isolation_regression_$(MODULE_big)
649   else
650     ifneq ($(MODULES),)
651       CONTRIB_TESTDB=contrib_regression_$(word 1,$(MODULES))
652       ISOLATION_TESTDB=isolation_regression_$(word 1,$(MODULES))
653     else
654       CONTRIB_TESTDB=contrib_regression_$(word 1,$(REGRESS))
655       ISOLATION_TESTDB=isolation_regression_$(word 1,$(ISOLATION))
656     endif
657   endif
658 else
659   PL_TESTDB = pl_regression
660   CONTRIB_TESTDB = contrib_regression
661   ISOLATION_TESTDB = isolation_regression
662 endif
664 ifdef NO_LOCALE
665 NOLOCALE += --no-locale
666 endif
668 # file with extra config for temp build
669 TEMP_CONF =
670 ifdef TEMP_CONFIG
671 TEMP_CONF += --temp-config=$(TEMP_CONFIG)
672 endif
674 pg_regress_locale_flags = $(if $(ENCODING),--encoding=$(ENCODING)) $(NOLOCALE)
675 pg_regress_clean_files = results/ regression.diffs regression.out tmp_check/ tmp_check_iso/ log/ output_iso/
677 pg_regress_check = \
678     echo "\# +++ regress check in $(subdir) +++" && \
679     $(with_temp_install) \
680     $(top_builddir)/src/test/regress/pg_regress \
681     --temp-instance=./tmp_check \
682     --inputdir=$(srcdir) \
683     --bindir= \
684     $(TEMP_CONF) \
685     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
686 pg_regress_installcheck = \
687     echo "\# +++ regress install-check in $(subdir) +++" && \
688     $(top_builddir)/src/test/regress/pg_regress \
689     --inputdir=$(srcdir) \
690     --bindir='$(bindir)' \
691     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
693 pg_isolation_regress_check = \
694     echo "\# +++ isolation check in $(subdir) +++" && \
695     $(with_temp_install) \
696     $(top_builddir)/src/test/isolation/pg_isolation_regress \
697     --temp-instance=./tmp_check_iso \
698     --inputdir=$(srcdir) --outputdir=output_iso \
699     --bindir= \
700     $(TEMP_CONF) \
701     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
702 pg_isolation_regress_installcheck = \
703     echo "\# +++ isolation install-check in $(subdir) +++" && \
704     $(top_builddir)/src/test/isolation/pg_isolation_regress \
705     --inputdir=$(srcdir) --outputdir=output_iso \
706     --bindir='$(bindir)' \
707     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
709 ##########################################################################
711 # Customization
713 # This includes your local customizations if Makefile.custom exists
714 # in the source directory.  This file doesn't exist in the original
715 # distribution so that it doesn't get overwritten when you upgrade.
717 # NOTE:  Makefile.custom is from the pre-Autoconf days of PostgreSQL.
718 # You are liable to shoot yourself in the foot if you use it without
719 # knowing exactly what you're doing.  The preferred (and more
720 # reliable) method is to communicate what you want to do to the
721 # configure script, and leave the makefiles alone.
723 -include $(top_srcdir)/src/Makefile.custom
725 ifneq ($(CUSTOM_INSTALL),)
726 INSTALL= $(CUSTOM_INSTALL)
727 endif
729 ifneq ($(CUSTOM_CC),)
730   CC= $(CUSTOM_CC)
731 endif
733 ifneq ($(CUSTOM_COPT),)
734   COPT= $(CUSTOM_COPT)
735 endif
738 # These variables are meant to be set in the environment of "make"
739 # to add flags to whatever configure picked.  Unlike the ones above,
740 # they are documented.
742 ifdef COPT
743    CFLAGS += $(COPT)
744    LDFLAGS += $(COPT)
745 endif
747 ifdef PROFILE
748    CFLAGS += $(PROFILE)
749    LDFLAGS += $(PROFILE)
750 endif
753 ##########################################################################
755 # substitute implementations of C library routines (see src/port/)
756 # note we already included -L.../src/port in LDFLAGS above
758 LIBOBJS = @LIBOBJS@
760 # files needed for the chosen CRC-32C implementation
761 PG_CRC32C_OBJS = @PG_CRC32C_OBJS@
763 # files needed for the chosen popcount implementation
764 PG_POPCNT_OBJS = @PG_POPCNT_OBJS@
766 LIBS := -lpgcommon -lpgport $(LIBS)
768 # to make ws2_32.lib the last library
769 ifeq ($(PORTNAME),win32)
770 LIBS += -lws2_32
771 endif
773 # Not really standard libc functions, used by the backend.
774 TAS         = @TAS@
777 ##########################################################################
779 # Global targets and rules
781 %.c: %.l
782         $(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $<
783         @$(if $(FLEX_NO_BACKUP),if [ `wc -l <lex.backup` -eq 1 ]; then rm lex.backup; else echo "Scanner requires backup; see lex.backup." 1>&2; exit 1; fi)
784         $(if $(FLEX_FIX_WARNING),$(PERL) $(top_srcdir)/src/tools/fix-old-flex-code.pl '$@')
786 %.c: %.y
787         $(if $(BISON_CHECK_CMD),$(BISON_CHECK_CMD))
788         $(BISON) $(BISONFLAGS) -o $@ $<
790 %.i: %.c
791         $(CPP) $(CPPFLAGS) -o $@ $<
793 %.gz: %
794         $(GZIP) --best -c $< >$@
796 %.bz2: %
797         $(BZIP2) -c $< >$@
799 # Direct builds of foo.c -> foo are disabled to avoid generating
800 # *.dSYM junk on Macs.  All builds should normally go through the
801 # foo.c -> foo.o -> foo steps.  This also ensures that dependency
802 # tracking (see below) is used.
803 %: %.c
805 # Replace gmake's default rule for linking a single .o file to produce an
806 # executable.  The main point here is to put LDFLAGS after the .o file,
807 # since we put -l switches into LDFLAGS and those are order-sensitive.
808 # In addition, include CFLAGS and LDFLAGS_EX per project conventions.
809 %: %.o
810         $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
812 ifndef PGXS
814 # Remake Makefile.global from Makefile.global.in if the latter
815 # changed. In order to trigger this rule, the including file must
816 # write `include $(top_builddir)/src/Makefile.global', not some
817 # shortcut thereof.
818 $(top_builddir)/src/Makefile.global: $(top_srcdir)/src/Makefile.global.in $(top_builddir)/config.status
819         cd $(top_builddir) && ./config.status src/Makefile.global
821 # Remake pg_config.h from pg_config.h.in if the latter changed.
822 # config.status will not change the timestamp on pg_config.h if it
823 # doesn't change, so as to avoid recompiling the entire tree
824 # unnecessarily. Therefore we make config.status update a timestamp file
825 # stamp-h every time it runs, so that we don't trigger this rule every time.
826 # (We do trigger the null rule for stamp-h to pg_config.h every time; so it's
827 # important for that rule to be empty!)
829 # Of course you need to turn on dependency tracking to get any
830 # dependencies on pg_config.h.
831 $(top_builddir)/src/include/pg_config.h: $(top_builddir)/src/include/stamp-h ;
833 $(top_builddir)/src/include/stamp-h: $(top_srcdir)/src/include/pg_config.h.in $(top_builddir)/config.status
834         cd $(top_builddir) && ./config.status src/include/pg_config.h
836 # Also remake pg_config_ext.h from pg_config_ext.h.in, same logic as above.
837 $(top_builddir)/src/include/pg_config_ext.h: $(top_builddir)/src/include/stamp-ext-h ;
839 $(top_builddir)/src/include/stamp-ext-h: $(top_srcdir)/src/include/pg_config_ext.h.in $(top_builddir)/config.status
840         cd $(top_builddir) && ./config.status src/include/pg_config_ext.h
842 # Also remake ecpg_config.h from ecpg_config.h.in if the latter changed, same
843 # logic as above.
844 $(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h: $(top_builddir)/src/interfaces/ecpg/include/stamp-h ;
846  $(top_builddir)/src/interfaces/ecpg/include/stamp-h: $(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h.in $(top_builddir)/config.status
847         cd $(top_builddir) && ./config.status src/interfaces/ecpg/include/ecpg_config.h
849 # When configure changes, rerun configure with the same options as
850 # last time. To change configure, you need to run autoconf manually.
851 $(top_builddir)/config.status: $(top_srcdir)/configure
852         cd $(top_builddir) && ./config.status --recheck
854 endif # not PGXS
857 install-strip:
858 # install-strip always uses install-sh, so that strip options can be
859 # passed.
860         $(MAKE) use_install_sh=yes \
861             INSTALL_PROGRAM_ENV="STRIPPROG='$(STRIP)'" \
862             INSTALL_STLIB_ENV="STRIPPROG='$(STRIP_STATIC_LIB)'" \
863             INSTALL_SHLIB_ENV="STRIPPROG='$(STRIP_SHARED_LIB)'" \
864             INSTALL_STRIP_FLAG=-s \
865             install
868 ##########################################################################
870 # Recursive make support
871 # ----------------------
872 # Instead of recursing through subdirectories with a for loop or
873 # repeated $(MAKE) -C whatever calls, this is a little smarter: it
874 # allows parallel make across directories and lets make -k and -q work
875 # correctly.
877 # We need the ability to export target-specific variables, which was
878 # added in GNU make 3.81.  That also happens to be the version
879 # where the .FEATURES variable was introduced, so this is a simple check.
880 ifndef .FEATURES
881 $(error GNU make 3.81 or newer is required.  You are using version $(MAKE_VERSION))
882 endif
884 # This function is only for internal use below.  It should be called
885 # using $(eval).  It will set up a target so that it recurses into a
886 # given subdirectory.  For the tree-wide all/install/check/installcheck cases,
887 # ensure we do our one-time tasks before recursing (see targets above).
888 # Note that to avoid a nasty bug in make 3.80,
889 # this function was written to not use any complicated constructs (like
890 # multiple targets on a line) and also not contain any lines that expand
891 # to more than about 200 bytes.  This is why we make it apply to just one
892 # subdirectory at a time, rather than to a list of subdirectories.
893 # $1: target name, e.g., all
894 # $2: subdir name
895 # $3: target to run in subdir, usually same as $1
896 define _create_recursive_target
897 .PHONY: $(1)-$(2)-recurse
898 $(1): $(1)-$(2)-recurse
899 $(1)-$(2)-recurse: $(if $(filter all install check installcheck, $(3)), submake-generated-headers) $(if $(filter check, $(3)), temp-install)
900         $$(MAKE) -C $(2) $(3)
901 endef
902 # Note that the use of $$ on the last line above is important; we want
903 # $(MAKE) to be evaluated when the rule is run, not when the $(eval) is run
904 # to create the rule.  This is necessary to get make -q working.
906 # Call this function in a makefile that needs to recurse into subdirectories.
907 # In the normal case all arguments can be defaulted.
908 # $1: targets to make recursive (defaults to list of standard targets)
909 # $2: list of subdirs (defaults to SUBDIRS variable)
910 # $3: target to run in subdir (defaults to current element of $1)
911 recurse = $(foreach target,$(if $1,$1,$(standard_targets)),$(foreach subdir,$(if $2,$2,$(SUBDIRS)),$(eval $(call _create_recursive_target,$(target),$(subdir),$(if $3,$3,$(target))))))
913 # If a makefile's list of SUBDIRS varies depending on configuration, then
914 # any subdirectories excluded from SUBDIRS should instead be added to
915 # ALWAYS_SUBDIRS, and then it must call recurse_always as well as recurse.
916 # This ensures that distclean, etc will apply to all subdirectories.
917 # In the normal case all arguments will be defaulted.
918 # $1: targets to make recursive (defaults to standard_always_targets)
919 # $2: list of subdirs (defaults to ALWAYS_SUBDIRS variable)
920 # $3: target to run in subdir (defaults to current element of $1)
921 recurse_always = $(foreach target,$(if $1,$1,$(standard_always_targets)),$(foreach subdir,$(if $2,$2,$(ALWAYS_SUBDIRS)),$(eval $(call _create_recursive_target,$(target),$(subdir),$(if $3,$3,$(target))))))
924 ##########################################################################
926 # Automatic dependency generation
927 # -------------------------------
928 # When we configure with --enable-depend then we override the default
929 # compilation rule with the magic below. While or after creating the
930 # actual output file we also create a dependency list for the .c file.
931 # Next time we invoke make we will have top-notch information about
932 # whether this file needs to be updated. The dependency files are kept
933 # in the .deps subdirectory of each directory.
935 autodepend = @autodepend@
937 ifeq ($(autodepend), yes)
939 ifndef COMPILE.c
940 COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
941 endif
943 ifndef COMPILE.cc
944 COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
945 endif
947 DEPDIR = .deps
949 ifeq ($(GCC), yes)
951 # GCC allows us to create object and dependency file in one invocation.
952 %.o : %.c
953         @if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
954         $(COMPILE.c) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
956 %.o : %.cpp
957         @if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
958         $(COMPILE.cc) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
960 endif # GCC
962 # Include all the dependency files generated for the current
963 # directory. Note that make would complain if include was called with
964 # no arguments.
965 Po_files := $(wildcard $(DEPDIR)/*.Po)
966 ifneq (,$(Po_files))
967 include $(Po_files)
968 endif
970 # hook for clean-up
971 clean distclean: clean-deps
973 .PHONY: clean-deps
974 clean-deps:
975         @rm -rf $(DEPDIR)
977 endif # autodepend
980 ##########################################################################
982 # Native language support
984 ifeq ($(enable_nls), yes)
985 ifneq (,$(wildcard $(srcdir)/nls.mk))
987 include $(top_srcdir)/src/nls-global.mk
989 endif # nls.mk
990 endif # enable_nls
993 ##########################################################################
995 # Coverage
997 # Explanation of involved files:
998 #   foo.c       source file
999 #   foo.o       object file
1000 #   foo.gcno    gcov graph (a.k.a. "notes") file, created at compile time
1001 #               (by gcc -ftest-coverage)
1002 #   foo.gcda    gcov data file, created when the program is run (for
1003 #               programs compiled with gcc -fprofile-arcs)
1004 #   foo.c.gcov  gcov output file with coverage information, created by
1005 #               gcov from foo.gcda (by "make coverage")
1006 #   foo.c.gcov.out  stdout captured when foo.c.gcov is created, mildly
1007 #               interesting
1008 #   lcov_test.info
1009 #               lcov tracefile, built from gcda files in one directory,
1010 #               later collected by "make coverage-html"
1011 #   lcov_base.info
1012 #               tracefile for zero counters for every file, so that
1013 #               even files that are not touched by tests are counted
1014 #               for the overall coverage rate
1016 ifeq ($(enable_coverage), yes)
1018 # make coverage -- text output
1020 local_gcda_files = $(wildcard *.gcda)
1022 coverage: $(local_gcda_files:.gcda=.c.gcov)
1024 %.c.gcov: %.gcda
1025         $(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
1027 # make coverage-html -- HTML output via lcov
1029 .PHONY: coverage-html
1030 coverage-html: coverage-html-stamp
1032 GENHTML_FLAGS = -q --legend
1033 GENHTML_TITLE = PostgreSQL $(VERSION)
1035 coverage-html-stamp: lcov_base.info lcov_test.info
1036         rm -rf coverage
1037         $(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 $(if $(filter no,$(vpath_build)),--prefix='$(abs_top_srcdir)') $^
1038         touch $@
1040 LCOV += --gcov-tool $(GCOV)
1041 LCOVFLAGS = -q --no-external
1043 all_gcno_files = $(shell find . -name '*.gcno' -print)
1045 lcov_base.info: $(all_gcno_files)
1046         $(LCOV) $(LCOVFLAGS) -c -i -d . -d $(srcdir) -o $@
1048 all_gcda_files = $(shell find . -name '*.gcda' -print)
1050 lcov_test.info: $(all_gcda_files)
1051         $(LCOV) $(LCOVFLAGS) -c -d . -d $(srcdir) -o $@
1054 # hook for clean-up
1055 clean distclean: clean-coverage
1057 .PHONY: clean-coverage
1058 clean-coverage:
1059         rm -rf coverage coverage-html-stamp
1060         rm -f *.gcda *.gcno lcov*.info *.gcov .*.gcov *.gcov.out
1063 # User-callable target to reset counts between test runs
1064 coverage-clean:
1065         rm -f `find . -name '*.gcda' -print`
1067 endif # enable_coverage
1069 ##########################################################################
1071 # LLVM support
1074 ifndef COMPILE.c.bc
1075 # -Wno-ignored-attributes added so gnu_printf doesn't trigger
1076 # warnings, when the main binary is compiled with C.
1077 COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
1078 endif
1080 ifndef COMPILE.cxx.bc
1081 COMPILE.cxx.bc = $(CLANG) -xc++ -Wno-ignored-attributes $(BITCODE_CXXFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
1082 endif
1084 %.bc : %.c
1085         $(COMPILE.c.bc) -o $@ $<
1087 %.bc : %.cpp
1088         $(COMPILE.cxx.bc) -o $@ $<
1090 # Install LLVM bitcode module (for JITing).
1092 # The arguments are:
1093 # $(1) name of the module (e.g. an extension's name or postgres for core code)
1094 # $(2) source objects, with .o suffix
1096 # The many INSTALL_DATA invocations aren't particularly fast, it'd be
1097 # good if we could coalesce them, but I didn't find a good way.
1099 # Note: blank line at end of macro is necessary to let it be used in foreach
1100 define install_llvm_module
1101 $(MKDIR_P) '$(DESTDIR)${bitcodedir}/$(1)'
1102 $(MKDIR_P) $(sort $(dir $(addprefix '$(DESTDIR)${bitcodedir}'/$(1)/, $(2))))
1103 $(foreach obj, ${2}, $(INSTALL_DATA) $(patsubst %.o,%.bc, $(obj)) '$(DESTDIR)${bitcodedir}'/$(1)/$(dir $(obj))
1105 cd '$(DESTDIR)${bitcodedir}' && $(LLVM_BINPATH)/llvm-lto -thinlto -thinlto-action=thinlink -o $(1).index.bc $(addprefix $(1)/,$(patsubst %.o,%.bc, $(2)))
1107 endef
1109 # Uninstall LLVM bitcode module.
1111 # The arguments are:
1112 # $(1) name of the module (e.g. an extension's name or postgres for core code)
1114 # This intentionally doesn't use the explicit installed file list,
1115 # seems too likely to change regularly.
1116 define uninstall_llvm_module
1117 rm -rf '$(DESTDIR)${bitcodedir}/$(1)/'
1118 rm -f '$(DESTDIR)${bitcodedir}/$(1).index.bc'
1120 endef