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