Suppress "variable may be used uninitialized" warning.
[pgsql.git] / src / Makefile.global.in
blob8b3f8c24e08e8a7527f3735686b515403efac521
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_CRC = @CFLAGS_CRC@
266 PERMIT_DECLARATION_AFTER_STATEMENT = @PERMIT_DECLARATION_AFTER_STATEMENT@
267 CXXFLAGS = @CXXFLAGS@
269 LLVM_CPPFLAGS = @LLVM_CPPFLAGS@
270 LLVM_CFLAGS = @LLVM_CFLAGS@
271 LLVM_CXXFLAGS = @LLVM_CXXFLAGS@
273 # Kind-of compilers
275 BISON = @BISON@
276 BISONFLAGS = @BISONFLAGS@ $(YFLAGS)
277 FLEX = @FLEX@
278 FLEXFLAGS = @FLEXFLAGS@ $(LFLAGS)
279 DTRACE = @DTRACE@
280 DTRACEFLAGS = @DTRACEFLAGS@
281 ZIC = @ZIC@
283 # Linking
285 AR = @AR@
286 AROPT = crs
287 LIBS = @LIBS@
288 LDAP_LIBS_FE = @LDAP_LIBS_FE@
289 LDAP_LIBS_BE = @LDAP_LIBS_BE@
290 UUID_LIBS = @UUID_LIBS@
291 LLVM_LIBS=@LLVM_LIBS@
293 # It's critical that within LDFLAGS, all -L switches pointing to build-tree
294 # directories come before any -L switches pointing to external directories.
295 # Otherwise it's possible for, e.g., a platform-provided copy of libpq.so
296 # to get linked in place of the one we've built.  Therefore we adopt the
297 # convention that the first component of LDFLAGS is an extra variable
298 # LDFLAGS_INTERNAL, and -L and -l switches for PG's own libraries must be
299 # put into LDFLAGS_INTERNAL, so they will appear ahead of those for external
300 # libraries.
302 # We need LDFLAGS and LDFLAGS_INTERNAL to be "recursively expanded" variables,
303 # else adjustments to, e.g., rpathdir don't work right.  So we must NOT do
304 # "LDFLAGS := something" anywhere, ditto for LDFLAGS_INTERNAL.
305 # These initial assignments must be "=" type, and elsewhere we must only do
306 # "LDFLAGS += something" or "LDFLAGS_INTERNAL += something".
307 ifdef PGXS
308   LDFLAGS_INTERNAL = -L$(libdir)
309 else
310   LDFLAGS_INTERNAL = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
311 endif
312 LDFLAGS = $(LDFLAGS_INTERNAL) @LDFLAGS@
314 LDFLAGS_EX = @LDFLAGS_EX@
315 LDFLAGS_EX_BE = @LDFLAGS_EX_BE@
316 # LDFLAGS_SL might have already been assigned by calling makefile
317 LDFLAGS_SL += @LDFLAGS_SL@
318 WINDRES = @WINDRES@
319 X = @EXEEXT@
321 # Perl
323 # quoted to protect pathname with spaces
324 PERL            = '@PERL@'
325 perl_archlibexp         = @perl_archlibexp@
326 perl_privlibexp         = @perl_privlibexp@
327 perl_includespec        = @perl_includespec@
328 perl_embed_ccflags      = @perl_embed_ccflags@
329 perl_embed_ldflags      = @perl_embed_ldflags@
331 # Miscellaneous
333 AWK     = @AWK@
334 LN_S    = @LN_S@
335 MSGFMT  = @MSGFMT@
336 MSGFMT_FLAGS = @MSGFMT_FLAGS@
337 MSGMERGE = @MSGMERGE@
338 OPENSSL = @OPENSSL@
339 PYTHON  = @PYTHON@
340 TAR     = @TAR@
341 XGETTEXT = @XGETTEXT@
343 GZIP    = gzip
344 BZIP2   = bzip2
345 LZ4     = @LZ4@
346 ZSTD    = @ZSTD@
348 DOWNLOAD = wget -O $@ --no-use-server-timestamps
349 #DOWNLOAD = curl -o $@
352 # Unicode data information
354 # Before each major release, update these and run make update-unicode.
356 # Pick a release from here: <https://www.unicode.org/Public/>.  Note
357 # that the most recent release listed there is often a pre-release;
358 # don't pick that one, except for testing.
359 UNICODE_VERSION = 15.1.0
361 # Pick a release from here: <http://cldr.unicode.org/index/downloads>
362 CLDR_VERSION = 43
365 # Tree-wide build support
367 # Just about every code subdirectory wants to have the generated headers
368 # available before building, but we don't want parallel makes all trying
369 # to build the same headers.  These rules, together with the recursion rules
370 # below, ensure that we update the generated headers once, if needed,
371 # at the top level of any "make all/install/check/installcheck" request.
372 # If a particular subdirectory knows this isn't needed in itself or its
373 # children, it can set NO_GENERATED_HEADERS.
375 all install check installcheck: submake-generated-headers
377 .PHONY: submake-generated-headers
379 submake-generated-headers:
380 ifndef NO_GENERATED_HEADERS
381 ifeq ($(MAKELEVEL),0)
382         $(MAKE) -C $(top_builddir)/src/backend generated-headers
383 endif
384 endif
387 # Testing
389 # In much the same way as above, these rules ensure that we build a temp
390 # install tree just once in any recursive "make check".  The additional test
391 # on abs_top_builddir prevents doing anything foolish to the root directory.
393 check: temp-install
395 .PHONY: temp-install
398 # prepend to path if already set, else just set it
399 define add_to_path
400 $(1)="$(if $($(1)),$(2):$$$(1),$(2))"
401 endef
403 # platform-specific environment variable to set shared library path
404 # individual ports can override this later, this is the default name
405 ld_library_path_var = LD_LIBRARY_PATH
407 # with_temp_install_extra is for individual ports to define if they
408 # need something more here. If not defined then the expansion does
409 # nothing.
410 with_temp_install = \
411         PATH="$(abs_top_builddir)/tmp_install$(bindir):$(CURDIR):$$PATH" \
412         $(call add_to_path,$(strip $(ld_library_path_var)),$(abs_top_builddir)/tmp_install$(libdir)) \
413         INITDB_TEMPLATE='$(abs_top_builddir)'/tmp_install/initdb-template \
414         $(with_temp_install_extra)
416 temp-install: | submake-generated-headers
417 ifndef NO_TEMP_INSTALL
418 ifneq ($(abs_top_builddir),)
419 ifeq ($(MAKELEVEL),0)
420         rm -rf '$(abs_top_builddir)'/tmp_install
421         $(MKDIR_P) '$(abs_top_builddir)'/tmp_install/log
422         $(MAKE) -C '$(top_builddir)' DESTDIR='$(abs_top_builddir)'/tmp_install install >'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
423         $(MAKE) -j1 $(if $(CHECKPREP_TOP),-C $(CHECKPREP_TOP),) checkprep >>'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
425         $(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
426 endif
427 endif
428 endif
430 # Tasks to run serially at the end of temp-install.  Some EXTRA_INSTALL
431 # entries appear more than once in the tree, and parallel installs of the same
432 # file can fail with EEXIST.
433 checkprep:
434         $(if $(EXTRA_INSTALL),for extra in $(EXTRA_INSTALL); do $(MAKE) -C '$(top_builddir)'/$$extra DESTDIR='$(abs_top_builddir)'/tmp_install install || exit; done)
436 PROVE = @PROVE@
437 # There are common routines in src/test/perl, and some test suites have
438 # extra perl modules in their own directory.
439 PG_PROVE_FLAGS = -I $(top_srcdir)/src/test/perl/ -I $(srcdir)
440 # User-supplied prove flags such as --verbose can be provided in PROVE_FLAGS.
441 PROVE_FLAGS =
443 ifeq ($(enable_tap_tests),yes)
445 ifndef PGXS
446 define prove_installcheck
447 echo "# +++ tap install-check in $(subdir) +++" && \
448 rm -rf '$(CURDIR)'/tmp_check && \
449 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
450 cd $(srcdir) && \
451    TESTLOGDIR='$(CURDIR)/tmp_check/log' \
452    TESTDATADIR='$(CURDIR)/tmp_check' \
453    PATH="$(bindir):$(CURDIR):$$PATH" \
454    PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' \
455    PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
456    $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
457 endef
458 else # PGXS case
459 define prove_installcheck
460 echo "# +++ tap install-check in $(subdir) +++" && \
461 rm -rf '$(CURDIR)'/tmp_check && \
462 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
463 cd $(srcdir) && \
464    TESTLOGDIR='$(CURDIR)/tmp_check/log' \
465    TESTDATADIR='$(CURDIR)/tmp_check' \
466    PATH="$(bindir):$(CURDIR):$$PATH" \
467    PGPORT='6$(DEF_PGPORT)' \
468    PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' \
469    $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
470 endef
471 endif # PGXS
473 define prove_check
474 echo "# +++ tap check in $(subdir) +++" && \
475 rm -rf '$(CURDIR)'/tmp_check && \
476 $(MKDIR_P) '$(CURDIR)'/tmp_check && \
477 cd $(srcdir) && \
478    TESTLOGDIR='$(CURDIR)/tmp_check/log' \
479    TESTDATADIR='$(CURDIR)/tmp_check' \
480    $(with_temp_install) \
481    PGPORT='6$(DEF_PGPORT)' top_builddir='$(CURDIR)/$(top_builddir)' \
482    PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
483    $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
484 endef
486 else
487 prove_installcheck = @echo "TAP tests not enabled. Try configuring with --enable-tap-tests"
488 prove_check = $(prove_installcheck)
489 endif
491 # Installation.
493 install_bin = @install_bin@
494 install_sh = $(SHELL) $(top_srcdir)/config/install-sh -c
495 INSTALL = $(if $(use_install_sh),$(install_sh),$(if $(install_bin),$(install_bin),$(install_sh)))
497 INSTALL_SCRIPT_MODE     = 755
498 INSTALL_DATA_MODE       = 644
499 INSTALL_PROGRAM = $(INSTALL_PROGRAM_ENV) $(INSTALL) $(INSTALL_STRIP_FLAG)
500 INSTALL_SCRIPT  = $(INSTALL) -m $(INSTALL_SCRIPT_MODE)
501 INSTALL_DATA    = $(INSTALL) -m $(INSTALL_DATA_MODE)
502 INSTALL_STLIB   = $(INSTALL_STLIB_ENV) $(INSTALL_DATA) $(INSTALL_STRIP_FLAG)
503 INSTALL_SHLIB   = $(INSTALL_SHLIB_ENV) $(INSTALL) $(INSTALL_SHLIB_OPTS) $(INSTALL_STRIP_FLAG)
504 # Override in Makefile.port if necessary
505 INSTALL_SHLIB_OPTS = -m 755
507 MKDIR_P = @MKDIR_P@
509 missing         = $(SHELL) $(top_srcdir)/config/missing
511 STRIP           = @STRIP@
512 STRIP_STATIC_LIB = @STRIP_STATIC_LIB@
513 STRIP_SHARED_LIB = @STRIP_SHARED_LIB@
515 # Documentation
517 DBTOEPUB        = @DBTOEPUB@
518 FOP                             = @FOP@
519 XMLLINT                 = @XMLLINT@
520 XSLTPROC                = @XSLTPROC@
522 # Code coverage
524 GCOV = @GCOV@
525 LCOV = @LCOV@
526 GENHTML = @GENHTML@
528 # Feature settings
530 DEF_PGPORT = @default_port@
531 WANTED_LANGUAGES = @WANTED_LANGUAGES@
534 ##########################################################################
536 # Additional platform-specific settings
539 # Name of the "template"
540 PORTNAME= @PORTNAME@
542 build_os = @build_os@
544 host_tuple = @host@
545 host_os = @host_os@
546 host_cpu = @host_cpu@
548 # Backend stack size limit has to be hard-wired on Windows (it's in bytes)
549 WIN32_STACK_RLIMIT=4194304
551 DLSUFFIX = @DLSUFFIX@
553 # Pull in platform-specific magic
554 include $(top_builddir)/src/Makefile.port
556 # Set up rpath if enabled.  By default it will point to our libdir,
557 # but individual Makefiles can force other rpath paths if needed.
558 rpathdir = $(libdir)
560 ifeq ($(enable_rpath), yes)
561 LDFLAGS += $(rpath)
562 endif
564 # Show the DLSUFFIX to build scripts (e.g. buildfarm)
565 .PHONY: show_dl_suffix
566 show_dl_suffix:
567         @echo $(DLSUFFIX)
570 ##########################################################################
572 # Some variables needed to find some client interfaces
574 ifdef PGXS
575 # some contribs assumes headers and libs are in the source tree...
576 libpq_srcdir = $(includedir)
577 libpq_builddir = $(libdir)
578 else
579 libpq_srcdir = $(top_srcdir)/src/interfaces/libpq
580 libpq_builddir = $(top_builddir)/src/interfaces/libpq
581 endif
583 # How to link to libpq.  (This macro may be used as-is by backend extensions.
584 # Client-side code should go through libpq_pgport or libpq_pgport_shlib,
585 # instead.)
586 libpq = -L$(libpq_builddir) -lpq
588 # libpq_pgport is for use by client executables (not libraries) that use libpq.
589 # We used to use this to force libpgport and libpgcommon to be linked before
590 # libpq, ensuring that clients would pull symbols from those libraries rather
591 # than possibly getting them from libpq (and thereby having an unwanted
592 # dependency on which symbols libpq uses).  However, now that we can prevent
593 # libpq from exporting those symbols on all platforms of interest, we don't
594 # worry about that anymore.  The previous technique resulted in duplicate
595 # libraries in link commands, since those libraries also appear in $(LIBS).
596 # Some platforms warn about that, so avoiding those warnings is now more
597 # important.  Hence, $(libpq_pgport) is now equivalent to $(libpq), but we
598 # still recommend using it for client executables in case some other reason
599 # appears to handle them differently.
600 libpq_pgport = $(libpq)
602 # libpq_pgport_shlib is the same idea, but for use in client shared libraries.
603 # We need those clients to use the shlib variants.  (Ideally, users of this
604 # macro would strip libpgport and libpgcommon from $(LIBS), but no harm is
605 # done if they don't, since they will have satisfied all their references
606 # from these libraries.)
607 ifdef PGXS
608 libpq_pgport_shlib = -L$(libdir) -lpgcommon_shlib -lpgport_shlib $(libpq)
609 else
610 libpq_pgport_shlib = -L$(top_builddir)/src/common -lpgcommon_shlib -L$(top_builddir)/src/port -lpgport_shlib $(libpq)
611 endif
613 # Cygwin seems to need ldap libraries to be mentioned here, too
614 ifeq ($(PORTNAME),cygwin)
615 libpq_pgport += $(LDAP_LIBS_FE)
616 endif
619 ##########################################################################
621 # Commonly used submake targets
623 submake-libpq: | submake-generated-headers
624         $(MAKE) -C $(libpq_builddir) all
626 submake-libpgport: | submake-generated-headers
627         $(MAKE) -C $(top_builddir)/src/port all
628         $(MAKE) -C $(top_builddir)/src/common all
630 submake-libpgfeutils: | submake-generated-headers
631         $(MAKE) -C $(top_builddir)/src/port all
632         $(MAKE) -C $(top_builddir)/src/common all
633         $(MAKE) -C $(top_builddir)/src/fe_utils all
635 .PHONY: submake-libpq submake-libpgport submake-libpgfeutils
638 ##########################################################################
640 # Testing support
642 ifneq ($(USE_MODULE_DB),)
643   PL_TESTDB = pl_regression_$(NAME)
644   ifneq ($(MODULE_big),)
645     CONTRIB_TESTDB=contrib_regression_$(MODULE_big)
646     ISOLATION_TESTDB=isolation_regression_$(MODULE_big)
647   else
648     ifneq ($(MODULES),)
649       CONTRIB_TESTDB=contrib_regression_$(word 1,$(MODULES))
650       ISOLATION_TESTDB=isolation_regression_$(word 1,$(MODULES))
651     else
652       CONTRIB_TESTDB=contrib_regression_$(word 1,$(REGRESS))
653       ISOLATION_TESTDB=isolation_regression_$(word 1,$(ISOLATION))
654     endif
655   endif
656 else
657   PL_TESTDB = pl_regression
658   CONTRIB_TESTDB = contrib_regression
659   ISOLATION_TESTDB = isolation_regression
660 endif
662 ifdef NO_LOCALE
663 NOLOCALE += --no-locale
664 endif
666 # file with extra config for temp build
667 TEMP_CONF =
668 ifdef TEMP_CONFIG
669 TEMP_CONF += --temp-config=$(TEMP_CONFIG)
670 endif
672 pg_regress_locale_flags = $(if $(ENCODING),--encoding=$(ENCODING)) $(NOLOCALE)
673 pg_regress_clean_files = results/ regression.diffs regression.out tmp_check/ tmp_check_iso/ log/ output_iso/
675 pg_regress_check = \
676     echo "\# +++ regress check in $(subdir) +++" && \
677     $(with_temp_install) \
678     $(top_builddir)/src/test/regress/pg_regress \
679     --temp-instance=./tmp_check \
680     --inputdir=$(srcdir) \
681     --bindir= \
682     $(TEMP_CONF) \
683     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
684 pg_regress_installcheck = \
685     echo "\# +++ regress install-check in $(subdir) +++" && \
686     $(top_builddir)/src/test/regress/pg_regress \
687     --inputdir=$(srcdir) \
688     --bindir='$(bindir)' \
689     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
691 pg_isolation_regress_check = \
692     echo "\# +++ isolation check in $(subdir) +++" && \
693     $(with_temp_install) \
694     $(top_builddir)/src/test/isolation/pg_isolation_regress \
695     --temp-instance=./tmp_check_iso \
696     --inputdir=$(srcdir) --outputdir=output_iso \
697     --bindir= \
698     $(TEMP_CONF) \
699     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
700 pg_isolation_regress_installcheck = \
701     echo "\# +++ isolation install-check in $(subdir) +++" && \
702     $(top_builddir)/src/test/isolation/pg_isolation_regress \
703     --inputdir=$(srcdir) --outputdir=output_iso \
704     --bindir='$(bindir)' \
705     $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
707 ##########################################################################
709 # Customization
711 # This includes your local customizations if Makefile.custom exists
712 # in the source directory.  This file doesn't exist in the original
713 # distribution so that it doesn't get overwritten when you upgrade.
715 # NOTE:  Makefile.custom is from the pre-Autoconf days of PostgreSQL.
716 # You are liable to shoot yourself in the foot if you use it without
717 # knowing exactly what you're doing.  The preferred (and more
718 # reliable) method is to communicate what you want to do to the
719 # configure script, and leave the makefiles alone.
721 -include $(top_srcdir)/src/Makefile.custom
723 ifneq ($(CUSTOM_INSTALL),)
724 INSTALL= $(CUSTOM_INSTALL)
725 endif
727 ifneq ($(CUSTOM_CC),)
728   CC= $(CUSTOM_CC)
729 endif
731 ifneq ($(CUSTOM_COPT),)
732   COPT= $(CUSTOM_COPT)
733 endif
736 # These variables are meant to be set in the environment of "make"
737 # to add flags to whatever configure picked.  Unlike the ones above,
738 # they are documented.
740 ifdef COPT
741    CFLAGS += $(COPT)
742    LDFLAGS += $(COPT)
743 endif
745 ifdef PROFILE
746    CFLAGS += $(PROFILE)
747    LDFLAGS += $(PROFILE)
748 endif
751 ##########################################################################
753 # substitute implementations of C library routines (see src/port/)
754 # note we already included -L.../src/port in LDFLAGS above
756 LIBOBJS = @LIBOBJS@
758 # files needed for the chosen CRC-32C implementation
759 PG_CRC32C_OBJS = @PG_CRC32C_OBJS@
761 LIBS := -lpgcommon -lpgport $(LIBS)
763 # to make ws2_32.lib the last library
764 ifeq ($(PORTNAME),win32)
765 LIBS += -lws2_32
766 endif
768 # Not really standard libc functions, used by the backend.
769 TAS         = @TAS@
772 ##########################################################################
774 # Global targets and rules
776 %.c: %.l
777         $(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $<
778         @$(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)
779         $(if $(FLEX_FIX_WARNING),$(PERL) $(top_srcdir)/src/tools/fix-old-flex-code.pl '$@')
781 %.c: %.y
782         $(if $(BISON_CHECK_CMD),$(BISON_CHECK_CMD))
783         $(BISON) $(BISONFLAGS) -o $@ $<
785 %.i: %.c
786         $(CPP) $(CPPFLAGS) -o $@ $<
788 %.gz: %
789         $(GZIP) --best -c $< >$@
791 %.bz2: %
792         $(BZIP2) -c $< >$@
794 # Direct builds of foo.c -> foo are disabled to avoid generating
795 # *.dSYM junk on Macs.  All builds should normally go through the
796 # foo.c -> foo.o -> foo steps.  This also ensures that dependency
797 # tracking (see below) is used.
798 %: %.c
800 # Replace gmake's default rule for linking a single .o file to produce an
801 # executable.  The main point here is to put LDFLAGS after the .o file,
802 # since we put -l switches into LDFLAGS and those are order-sensitive.
803 # In addition, include CFLAGS and LDFLAGS_EX per project conventions.
804 %: %.o
805         $(CC) $(CFLAGS) $^ $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
807 ifndef PGXS
809 # Remake Makefile.global from Makefile.global.in if the latter
810 # changed. In order to trigger this rule, the including file must
811 # write `include $(top_builddir)/src/Makefile.global', not some
812 # shortcut thereof.
813 $(top_builddir)/src/Makefile.global: $(top_srcdir)/src/Makefile.global.in $(top_builddir)/config.status
814         cd $(top_builddir) && ./config.status src/Makefile.global
816 # Remake pg_config.h from pg_config.h.in if the latter changed.
817 # config.status will not change the timestamp on pg_config.h if it
818 # doesn't change, so as to avoid recompiling the entire tree
819 # unnecessarily. Therefore we make config.status update a timestamp file
820 # stamp-h every time it runs, so that we don't trigger this rule every time.
821 # (We do trigger the null rule for stamp-h to pg_config.h every time; so it's
822 # important for that rule to be empty!)
824 # Of course you need to turn on dependency tracking to get any
825 # dependencies on pg_config.h.
826 $(top_builddir)/src/include/pg_config.h: $(top_builddir)/src/include/stamp-h ;
828 $(top_builddir)/src/include/stamp-h: $(top_srcdir)/src/include/pg_config.h.in $(top_builddir)/config.status
829         cd $(top_builddir) && ./config.status src/include/pg_config.h
831 # Also remake pg_config_ext.h from pg_config_ext.h.in, same logic as above.
832 $(top_builddir)/src/include/pg_config_ext.h: $(top_builddir)/src/include/stamp-ext-h ;
834 $(top_builddir)/src/include/stamp-ext-h: $(top_srcdir)/src/include/pg_config_ext.h.in $(top_builddir)/config.status
835         cd $(top_builddir) && ./config.status src/include/pg_config_ext.h
837 # Also remake ecpg_config.h from ecpg_config.h.in if the latter changed, same
838 # logic as above.
839 $(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h: $(top_builddir)/src/interfaces/ecpg/include/stamp-h ;
841  $(top_builddir)/src/interfaces/ecpg/include/stamp-h: $(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h.in $(top_builddir)/config.status
842         cd $(top_builddir) && ./config.status src/interfaces/ecpg/include/ecpg_config.h
844 # When configure changes, rerun configure with the same options as
845 # last time. To change configure, you need to run autoconf manually.
846 $(top_builddir)/config.status: $(top_srcdir)/configure
847         cd $(top_builddir) && ./config.status --recheck
849 endif # not PGXS
852 install-strip:
853 # install-strip always uses install-sh, so that strip options can be
854 # passed.
855         $(MAKE) use_install_sh=yes \
856             INSTALL_PROGRAM_ENV="STRIPPROG='$(STRIP)'" \
857             INSTALL_STLIB_ENV="STRIPPROG='$(STRIP_STATIC_LIB)'" \
858             INSTALL_SHLIB_ENV="STRIPPROG='$(STRIP_SHARED_LIB)'" \
859             INSTALL_STRIP_FLAG=-s \
860             install
863 ##########################################################################
865 # Recursive make support
866 # ----------------------
867 # Instead of recursing through subdirectories with a for loop or
868 # repeated $(MAKE) -C whatever calls, this is a little smarter: it
869 # allows parallel make across directories and lets make -k and -q work
870 # correctly.
872 # We need the ability to export target-specific variables, which was
873 # added in GNU make 3.81.  That also happens to be the version
874 # where the .FEATURES variable was introduced, so this is a simple check.
875 ifndef .FEATURES
876 $(error GNU make 3.81 or newer is required.  You are using version $(MAKE_VERSION))
877 endif
879 # This function is only for internal use below.  It should be called
880 # using $(eval).  It will set up a target so that it recurses into a
881 # given subdirectory.  For the tree-wide all/install/check/installcheck cases,
882 # ensure we do our one-time tasks before recursing (see targets above).
883 # Note that to avoid a nasty bug in make 3.80,
884 # this function was written to not use any complicated constructs (like
885 # multiple targets on a line) and also not contain any lines that expand
886 # to more than about 200 bytes.  This is why we make it apply to just one
887 # subdirectory at a time, rather than to a list of subdirectories.
888 # $1: target name, e.g., all
889 # $2: subdir name
890 # $3: target to run in subdir, usually same as $1
891 define _create_recursive_target
892 .PHONY: $(1)-$(2)-recurse
893 $(1): $(1)-$(2)-recurse
894 $(1)-$(2)-recurse: $(if $(filter all install check installcheck, $(3)), submake-generated-headers) $(if $(filter check, $(3)), temp-install)
895         $$(MAKE) -C $(2) $(3)
896 endef
897 # Note that the use of $$ on the last line above is important; we want
898 # $(MAKE) to be evaluated when the rule is run, not when the $(eval) is run
899 # to create the rule.  This is necessary to get make -q working.
901 # Call this function in a makefile that needs to recurse into subdirectories.
902 # In the normal case all arguments can be defaulted.
903 # $1: targets to make recursive (defaults to list of standard targets)
904 # $2: list of subdirs (defaults to SUBDIRS variable)
905 # $3: target to run in subdir (defaults to current element of $1)
906 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))))))
908 # If a makefile's list of SUBDIRS varies depending on configuration, then
909 # any subdirectories excluded from SUBDIRS should instead be added to
910 # ALWAYS_SUBDIRS, and then it must call recurse_always as well as recurse.
911 # This ensures that distclean, etc will apply to all subdirectories.
912 # In the normal case all arguments will be defaulted.
913 # $1: targets to make recursive (defaults to standard_always_targets)
914 # $2: list of subdirs (defaults to ALWAYS_SUBDIRS variable)
915 # $3: target to run in subdir (defaults to current element of $1)
916 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))))))
919 ##########################################################################
921 # Automatic dependency generation
922 # -------------------------------
923 # When we configure with --enable-depend then we override the default
924 # compilation rule with the magic below. While or after creating the
925 # actual output file we also create a dependency list for the .c file.
926 # Next time we invoke make we will have top-notch information about
927 # whether this file needs to be updated. The dependency files are kept
928 # in the .deps subdirectory of each directory.
930 autodepend = @autodepend@
932 ifeq ($(autodepend), yes)
934 ifndef COMPILE.c
935 COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
936 endif
938 ifndef COMPILE.cc
939 COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
940 endif
942 DEPDIR = .deps
944 ifeq ($(GCC), yes)
946 # GCC allows us to create object and dependency file in one invocation.
947 %.o : %.c
948         @if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
949         $(COMPILE.c) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
951 %.o : %.cpp
952         @if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
953         $(COMPILE.cc) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
955 endif # GCC
957 # Include all the dependency files generated for the current
958 # directory. Note that make would complain if include was called with
959 # no arguments.
960 Po_files := $(wildcard $(DEPDIR)/*.Po)
961 ifneq (,$(Po_files))
962 include $(Po_files)
963 endif
965 # hook for clean-up
966 clean distclean: clean-deps
968 .PHONY: clean-deps
969 clean-deps:
970         @rm -rf $(DEPDIR)
972 endif # autodepend
975 ##########################################################################
977 # Native language support
979 ifeq ($(enable_nls), yes)
980 ifneq (,$(wildcard $(srcdir)/nls.mk))
982 include $(top_srcdir)/src/nls-global.mk
984 endif # nls.mk
985 endif # enable_nls
988 ##########################################################################
990 # Coverage
992 # Explanation of involved files:
993 #   foo.c       source file
994 #   foo.o       object file
995 #   foo.gcno    gcov graph (a.k.a. "notes") file, created at compile time
996 #               (by gcc -ftest-coverage)
997 #   foo.gcda    gcov data file, created when the program is run (for
998 #               programs compiled with gcc -fprofile-arcs)
999 #   foo.c.gcov  gcov output file with coverage information, created by
1000 #               gcov from foo.gcda (by "make coverage")
1001 #   foo.c.gcov.out  stdout captured when foo.c.gcov is created, mildly
1002 #               interesting
1003 #   lcov_test.info
1004 #               lcov tracefile, built from gcda files in one directory,
1005 #               later collected by "make coverage-html"
1006 #   lcov_base.info
1007 #               tracefile for zero counters for every file, so that
1008 #               even files that are not touched by tests are counted
1009 #               for the overall coverage rate
1011 ifeq ($(enable_coverage), yes)
1013 # make coverage -- text output
1015 local_gcda_files = $(wildcard *.gcda)
1017 coverage: $(local_gcda_files:.gcda=.c.gcov)
1019 %.c.gcov: %.gcda
1020         $(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
1022 # make coverage-html -- HTML output via lcov
1024 .PHONY: coverage-html
1025 coverage-html: coverage-html-stamp
1027 GENHTML_FLAGS = -q --legend
1028 GENHTML_TITLE = PostgreSQL $(VERSION)
1030 coverage-html-stamp: lcov_base.info lcov_test.info
1031         rm -rf coverage
1032         $(GENHTML) $(GENHTML_FLAGS) -o coverage --title='$(GENHTML_TITLE)' --num-spaces=4 $(if $(filter no,$(vpath_build)),--prefix='$(abs_top_srcdir)') $^
1033         touch $@
1035 LCOV += --gcov-tool $(GCOV)
1036 LCOVFLAGS = -q --no-external
1038 all_gcno_files = $(shell find . -name '*.gcno' -print)
1040 lcov_base.info: $(all_gcno_files)
1041         $(LCOV) $(LCOVFLAGS) -c -i -d . -d $(srcdir) -o $@
1043 all_gcda_files = $(shell find . -name '*.gcda' -print)
1045 lcov_test.info: $(all_gcda_files)
1046         $(LCOV) $(LCOVFLAGS) -c -d . -d $(srcdir) -o $@
1049 # hook for clean-up
1050 clean distclean: clean-coverage
1052 .PHONY: clean-coverage
1053 clean-coverage:
1054         rm -rf coverage coverage-html-stamp
1055         rm -f *.gcda *.gcno lcov*.info *.gcov .*.gcov *.gcov.out
1058 # User-callable target to reset counts between test runs
1059 coverage-clean:
1060         rm -f `find . -name '*.gcda' -print`
1062 endif # enable_coverage
1064 ##########################################################################
1066 # LLVM support
1069 ifndef COMPILE.c.bc
1070 # -Wno-ignored-attributes added so gnu_printf doesn't trigger
1071 # warnings, when the main binary is compiled with C.
1072 COMPILE.c.bc = $(CLANG) -Wno-ignored-attributes $(BITCODE_CFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
1073 endif
1075 ifndef COMPILE.cxx.bc
1076 COMPILE.cxx.bc = $(CLANG) -xc++ -Wno-ignored-attributes $(BITCODE_CXXFLAGS) $(CPPFLAGS) -flto=thin -emit-llvm -c
1077 endif
1079 %.bc : %.c
1080         $(COMPILE.c.bc) -o $@ $<
1082 %.bc : %.cpp
1083         $(COMPILE.cxx.bc) -o $@ $<
1085 # Install LLVM bitcode module (for JITing).
1087 # The arguments are:
1088 # $(1) name of the module (e.g. an extension's name or postgres for core code)
1089 # $(2) source objects, with .o suffix
1091 # The many INSTALL_DATA invocations aren't particularly fast, it'd be
1092 # good if we could coalesce them, but I didn't find a good way.
1094 # Note: blank line at end of macro is necessary to let it be used in foreach
1095 define install_llvm_module
1096 $(MKDIR_P) '$(DESTDIR)${bitcodedir}/$(1)'
1097 $(MKDIR_P) $(sort $(dir $(addprefix '$(DESTDIR)${bitcodedir}'/$(1)/, $(2))))
1098 $(foreach obj, ${2}, $(INSTALL_DATA) $(patsubst %.o,%.bc, $(obj)) '$(DESTDIR)${bitcodedir}'/$(1)/$(dir $(obj))
1100 cd '$(DESTDIR)${bitcodedir}' && $(LLVM_BINPATH)/llvm-lto -thinlto -thinlto-action=thinlink -o $(1).index.bc $(addprefix $(1)/,$(patsubst %.o,%.bc, $(2)))
1102 endef
1104 # Uninstall LLVM bitcode module.
1106 # The arguments are:
1107 # $(1) name of the module (e.g. an extension's name or postgres for core code)
1109 # This intentionally doesn't use the explicit installed file list,
1110 # seems too likely to change regularly.
1111 define uninstall_llvm_module
1112 rm -rf '$(DESTDIR)${bitcodedir}/$(1)/'
1113 rm -f '$(DESTDIR)${bitcodedir}/$(1).index.bc'
1115 endef