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 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 maintainer-check
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
43# Set top_srcdir, srcdir, and VPATH.
44ifdef PGXS
45top_srcdir = $(top_builddir)
46
47# If VPATH is set or Makefile is not in current directory we are building
48# the extension with VPATH so we set the variable here.
49ifdef VPATH
50srcdir = $(VPATH)
51else
52ifeq ($(CURDIR),$(dir $(firstword $(MAKEFILE_LIST))))
53srcdir = .
54VPATH =
55else
56srcdir = $(dir $(firstword $(MAKEFILE_LIST)))
57VPATH = $(srcdir)
58endif
59endif
60else # not PGXS
61vpath_build = @vpath_build@
62abs_top_builddir = @abs_top_builddir@
63abs_top_srcdir = @abs_top_srcdir@
64
65ifneq ($(vpath_build),yes)
66top_srcdir = $(top_builddir)
67srcdir = .
68else # vpath_build = yes
69top_srcdir = $(abs_top_srcdir)
70srcdir = $(top_srcdir)/$(subdir)
71VPATH = $(srcdir)
72endif
73endif # not PGXS
74
75vpathsearch = `for f in $(addsuffix /$(1),$(subst :, ,. $(VPATH))); do test -r $$f && echo $$f && break; done`
76
77# Saved arguments from configure
78configure_args = @configure_args@
79
80
81##########################################################################
82#
83# Installation directories
84#
85# These are set by the equivalent --xxxdir configure options.  We
86# append "postgresql" to some of them, if the string does not already
87# contain "pgsql" or "postgres", in order to avoid directory clutter.
88#
89# In a PGXS build, we cannot use the values inserted into Makefile.global
90# by configure, since the installation tree may have been relocated.
91# Instead get the path values from pg_config.
92
93ifndef PGXS
94
95# Note that prefix, exec_prefix, and datarootdir aren't defined in a PGXS build;
96# makefiles may only use the derived variables such as bindir.
97
98prefix := @prefix@
99exec_prefix := @exec_prefix@
100datarootdir := @datarootdir@
101
102bindir := @bindir@
103
104datadir := @datadir@
105ifeq "$(findstring pgsql, $(datadir))" ""
106ifeq "$(findstring postgres, $(datadir))" ""
107override datadir := $(datadir)/postgresql
108endif
109endif
110
111sysconfdir := @sysconfdir@
112ifeq "$(findstring pgsql, $(sysconfdir))" ""
113ifeq "$(findstring postgres, $(sysconfdir))" ""
114override sysconfdir := $(sysconfdir)/postgresql
115endif
116endif
117
118libdir := @libdir@
119
120pkglibdir = $(libdir)
121ifeq "$(findstring pgsql, $(pkglibdir))" ""
122ifeq "$(findstring postgres, $(pkglibdir))" ""
123override pkglibdir := $(pkglibdir)/postgresql
124endif
125endif
126
127includedir := @includedir@
128
129pkgincludedir = $(includedir)
130ifeq "$(findstring pgsql, $(pkgincludedir))" ""
131ifeq "$(findstring postgres, $(pkgincludedir))" ""
132override pkgincludedir := $(pkgincludedir)/postgresql
133endif
134endif
135
136mandir := @mandir@
137
138docdir := @docdir@
139ifeq "$(findstring pgsql, $(docdir))" ""
140ifeq "$(findstring postgres, $(docdir))" ""
141override docdir := $(docdir)/postgresql
142endif
143endif
144
145htmldir := @htmldir@
146
147localedir := @localedir@
148
149else # PGXS case
150
151# Extension makefiles should set PG_CONFIG, but older ones might not
152ifndef PG_CONFIG
153PG_CONFIG = pg_config
154endif
155
156bindir := $(shell $(PG_CONFIG) --bindir)
157datadir := $(shell $(PG_CONFIG) --sharedir)
158sysconfdir := $(shell $(PG_CONFIG) --sysconfdir)
159libdir := $(shell $(PG_CONFIG) --libdir)
160pkglibdir := $(shell $(PG_CONFIG) --pkglibdir)
161includedir := $(shell $(PG_CONFIG) --includedir)
162pkgincludedir := $(shell $(PG_CONFIG) --pkgincludedir)
163mandir := $(shell $(PG_CONFIG) --mandir)
164docdir := $(shell $(PG_CONFIG) --docdir)
165localedir := $(shell $(PG_CONFIG) --localedir)
166
167endif # PGXS
168
169# These derived path variables aren't separately configurable.
170
171includedir_server = $(pkgincludedir)/server
172includedir_internal = $(pkgincludedir)/internal
173pgxsdir = $(pkglibdir)/pgxs
174
175
176##########################################################################
177#
178# Features
179#
180# Records the choice of the various --enable-xxx and --with-xxx options.
181
182with_perl	= @with_perl@
183with_python	= @with_python@
184with_tcl	= @with_tcl@
185with_openssl	= @with_openssl@
186with_selinux	= @with_selinux@
187with_systemd	= @with_systemd@
188with_libxml	= @with_libxml@
189with_libxslt	= @with_libxslt@
190with_system_tzdata = @with_system_tzdata@
191with_uuid	= @with_uuid@
192with_zlib	= @with_zlib@
193enable_rpath	= @enable_rpath@
194enable_nls	= @enable_nls@
195enable_debug	= @enable_debug@
196enable_dtrace	= @enable_dtrace@
197enable_coverage	= @enable_coverage@
198enable_tap_tests	= @enable_tap_tests@
199enable_thread_safety	= @enable_thread_safety@
200
201python_includespec	= @python_includespec@
202python_libdir		= @python_libdir@
203python_libspec		= @python_libspec@
204python_additional_libs	= @python_additional_libs@
205python_majorversion	= @python_majorversion@
206python_version		= @python_version@
207
208krb_srvtab = @krb_srvtab@
209
210TCLSH			= @TCLSH@
211TCL_LIBS		= @TCL_LIBS@
212TCL_LIB_SPEC		= @TCL_LIB_SPEC@
213TCL_INCLUDE_SPEC	= @TCL_INCLUDE_SPEC@
214TCL_SHARED_BUILD	= @TCL_SHARED_BUILD@
215TCL_SHLIB_LD_LIBS	= @TCL_SHLIB_LD_LIBS@
216
217PTHREAD_CFLAGS		= @PTHREAD_CFLAGS@
218PTHREAD_LIBS		= @PTHREAD_LIBS@
219
220
221##########################################################################
222#
223# Programs and flags
224
225# Compilers
226
227CPP = @CPP@
228CPPFLAGS = @CPPFLAGS@
229PG_SYSROOT = @PG_SYSROOT@
230
231ifdef PGXS
232override CPPFLAGS := -I$(includedir_server) -I$(includedir_internal) $(CPPFLAGS)
233else # not PGXS
234override CPPFLAGS := -I$(top_srcdir)/src/include $(CPPFLAGS)
235ifdef VPATH
236override CPPFLAGS := -I$(top_builddir)/src/include $(CPPFLAGS)
237endif
238endif # not PGXS
239
240CC = @CC@
241GCC = @GCC@
242SUN_STUDIO_CC = @SUN_STUDIO_CC@
243CFLAGS = @CFLAGS@
244CFLAGS_SL = @CFLAGS_SL@
245CFLAGS_VECTOR = @CFLAGS_VECTOR@
246CFLAGS_SSE42 = @CFLAGS_SSE42@
247
248# Kind-of compilers
249
250BISON = @BISON@
251BISONFLAGS = @BISONFLAGS@ $(YFLAGS)
252FLEX = @FLEX@
253FLEXFLAGS = @FLEXFLAGS@ $(LFLAGS)
254DTRACE = @DTRACE@
255DTRACEFLAGS = @DTRACEFLAGS@
256ZIC = @ZIC@
257
258# Linking
259
260AR = @AR@
261DLLTOOL = @DLLTOOL@
262DLLWRAP = @DLLWRAP@
263LIBS = @LIBS@
264LDAP_LIBS_FE = @LDAP_LIBS_FE@
265LDAP_LIBS_BE = @LDAP_LIBS_BE@
266UUID_LIBS = @UUID_LIBS@
267UUID_EXTRA_OBJS = @UUID_EXTRA_OBJS@
268LD = @LD@
269with_gnu_ld = @with_gnu_ld@
270ld_R_works = @ld_R_works@
271
272# It's critical that within LDFLAGS, all -L switches pointing to build-tree
273# directories come before any -L switches pointing to external directories.
274# Otherwise it's possible for, e.g., a platform-provided copy of libpq.so
275# to get linked in place of the one we've built.  Therefore we adopt the
276# convention that the first component of LDFLAGS is an extra variable
277# LDFLAGS_INTERNAL, and -L and -l switches for PG's own libraries must be
278# put into LDFLAGS_INTERNAL, so they will appear ahead of those for external
279# libraries.
280#
281# We need LDFLAGS and LDFLAGS_INTERNAL to be "recursively expanded" variables,
282# else adjustments to, e.g., rpathdir don't work right.  So we must NOT do
283# "LDFLAGS := something" anywhere, ditto for LDFLAGS_INTERNAL.
284# These initial assignments must be "=" type, and elsewhere we must only do
285# "LDFLAGS += something" or "LDFLAGS_INTERNAL += something".
286ifdef PGXS
287  LDFLAGS_INTERNAL = -L$(libdir)
288else
289  LDFLAGS_INTERNAL = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
290endif
291LDFLAGS = $(LDFLAGS_INTERNAL) @LDFLAGS@
292
293LDFLAGS_EX = @LDFLAGS_EX@
294# LDFLAGS_SL might have already been assigned by calling makefile
295LDFLAGS_SL += @LDFLAGS_SL@
296LDREL = -r
297LDOUT = -o
298RANLIB = @RANLIB@
299WINDRES = @WINDRES@
300X = @EXEEXT@
301
302# Perl
303
304ifneq (@PERL@,)
305    # quoted to protect pathname with spaces
306    PERL		= '@PERL@'
307else
308    PERL		= $(missing) perl
309endif
310perl_archlibexp		= @perl_archlibexp@
311perl_privlibexp		= @perl_privlibexp@
312perl_includespec	= @perl_includespec@
313perl_embed_ccflags	= @perl_embed_ccflags@
314perl_embed_ldflags	= @perl_embed_ldflags@
315
316# Miscellaneous
317
318AWK	= @AWK@
319LN_S	= @LN_S@
320MSGFMT  = @MSGFMT@
321MSGFMT_FLAGS = @MSGFMT_FLAGS@
322MSGMERGE = @MSGMERGE@
323PYTHON	= @PYTHON@
324TAR	= @TAR@
325XGETTEXT = @XGETTEXT@
326
327GZIP	= gzip
328BZIP2	= bzip2
329
330# Testing
331
332check: temp-install
333
334.PHONY: temp-install
335temp-install:
336ifndef NO_TEMP_INSTALL
337ifneq ($(abs_top_builddir),)
338ifeq ($(MAKELEVEL),0)
339	rm -rf '$(abs_top_builddir)'/tmp_install
340	$(MKDIR_P) '$(abs_top_builddir)'/tmp_install/log
341	$(MAKE) -C '$(top_builddir)' DESTDIR='$(abs_top_builddir)'/tmp_install install >'$(abs_top_builddir)'/tmp_install/log/install.log 2>&1
342endif
343	$(if $(EXTRA_INSTALL),for extra in $(EXTRA_INSTALL); do $(MAKE) -C '$(top_builddir)'/$$extra DESTDIR='$(abs_top_builddir)'/tmp_install install >>'$(abs_top_builddir)'/tmp_install/log/install.log || exit; done)
344endif
345endif
346
347PROVE = @PROVE@
348# There are common routines in src/test/perl, and some test suites have
349# extra perl modules in their own directory.
350PG_PROVE_FLAGS = -I $(top_srcdir)/src/test/perl/ -I $(srcdir)
351# User-supplied prove flags such as --verbose can be provided in PROVE_FLAGS.
352PROVE_FLAGS =
353
354# prepend to path if already set, else just set it
355define add_to_path
356$(1)="$(if $($(1)),$(2):$$$(1),$(2))"
357endef
358
359# platform-specific environment variable to set shared library path
360# individual ports can override this later, this is the default name
361ld_library_path_var = LD_LIBRARY_PATH
362
363# with_temp_install_extra is for individual ports to define if they
364# need something more here. If not defined then the expansion does
365# nothing.
366with_temp_install = \
367	PATH="$(abs_top_builddir)/tmp_install$(bindir):$$PATH" \
368	$(call add_to_path,$(strip $(ld_library_path_var)),$(abs_top_builddir)/tmp_install$(libdir)) \
369	$(with_temp_install_extra)
370
371ifeq ($(enable_tap_tests),yes)
372
373ifndef PGXS
374define prove_installcheck
375rm -rf $(CURDIR)/tmp_check/log
376cd $(srcdir) && \
377   TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' \
378   top_builddir='$(CURDIR)/$(top_builddir)' \
379   PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
380   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl
381endef
382else # PGXS case
383define prove_installcheck
384rm -rf $(CURDIR)/tmp_check/log
385cd $(srcdir) && \
386   TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" PGPORT='6$(DEF_PGPORT)' \
387   top_builddir='$(top_builddir)' \
388   PG_REGRESS='$(top_builddir)/src/test/regress/pg_regress' \
389   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl
390endef
391endif # PGXS
392
393define prove_check
394rm -rf $(CURDIR)/tmp_check/log
395cd $(srcdir) && \
396   TESTDIR='$(CURDIR)' $(with_temp_install) PGPORT='6$(DEF_PGPORT)' \
397   PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' \
398   $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) t/*.pl
399endef
400
401else
402prove_installcheck = @echo "TAP tests not enabled"
403prove_check = $(prove_installcheck)
404endif
405
406# Installation.
407
408install_bin = @install_bin@
409install_sh = $(SHELL) $(top_srcdir)/config/install-sh -c
410INSTALL = $(if $(use_install_sh),$(install_sh),$(if $(install_bin),$(install_bin),$(install_sh)))
411
412INSTALL_SCRIPT_MODE	= 755
413INSTALL_DATA_MODE	= 644
414INSTALL_PROGRAM	= $(INSTALL_PROGRAM_ENV) $(INSTALL) $(INSTALL_STRIP_FLAG)
415INSTALL_SCRIPT	= $(INSTALL) -m $(INSTALL_SCRIPT_MODE)
416INSTALL_DATA	= $(INSTALL) -m $(INSTALL_DATA_MODE)
417INSTALL_STLIB	= $(INSTALL_STLIB_ENV) $(INSTALL_DATA) $(INSTALL_STRIP_FLAG)
418INSTALL_SHLIB	= $(INSTALL_SHLIB_ENV) $(INSTALL) $(INSTALL_SHLIB_OPTS) $(INSTALL_STRIP_FLAG)
419# Override in Makefile.port if necessary
420INSTALL_SHLIB_OPTS = -m 755
421
422MKDIR_P = @MKDIR_P@
423
424missing		= $(SHELL) $(top_srcdir)/config/missing
425
426STRIP		= @STRIP@
427STRIP_STATIC_LIB = @STRIP_STATIC_LIB@
428STRIP_SHARED_LIB = @STRIP_SHARED_LIB@
429
430# Documentation
431
432have_docbook	= @have_docbook@
433COLLATEINDEX	= @COLLATEINDEX@
434DBTOEPUB	= @DBTOEPUB@
435DOCBOOKSTYLE	= @DOCBOOKSTYLE@
436JADE			= @JADE@
437NSGMLS			= @NSGMLS@
438OSX				= @OSX@
439XMLLINT			= @XMLLINT@
440XSLTPROC		= @XSLTPROC@
441
442# Code coverage
443
444GCOV = @GCOV@
445LCOV = @LCOV@
446GENHTML = @GENHTML@
447
448ifeq ($(enable_coverage),yes)
449# ccache loses .gcno files
450export CCACHE_DISABLE = 1
451endif
452
453# Feature settings
454
455DEF_PGPORT = @default_port@
456WANTED_LANGUAGES = @WANTED_LANGUAGES@
457
458
459##########################################################################
460#
461# Additional platform-specific settings
462#
463
464# Name of the "template"
465PORTNAME= @PORTNAME@
466
467build_os = @build_os@
468
469host_tuple = @host@
470host_os = @host_os@
471host_cpu = @host_cpu@
472
473# Make HAVE_IPV6 available for initdb script creation
474HAVE_IPV6= @HAVE_IPV6@
475
476# This is mainly for use on FreeBSD, where we have both a.out and elf
477# systems now.  May be applicable to other systems to?
478ELF_SYSTEM= @ELF_SYS@
479
480# Backend stack size limit has to be hard-wired on Windows (it's in bytes)
481WIN32_STACK_RLIMIT=4194304
482
483# Set if we have a working win32 crashdump header
484have_win32_dbghelp = @have_win32_dbghelp@
485
486# Pull in platform-specific magic
487include $(top_builddir)/src/Makefile.port
488
489# Set up rpath if enabled.  By default it will point to our libdir,
490# but individual Makefiles can force other rpath paths if needed.
491rpathdir = $(libdir)
492
493ifeq ($(enable_rpath), yes)
494LDFLAGS += $(rpath)
495endif
496
497# Show the DLSUFFIX to build scripts (e.g. buildfarm)
498.PHONY: show_dl_suffix
499show_dl_suffix:
500	@echo $(DLSUFFIX)
501
502
503##########################################################################
504#
505# Some variables needed to find some client interfaces
506
507ifdef PGXS
508# some contribs assumes headers and libs are in the source tree...
509libpq_srcdir = $(includedir)
510libpq_builddir = $(libdir)
511else
512libpq_srcdir = $(top_srcdir)/src/interfaces/libpq
513libpq_builddir = $(top_builddir)/src/interfaces/libpq
514endif
515
516# This macro is for use by libraries linking to libpq.  (Because libpgport
517# isn't created with the same link flags as libpq, it can't be used.)
518libpq = -L$(libpq_builddir) -lpq
519
520# This macro is for use by client executables (not libraries) that use libpq.
521# We force clients to pull symbols from the non-shared libraries libpgport
522# and libpgcommon rather than pulling some libpgport symbols from libpq just
523# because libpq uses those functions too.  This makes applications less
524# dependent on changes in libpq's usage of pgport.  To do this we link to
525# pgport before libpq.  This does cause duplicate -lpgport's to appear
526# on client link lines.
527ifdef PGXS
528libpq_pgport = -L$(libdir) -lpgcommon -lpgport $(libpq)
529else
530libpq_pgport = -L$(top_builddir)/src/common -lpgcommon -L$(top_builddir)/src/port -lpgport $(libpq)
531endif
532
533# Cygwin seems to need ldap libraries to be mentioned here, too
534ifeq ($(PORTNAME),cygwin)
535libpq_pgport += $(LDAP_LIBS_FE)
536endif
537
538
539##########################################################################
540#
541# Commonly used submake targets
542
543submake-libpq:
544	$(MAKE) -C $(libpq_builddir) all
545
546submake-libpgport:
547	$(MAKE) -C $(top_builddir)/src/port all
548	$(MAKE) -C $(top_builddir)/src/common all
549
550submake-libpgfeutils:
551	$(MAKE) -C $(top_builddir)/src/port all
552	$(MAKE) -C $(top_builddir)/src/common all
553	$(MAKE) -C $(top_builddir)/src/fe_utils all
554
555submake-generated-headers:
556	$(MAKE) -C $(top_builddir)/src/backend generated-headers
557
558.PHONY: submake-libpq submake-libpgport submake-libpgfeutils submake-generated-headers
559
560
561##########################################################################
562#
563# Testing support
564
565ifneq ($(USE_MODULE_DB),)
566  PL_TESTDB = pl_regression_$(NAME)
567  # Replace this with $(or ...) if we ever require GNU make 3.81.
568  ifneq ($(MODULE_big),)
569    CONTRIB_TESTDB=contrib_regression_$(MODULE_big)
570  else
571    ifneq ($(MODULES),)
572      CONTRIB_TESTDB=contrib_regression_$(word 1,$(MODULES))
573    else
574      CONTRIB_TESTDB=contrib_regression_$(word 1,$(REGRESS))
575    endif
576  endif
577else
578  PL_TESTDB = pl_regression
579  CONTRIB_TESTDB = contrib_regression
580endif
581
582ifdef NO_LOCALE
583NOLOCALE += --no-locale
584endif
585
586# file with extra config for temp build
587TEMP_CONF =
588ifdef TEMP_CONFIG
589TEMP_CONF += --temp-config=$(TEMP_CONFIG)
590endif
591
592pg_regress_locale_flags = $(if $(ENCODING),--encoding=$(ENCODING)) $(NOLOCALE)
593
594pg_regress_check = $(with_temp_install) $(top_builddir)/src/test/regress/pg_regress --inputdir=$(srcdir) --temp-instance=./tmp_check $(TEMP_CONF) --bindir= $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
595pg_regress_installcheck = $(top_builddir)/src/test/regress/pg_regress --inputdir=$(srcdir) --bindir='$(bindir)' $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
596
597pg_regress_clean_files = results/ regression.diffs regression.out tmp_check/ log/
598
599pg_isolation_regress_check = $(with_temp_install) $(top_builddir)/src/test/isolation/pg_isolation_regress --inputdir=$(srcdir) --temp-instance=./tmp_check $(TEMP_CONF) --bindir= $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
600pg_isolation_regress_installcheck = $(top_builddir)/src/test/isolation/pg_isolation_regress --inputdir=$(srcdir) $(pg_regress_locale_flags) $(EXTRA_REGRESS_OPTS)
601
602##########################################################################
603#
604# Customization
605#
606# This includes your local customizations if Makefile.custom exists
607# in the source directory.  This file doesn't exist in the original
608# distribution so that it doesn't get overwritten when you upgrade.
609#
610# NOTE:  Makefile.custom is from the pre-Autoconf days of PostgreSQL.
611# You are liable to shoot yourself in the foot if you use it without
612# knowing exactly what you're doing.  The preferred (and more
613# reliable) method is to communicate what you want to do to the
614# configure script, and leave the makefiles alone.
615
616-include $(top_srcdir)/src/Makefile.custom
617
618ifneq ($(CUSTOM_INSTALL),)
619INSTALL= $(CUSTOM_INSTALL)
620endif
621
622ifneq ($(CUSTOM_CC),)
623  CC= $(CUSTOM_CC)
624endif
625
626ifneq ($(CUSTOM_COPT),)
627  COPT= $(CUSTOM_COPT)
628endif
629
630#
631# These variables are meant to be set in the environment of "make"
632# to add flags to whatever configure picked.  Unlike the ones above,
633# they are documented.
634#
635ifdef COPT
636   CFLAGS += $(COPT)
637   LDFLAGS += $(COPT)
638endif
639
640ifdef PROFILE
641   CFLAGS += $(PROFILE)
642   LDFLAGS += $(PROFILE)
643endif
644
645
646##########################################################################
647#
648# substitute implementations of C library routines (see src/port/)
649# note we already included -L.../src/port in LDFLAGS above
650
651LIBOBJS = @LIBOBJS@
652
653# files needed for the chosen CRC-32C implementation
654PG_CRC32C_OBJS = @PG_CRC32C_OBJS@
655
656LIBS := -lpgcommon -lpgport $(LIBS)
657
658# to make ws2_32.lib the last library
659ifeq ($(PORTNAME),win32)
660LIBS += -lws2_32
661endif
662
663# Not really standard libc functions, used by the backend.
664TAS         = @TAS@
665
666
667##########################################################################
668#
669# Global targets and rules
670
671%.c: %.l
672ifdef FLEX
673	$(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $<
674	@$(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)
675else
676	@$(missing) flex $< '$@'
677endif
678
679%.c: %.y
680	$(if $(BISON_CHECK_CMD),$(BISON_CHECK_CMD))
681ifdef BISON
682	$(BISON) $(BISONFLAGS) -o $@ $<
683else
684	@$(missing) bison $< $@
685endif
686
687%.i: %.c
688	$(CPP) $(CPPFLAGS) -o $@ $<
689
690%.gz: %
691	$(GZIP) --best -c $< >$@
692
693%.bz2: %
694	$(BZIP2) -c $< >$@
695
696# Direct builds of foo.c -> foo are disabled to avoid generating
697# *.dSYM junk on Macs.  All builds should normally go through the
698# foo.c -> foo.o -> foo steps.  This also ensures that dependency
699# tracking (see below) is used.
700%: %.c
701
702ifndef PGXS
703
704# Remake Makefile.global from Makefile.global.in if the latter
705# changed. In order to trigger this rule, the including file must
706# write `include $(top_builddir)/src/Makefile.global', not some
707# shortcut thereof.
708$(top_builddir)/src/Makefile.global: $(top_srcdir)/src/Makefile.global.in $(top_builddir)/config.status
709	cd $(top_builddir) && ./config.status src/Makefile.global
710
711# Remake pg_config.h from pg_config.h.in if the latter changed.
712# config.status will not change the timestamp on pg_config.h if it
713# doesn't change, so as to avoid recompiling the entire tree
714# unnecessarily. Therefore we make config.status update a timestamp file
715# stamp-h every time it runs, so that we don't trigger this rule every time.
716# (We do trigger the null rule for stamp-h to pg_config.h every time; so it's
717# important for that rule to be empty!)
718#
719# Of course you need to turn on dependency tracking to get any
720# dependencies on pg_config.h.
721$(top_builddir)/src/include/pg_config.h: $(top_builddir)/src/include/stamp-h ;
722
723$(top_builddir)/src/include/stamp-h: $(top_srcdir)/src/include/pg_config.h.in $(top_builddir)/config.status
724	cd $(top_builddir) && ./config.status src/include/pg_config.h
725
726# Also remake pg_config_ext.h from pg_config_ext.h.in, same logic as above.
727$(top_builddir)/src/include/pg_config_ext.h: $(top_builddir)/src/include/stamp-ext-h ;
728
729$(top_builddir)/src/include/stamp-ext-h: $(top_srcdir)/src/include/pg_config_ext.h.in $(top_builddir)/config.status
730	cd $(top_builddir) && ./config.status src/include/pg_config_ext.h
731
732# Also remake ecpg_config.h from ecpg_config.h.in if the latter changed, same
733# logic as above.
734$(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h: $(top_builddir)/src/interfaces/ecpg/include/stamp-h ;
735
736 $(top_builddir)/src/interfaces/ecpg/include/stamp-h: $(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h.in $(top_builddir)/config.status
737	cd $(top_builddir) && ./config.status src/interfaces/ecpg/include/ecpg_config.h
738
739# When configure changes, rerun configure with the same options as
740# last time. To change configure, you need to run autoconf manually.
741$(top_builddir)/config.status: $(top_srcdir)/configure
742	cd $(top_builddir) && ./config.status --recheck
743
744endif # not PGXS
745
746
747install-strip:
748# install-strip always uses install-sh, so that strip options can be
749# passed.
750	$(MAKE) use_install_sh=yes \
751	    INSTALL_PROGRAM_ENV="STRIPPROG='$(STRIP)'" \
752	    INSTALL_STLIB_ENV="STRIPPROG='$(STRIP_STATIC_LIB)'" \
753	    INSTALL_SHLIB_ENV="STRIPPROG='$(STRIP_SHARED_LIB)'" \
754	    INSTALL_STRIP_FLAG=-s \
755	    install
756
757
758##########################################################################
759#
760# Recursive make support
761# ----------------------
762# Instead of recursing through subdirectories with a for loop or
763# repeated $(MAKE) -C whatever calls, this is a little smarter: it
764# allows parallel make across directories and lets make -k and -q work
765# correctly.
766
767# We need the $(eval) function and order-only prerequisites, which are
768# available in GNU make 3.80.  That also happens to be the version
769# where the .VARIABLES variable was introduced, so this is a simple check.
770ifndef .VARIABLES
771$(error GNU make 3.80 or newer is required.  You are using version $(MAKE_VERSION))
772endif
773
774# This function is only for internal use below.  It should be called
775# using $(eval).  It will set up a target so that it recurses into
776# a given subdirectory.  Note that to avoid a nasty bug in make 3.80,
777# this function has to avoid using any complicated constructs (like
778# multiple targets on a line) and also not contain any lines that expand
779# to more than about 200 bytes.  This is why we make it apply to just one
780# subdirectory at a time, rather than to a list of subdirectories.
781# $1: target name, e.g., all
782# $2: subdir name
783# $3: target to run in subdir, usually same as $1
784define _create_recursive_target
785.PHONY: $(1)-$(2)-recurse
786$(1): $(1)-$(2)-recurse
787$(1)-$(2)-recurse: $(if $(filter check, $(3)), temp-install)
788	$$(MAKE) -C $(2) $(3)
789endef
790# Note that the use of $$ on the last line above is important; we want
791# $(MAKE) to be evaluated when the rule is run, not when the $(eval) is run
792# to create the rule.  This is necessary to get make -q working.
793
794# Call this function in a makefile that needs to recurse into subdirectories.
795# In the normal case all arguments can be defaulted.
796# $1: targets to make recursive (defaults to list of standard targets)
797# $2: list of subdirs (defaults to SUBDIRS variable)
798# $3: target to run in subdir (defaults to current element of $1)
799recurse = $(foreach target,$(if $1,$1,$(standard_targets)),$(foreach subdir,$(if $2,$2,$(SUBDIRS)),$(eval $(call _create_recursive_target,$(target),$(subdir),$(if $3,$3,$(target))))))
800
801# If a makefile's list of SUBDIRS varies depending on configuration, then
802# any subdirectories excluded from SUBDIRS should instead be added to
803# ALWAYS_SUBDIRS, and then it must call recurse_always as well as recurse.
804# This ensures that distprep, distclean, etc will apply to all subdirectories.
805# In the normal case all arguments will be defaulted.
806# $1: targets to make recursive (defaults to standard_always_targets)
807# $2: list of subdirs (defaults to ALWAYS_SUBDIRS variable)
808# $3: target to run in subdir (defaults to current element of $1)
809recurse_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))))))
810
811
812##########################################################################
813#
814# Automatic dependency generation
815# -------------------------------
816# When we configure with --enable-depend then we override the default
817# compilation rule with the magic below. While or after creating the
818# actual output file we also create a dependency list for the .c file.
819# Next time we invoke make we will have top-notch information about
820# whether this file needs to be updated. The dependency files are kept
821# in the .deps subdirectory of each directory.
822
823autodepend = @autodepend@
824
825ifeq ($(autodepend), yes)
826
827ifndef COMPILE.c
828COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
829endif
830
831DEPDIR = .deps
832
833ifeq ($(GCC), yes)
834
835# GCC allows us to create object and dependency file in one invocation.
836%.o : %.c
837	@if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
838	$(COMPILE.c) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
839
840endif # GCC
841
842# Include all the dependency files generated for the current
843# directory. Note that make would complain if include was called with
844# no arguments.
845Po_files := $(wildcard $(DEPDIR)/*.Po)
846ifneq (,$(Po_files))
847include $(Po_files)
848endif
849
850# hook for clean-up
851clean distclean maintainer-clean: clean-deps
852
853.PHONY: clean-deps
854clean-deps:
855	@rm -rf $(DEPDIR)
856
857endif # autodepend
858
859
860##########################################################################
861#
862# Native language support
863
864ifeq ($(enable_nls), yes)
865ifneq (,$(wildcard $(srcdir)/nls.mk))
866
867include $(top_srcdir)/src/nls-global.mk
868
869endif # nls.mk
870endif # enable_nls
871
872
873##########################################################################
874#
875# Coverage
876
877# Explanation of involved files:
878#   foo.c	source file
879#   foo.o	object file
880#   foo.gcno	gcov graph (a.k.a. "notes") file, created at compile time
881#		(by gcc -ftest-coverage)
882#   foo.gcda	gcov data file, created when the program is run (for
883#		programs compiled with gcc -fprofile-arcs)
884#   foo.c.gcov	gcov output file with coverage information, created by
885#		gcov from foo.gcda (by "make coverage")
886#   foo.c.gcov.out  stdout captured when foo.c.gcov is created, mildly
887#		interesting
888#   lcov.info	lcov tracefile, built from gcda files in one directory,
889#		later collected by "make coverage-html"
890
891ifeq ($(enable_coverage), yes)
892
893# There is a strange interaction between lcov and existing .gcov
894# output files.  Hence the rm command and the ordering dependency.
895
896gcda_files := $(wildcard *.gcda)
897
898lcov.info: $(gcda_files)
899	rm -f *.gcov
900	$(if $^,$(LCOV) -d . -c -o $@ $(LCOVFLAGS) --gcov-tool $(GCOV))
901
902%.c.gcov: %.gcda | lcov.info
903	$(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out
904
905coverage: $(gcda_files:.gcda=.c.gcov) lcov.info
906
907.PHONY: coverage-html
908coverage-html: coverage
909	rm -rf coverage
910	mkdir coverage
911	$(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) `find . -name lcov.info -print`
912
913
914# hook for clean-up
915clean distclean maintainer-clean: clean-coverage
916
917.PHONY: clean-coverage
918clean-coverage:
919	rm -rf coverage
920	rm -f *.gcda *.gcno lcov.info *.gcov *.gcov.out
921
922
923# User-callable target to reset counts between test runs
924coverage-clean:
925	rm -f `find . -name '*.gcda' -print`
926
927endif # enable_coverage
928