Makefile.global.in 25.4 KB
Newer Older
1
# -*-makefile-*-
2
# src/Makefile.global.in
3 4 5 6 7 8

#------------------------------------------------------------------------------
# All PostgreSQL makefiles include this file and use the variables it sets,
# which in turn are put here by the configure script. There is no need for
# users to edit this file -- if it turns out to be necessary then that's a
# bug.
9
#
10 11 12 13 14
# A makefile that includes this file needs to set the variable `subdir' to
# the relative path from the top to itself and `top_builddir' to the relative
# path from itself to the top before including this file. (The "top" is the
# parent directory of the directory this file is in.)
#------------------------------------------------------------------------------
15

16 17 18 19 20

##########################################################################
#
# Meta configuration

21
standard_targets = all install installdirs uninstall distprep clean distclean maintainer-clean coverage check installcheck maintainer-check init-po update-po
22 23
# these targets should recurse even into subdirectories not being built:
standard_always_targets = distprep clean distclean maintainer-clean
P
Peter Eisentraut 已提交
24

A
Asim R P 已提交
25
.PHONY: $(standard_targets) install-strip html man installcheck-parallel installcheck-good
26 27 28 29

# make `all' the default target
all:

30 31 32 33
# Delete target files if the command fails after it has
# started to update the file.
.DELETE_ON_ERROR:

34 35 36
# BLD_ARCH
BLD_ARCH = @BLD_ARCH@

37 38 39
# Never delete any intermediate files automatically.
.SECONDARY:

40
# PostgreSQL version number
41 42
PG_VERSION = @PG_PACKAGE_VERSION@
PG_MAJORVERSION = @PG_MAJORVERSION@
43 44

# GPDB version number
45
GP_VERSION = @GP_VERSION_SHORT@
46 47 48
GP_MAJORVERSION = @GP_MAJORVERSION@

ADDON_DIR = @ADDON_DIR@
49

50
# Support for VPATH builds
51
vpath_build = @vpath_build@
52
abs_top_srcdir = @abs_top_srcdir@
53

54
ifneq ($(vpath_build),yes)
55
top_srcdir = $(top_builddir)
56
srcdir = .
57
else # vpath_build = yes
58
top_srcdir = $(abs_top_srcdir)
59 60
srcdir = $(top_srcdir)/$(subdir)
VPATH = $(srcdir)
61
endif
62

63 64
vpathsearch = `for f in $(addsuffix /$(1),$(subst :, ,. $(VPATH))); do test -r $$f && echo $$f && break; done`

65 66 67
# Saved arguments from configure
configure_args = @configure_args@

68 69

##########################################################################
70
#
71
# Installation directories
72 73 74 75
#
# These are set by the equivalent --xxxdir configure options.  We
# append "postgresql" to some of them, if the string does not already
# contain "pgsql" or "postgres", in order to avoid directory clutter.
76 77 78 79 80 81 82
#
# In a PGXS build, we cannot use the values inserted into Makefile.global
# by configure, since the installation tree may have been relocated.
# Instead get the path values from pg_config.

ifndef PGXS

83
# Note that prefix, exec_prefix, and datarootdir aren't defined in a PGXS build;
84
# makefiles may only use the derived variables such as bindir.
85

86 87
prefix := @prefix@
exec_prefix := @exec_prefix@
88
datarootdir := @datarootdir@
M
 
Marc G. Fournier 已提交
89

90
bindir := @bindir@
91

92
datadir := @datadir@
93 94 95 96 97 98
ifeq "$(findstring pgsql, $(datadir))" ""
ifeq "$(findstring postgres, $(datadir))" ""
override datadir := $(datadir)/postgresql
endif
endif

99
sysconfdir := @sysconfdir@
100 101 102 103 104
ifeq "$(findstring pgsql, $(sysconfdir))" ""
ifeq "$(findstring postgres, $(sysconfdir))" ""
override sysconfdir := $(sysconfdir)/postgresql
endif
endif
105 106

libdir := @libdir@
107

108 109 110 111 112 113
pkglibdir = $(libdir)
ifeq "$(findstring pgsql, $(pkglibdir))" ""
ifeq "$(findstring postgres, $(pkglibdir))" ""
override pkglibdir := $(pkglibdir)/postgresql
endif
endif
114 115

includedir := @includedir@
116

117 118 119 120 121 122
pkgincludedir = $(includedir)
ifeq "$(findstring pgsql, $(pkgincludedir))" ""
ifeq "$(findstring postgres, $(pkgincludedir))" ""
override pkgincludedir := $(pkgincludedir)/postgresql
endif
endif
123

124
mandir := @mandir@
125

126
docdir := @docdir@
127 128 129 130 131
ifeq "$(findstring pgsql, $(docdir))" ""
ifeq "$(findstring postgres, $(docdir))" ""
override docdir := $(docdir)/postgresql
endif
endif
132 133

htmldir := @htmldir@
134

P
Peter Eisentraut 已提交
135
localedir := @localedir@
136

137 138
else # PGXS case

139 140
# Extension makefiles should set PG_CONFIG, but older ones might not
ifndef PG_CONFIG
141
PG_CONFIG = pg_config
142
endif
143 144 145 146 147 148 149 150 151 152 153

bindir := $(shell $(PG_CONFIG) --bindir)
datadir := $(shell $(PG_CONFIG) --sharedir)
sysconfdir := $(shell $(PG_CONFIG) --sysconfdir)
libdir := $(shell $(PG_CONFIG) --libdir)
pkglibdir := $(shell $(PG_CONFIG) --pkglibdir)
includedir := $(shell $(PG_CONFIG) --includedir)
pkgincludedir := $(shell $(PG_CONFIG) --pkgincludedir)
mandir := $(shell $(PG_CONFIG) --mandir)
docdir := $(shell $(PG_CONFIG) --docdir)
localedir := $(shell $(PG_CONFIG) --localedir)
154 155 156 157 158 159 160

endif # PGXS

# These derived path variables aren't separately configurable.

includedir_server = $(pkgincludedir)/server
includedir_internal = $(pkgincludedir)/internal
161 162
pgxsdir = $(pkglibdir)/pgxs

163

164
##########################################################################
165
#
166
# Features
167
#
168
# Records the choice of the various --enable-xxx and --with-xxx options.
169

170 171 172
with_perl	= @with_perl@
with_python	= @with_python@
with_tcl	= @with_tcl@
173
with_openssl	= @with_openssl@
174
with_ossp_uuid	= @with_ossp_uuid@
175
with_selinux	= @with_selinux@
176
with_libxml	= @with_libxml@
177
with_libxslt	= @with_libxslt@
178
with_system_tzdata = @with_system_tzdata@
179
with_zlib	= @with_zlib@
180
with_libbz2	= @with_libbz2@
181
with_apr_config	= @with_apr_config@
182 183
with_apu_config	= @with_apu_config@
with_libsigar	= @with_libsigar@
184
enable_shared	= @enable_shared@
185
enable_rpath	= @enable_rpath@
186 187 188
# NLS is not supported in Greenplum, see comment documenting
# this in configure.in
# enable_nls	= @enable_nls@
189
enable_debug	= @enable_debug@
190
enable_dtrace	= @enable_dtrace@
191
enable_coverage	= @enable_coverage@
192
enable_thread_safety	= @enable_thread_safety@
193 194
enable_largefile	= @enable_largefile@
enable_orca		= @enable_orca@
195
enable_gpfdist		= @enable_gpfdist@
196
enable_pxf			= @enable_pxf@
197
enable_gphdfs		= @enable_gphdfs@
198
enable_snmp			= @enable_snmp@
199
enable_mapreduce    = @enable_mapreduce@
A
Adam Lee 已提交
200
enable_gpcloud 	    = @enable_gpcloud@
201
enable_gpperfmon    = @enable_gpperfmon@
202

203
enable_tap_tests = @enable_tap_tests@
204

205
python_enable_shared	= @python_enable_shared@
206
python_includespec	= @python_includespec@
207
python_libdir		= @python_libdir@
208
python_libspec		= @python_libspec@
209
python_additional_libs	= @python_additional_libs@
P
Peter Eisentraut 已提交
210
python_majorversion	= @python_majorversion@
B
Bruce Momjian 已提交
211
python_version		= @python_version@
212

213 214
krb_srvtab = @krb_srvtab@

215 216 217 218
TCLSH			= @TCLSH@
TCL_LIB_FILE		= @TCL_LIB_FILE@
TCL_LIBS		= @TCL_LIBS@
TCL_LIB_SPEC		= @TCL_LIB_SPEC@
219
TCL_INCLUDE_SPEC	= @TCL_INCLUDE_SPEC@
220 221 222
TCL_SHARED_BUILD	= @TCL_SHARED_BUILD@
TCL_SHLIB_LD_LIBS	= @TCL_SHLIB_LD_LIBS@

223 224
PTHREAD_CFLAGS		= @PTHREAD_CFLAGS@
PTHREAD_LIBS		= @PTHREAD_LIBS@
B
Bruce Momjian 已提交
225

M
Marbin Tan 已提交
226
have_yaml 		= @have_yaml@
D
David Kimura 已提交
227
with_zstd 		= @with_zstd@
228

229

230
##########################################################################
231
#
232
# Programs and flags
233

234
# Compilers
235

236 237
CPP = @CPP@
CPPFLAGS = @CPPFLAGS@
238 239 240 241

ifdef PGXS
override CPPFLAGS := -I$(includedir_server) -I$(includedir_internal) $(CPPFLAGS)
else # not PGXS
242 243 244 245
override CPPFLAGS := -I$(top_srcdir)/src/include $(CPPFLAGS)
ifdef VPATH
override CPPFLAGS := -I$(top_builddir)/src/include $(CPPFLAGS)
endif
246
endif # not PGXS
247

248 249
CC = @CC@
GCC = @GCC@
250
SUN_STUDIO_CC = @SUN_STUDIO_CC@
251
CFLAGS = @CFLAGS@
252
CFLAGS_VECTOR = @CFLAGS_VECTOR@
253
CFLAGS_SSE42 = @CFLAGS_SSE42@
254

255 256 257
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@

258
# Kind-of compilers
259

260 261
BISON = @BISON@
BISONFLAGS = @BISONFLAGS@ $(YFLAGS)
262 263
FLEX = @FLEX@
FLEXFLAGS = @FLEXFLAGS@ $(LFLAGS)
264 265
DTRACE = @DTRACE@
DTRACEFLAGS = @DTRACEFLAGS@
266
ZIC = @ZIC@
267 268 269

# Linking

270 271 272
AR = @AR@
DLLTOOL = @DLLTOOL@
DLLWRAP = @DLLWRAP@
273
LIBS = @LIBS@
274 275
LDAP_LIBS_FE = @LDAP_LIBS_FE@
LDAP_LIBS_BE = @LDAP_LIBS_BE@
276
OSSP_UUID_LIBS = @OSSP_UUID_LIBS@
277 278
LD = @LD@
with_gnu_ld = @with_gnu_ld@
279
ld_R_works = @ld_R_works@
280

281 282 283 284 285
# We want -L for libpgport.a and libpgcommon.a to be first in LDFLAGS.  We
# also need LDFLAGS to be a "recursively expanded" variable, else adjustments
# to rpathdir don't work right.  So we must NOT do LDFLAGS := something,
# meaning this has to be done first and elsewhere we must only do LDFLAGS +=
# something.
286 287 288
ifdef PGXS
  LDFLAGS = -L$(libdir)
else
289
  LDFLAGS = -L$(top_builddir)/src/port -L$(top_builddir)/src/common
290 291 292 293 294 295
endif
LDFLAGS += @LDFLAGS@

LDFLAGS_EX = @LDFLAGS_EX@
# LDFLAGS_SL might have already been assigned by calling makefile
LDFLAGS_SL += @LDFLAGS_SL@
296 297 298
LDREL = -r
LDOUT = -o
RANLIB = @RANLIB@
299
WINDRES = @WINDRES@
300
X = @EXEEXT@
301

302
# Perl
303

304 305
ifneq (@PERL@,)
    # quoted to protect pathname with spaces
306
    PERL		= '@PERL@'
307 308 309
else
    PERL		= $(missing) perl
endif
310 311 312 313
perl_archlibexp		= @perl_archlibexp@
perl_privlibexp		= @perl_privlibexp@
perl_useshrplib		= @perl_useshrplib@
perl_embed_ldflags	= @perl_embed_ldflags@
314

315 316 317 318 319 320 321 322
# apr-1-config

APR_1_CONFIG		= @APR_1_CONFIG@
apr_includes		= @apr_includes@
apr_link_ld_libs	= @apr_link_ld_libs@
apr_cflags			= @apr_cflags@
apr_cppflags		= @apr_cppflags@

323 324 325 326 327
# apu-1-config
APU_1_CONFIG		= @APU_1_CONFIG@
apu_includes		= @apu_includes@
apu_link_ld_libs	= @apu_link_ld_libs@

328 329 330 331
# Miscellaneous

AWK	= @AWK@
LN_S	= @LN_S@
P
Peter Eisentraut 已提交
332 333
MSGFMT  = @MSGFMT@
MSGMERGE = @MSGMERGE@
334 335
PYTHON	= @PYTHON@
TAR	= @TAR@
P
Peter Eisentraut 已提交
336
XGETTEXT = @XGETTEXT@
337

338 339 340
GZIP	= gzip
BZIP2	= bzip2

341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
# Testing

abs_top_builddir = @abs_top_builddir@
abs_top_srcdir = @abs_top_srcdir@

check:

PROVE = @PROVE@
# There are common routines in src/test/perl, and some test suites have
# extra perl modules in their own directory.
PG_PROVE_FLAGS = -I $(top_srcdir)/src/test/perl/ -I $(srcdir)
# User-supplied prove flags such as --verbose can be provided in PROVE_FLAGS.
PROVE_FLAGS =

ifeq ($(enable_tap_tests),yes)
define prove_installcheck
rm -rf $(CURDIR)/tmp_check/log
cd $(srcdir) && TESTDIR='$(CURDIR)' PATH="$(bindir):$$PATH" top_builddir='$(CURDIR)/$(top_builddir)' PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
endef

define prove_check
rm -rf $(CURDIR)/tmp_check/log
cd $(srcdir) && TESTDIR='$(CURDIR)' $(with_temp_install) top_builddir='$(CURDIR)/$(top_builddir)' PG_REGRESS='$(CURDIR)/$(top_builddir)/src/test/regress/pg_regress' $(PROVE) $(PG_PROVE_FLAGS) $(PROVE_FLAGS) $(if $(PROVE_TESTS),$(PROVE_TESTS),t/*.pl)
endef

else
prove_installcheck = @echo "TAP tests not enabled"
prove_check = $(prove_installcheck)
endif

371 372
# Installation.

373
install_bin = @install_bin@
374
install_sh = $(SHELL) $(top_srcdir)/config/install-sh -c
375
INSTALL = $(if $(use_install_sh),$(install_sh),$(if $(install_bin),$(install_bin),$(install_sh)))
376

377 378
INSTALL_SCRIPT_MODE	= 755
INSTALL_DATA_MODE	= 644
379
INSTALL_PROGRAM	= $(INSTALL_PROGRAM_ENV) $(INSTALL) $(INSTALL_STRIP_FLAG)
380 381
INSTALL_SCRIPT	= $(INSTALL) -m $(INSTALL_SCRIPT_MODE)
INSTALL_DATA	= $(INSTALL) -m $(INSTALL_DATA_MODE)
382 383
INSTALL_STLIB	= $(INSTALL_STLIB_ENV) $(INSTALL_DATA) $(INSTALL_STRIP_FLAG)
INSTALL_SHLIB	= $(INSTALL_SHLIB_ENV) $(INSTALL) $(INSTALL_SHLIB_OPTS) $(INSTALL_STRIP_FLAG)
384 385
# Override in Makefile.port if necessary
INSTALL_SHLIB_OPTS = -m 755
386

387 388
MKDIR_P = @MKDIR_P@

389
missing		= $(SHELL) $(top_srcdir)/config/missing
390

391 392 393 394
STRIP		= @STRIP@
STRIP_STATIC_LIB = @STRIP_STATIC_LIB@
STRIP_SHARED_LIB = @STRIP_SHARED_LIB@

395 396
# Documentation

397 398 399 400 401 402 403
have_docbook	= @have_docbook@
COLLATEINDEX	= @COLLATEINDEX@
DOCBOOKSTYLE	= @DOCBOOKSTYLE@
JADE			= @JADE@
NSGMLS			= @NSGMLS@
OSX				= @OSX@
XSLTPROC		= @XSLTPROC@
404

405 406 407 408 409 410 411 412 413 414 415
# Code coverage

GCOV = @GCOV@
LCOV = @LCOV@
GENHTML = @GENHTML@

ifeq ($(enable_coverage),yes)
# ccache loses .gcno files
export CCACHE_DISABLE = 1
endif

416 417 418
# Feature settings

DEF_PGPORT = @default_port@
419 420 421
# NLS is not supported in Greenplum, see comment documenting
# this in configure.in
# WANTED_LANGUAGES = @WANTED_LANGUAGES@
422

423

424

425
##########################################################################
426 427 428 429
#
# Additional platform-specific settings
#

430
# Name of the "template"
431
PORTNAME= @PORTNAME@
432

433 434
build_os = @build_os@

435 436 437
host_tuple = @host@
host_os = @host_os@
host_cpu = @host_cpu@
438

439 440 441
# Make HAVE_IPV6 available for initdb script creation
HAVE_IPV6= @HAVE_IPV6@

T
Tom Lane 已提交
442
# The HP-UX port makefile, for one, needs access to this symbol
443 444
HAVE_POSIX_SIGNALS= @HAVE_POSIX_SIGNALS@

445 446 447 448
# This is mainly for use on FreeBSD, where we have both a.out and elf
# systems now.  May be applicable to other systems to?
ELF_SYSTEM= @ELF_SYS@

449 450 451
# Backend stack size limit has to be hard-wired on Windows (it's in bytes)
WIN32_STACK_RLIMIT=4194304

452 453 454
# Set if we have a working win32 crashdump header
have_win32_dbghelp = @have_win32_dbghelp@

455
# Pull in platform-specific magic
456
include $(top_builddir)/src/Makefile.port
457

458 459 460 461
# Set up rpath if enabled.  By default it will point to our libdir,
# but individual Makefiles can force other rpath paths if needed.
rpathdir = $(libdir)

462 463 464
ifeq ($(enable_rpath), yes)
LDFLAGS += $(rpath)
endif
465

466

467 468 469 470
##########################################################################
#
# Some variables needed to find some client interfaces

471 472 473 474 475
ifdef PGXS
# some contribs assumes headers and libs are in the source tree...
libpq_srcdir = $(includedir)
libpq_builddir = $(libdir)
else
476 477
libpq_srcdir = $(top_srcdir)/src/interfaces/libpq
libpq_builddir = $(top_builddir)/src/interfaces/libpq
478 479
endif

480 481
# This macro is for use by libraries linking to libpq.  (Because libpgport
# isn't created with the same link flags as libpq, it can't be used.)
482 483
libpq = -L$(libpq_builddir) -lpq

484
# This macro is for use by client executables (not libraries) that use libpq.
485 486 487
# We force clients to pull symbols from the non-shared libraries libpgport
# and libpgcommon rather than pulling some libpgport symbols from libpq just
# because libpq uses those functions too.  This makes applications less
488 489 490 491
# dependent on changes in libpq's usage of pgport.  To do this we link to
# pgport before libpq.  This does cause duplicate -lpgport's to appear
# on client link lines.
ifdef PGXS
492
libpq_pgport = -L$(libdir) -lpgport -lpgcommon $(libpq)
493
else
494 495
libpq_pgport = -L$(top_builddir)/src/port -lpgport \
			   -L$(top_builddir)/src/common -lpgcommon $(libpq)
496 497 498
endif


499 500 501 502 503
submake-libpq:
	$(MAKE) -C $(libpq_builddir) all

submake-libpgport:
	$(MAKE) -C $(top_builddir)/src/port all
504
	$(MAKE) -C $(top_builddir)/src/common all
505 506 507

.PHONY: submake-libpq submake-libpgport

508

509 510 511 512 513 514
##########################################################################
#
# Testing support

PL_TESTDB = pl_regression
CONTRIB_TESTDB = contrib_regression
515 516
ifneq ($(MODULE_big),)
  CONTRIB_TESTDB_MODULE = contrib_regression_$(MODULE_big)
517
else
518 519 520 521 522 523
  ifneq ($(MODULES),)
    CONTRIB_TESTDB_MODULE = contrib_regression_$(MODULES)
  else
    CONTRIB_TESTDB_MODULE = contrib_regression
  endif
endif
524

525 526 527 528 529 530 531
ifdef NO_LOCALE
NOLOCALE += --no-locale
endif

pg_regress_locale_flags = $(if $(ENCODING),--encoding=$(ENCODING)) $(NOLOCALE)

pg_regress_check = $(top_builddir)/src/test/regress/pg_regress --inputdir=$(srcdir) --temp-install=./tmp_check --top-builddir=$(top_builddir) $(pg_regress_locale_flags)
532
pg_regress_installcheck = $(top_builddir)/src/test/regress/pg_regress --inputdir=$(srcdir) --psqldir='$(PSQLDIR)' $(pg_regress_locale_flags)
533 534 535 536

pg_regress_clean_files = results/ regression.diffs regression.out tmp_check/ log/


537
##########################################################################
538
#
539
# Customization
540
#
541 542 543
# This includes your local customizations if Makefile.custom exists
# in the source directory.  This file doesn't exist in the original
# distribution so that it doesn't get overwritten when you upgrade.
544 545 546 547 548 549
#
# NOTE:  Makefile.custom is from the pre-Autoconf days of PostgreSQL.
# You are liable to shoot yourself in the foot if you use it without
# knowing exactly what you're doing.  The preferred (and more
# reliable) method is to communicate what you want to do to the
# configure script, and leave the makefiles alone.
550

551
-include $(top_srcdir)/src/Makefile.custom
552 553 554 555 556 557 558 559 560 561 562 563 564 565

ifneq ($(CUSTOM_INSTALL),)
INSTALL= $(CUSTOM_INSTALL)
endif

ifneq ($(CUSTOM_CC),)
  CC= $(CUSTOM_CC)
endif

ifneq ($(CUSTOM_COPT),)
  COPT= $(CUSTOM_COPT)
endif

ifdef COPT
566 567
   CFLAGS += $(COPT)
   LDFLAGS += $(COPT)
568 569 570
endif

ifdef PROFILE
571 572
   CFLAGS += $(PROFILE)
   LDFLAGS += $(PROFILE)
573
endif
574 575


576 577
##########################################################################
#
578
# substitute implementations of C library routines (see src/port/)
579
# note we already included -L.../src/port in LDFLAGS above
580

581
LIBOBJS = @LIBOBJS@
582

583 584 585
# files needed for the chosen CRC-32C implementation
PG_CRC32C_OBJS = @PG_CRC32C_OBJS@

586
LIBS := -lpgport -lpgcommon $(LIBS)
P
Move  
Peter Eisentraut 已提交
587

588 589
# to make ws2_32.lib the last library, and always link with shfolder,
# so SHGetFolderName isn't picked up from shell32.dll
B
Bruce Momjian 已提交
590
ifeq ($(PORTNAME),win32)
591
LIBS += -lws2_32 -lshfolder
592 593
override LDFLAGS := -L$(top_builddir)/gpAux/ext/win32/kfw-3-2-2/lib $(LDFLAGS)
override AR := /usr/bin/i686-pc-mingw32-ar
B
Bruce Momjian 已提交
594 595
endif

B
Bruce Momjian 已提交
596
# Not really standard libc functions, used by the backend.
P
Move  
Peter Eisentraut 已提交
597
TAS         = @TAS@
598

P
Peter Eisentraut 已提交
599

600 601
##########################################################################
#
602 603
# Global targets and rules

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
%.c: %.l
ifdef FLEX
	$(FLEX) $(if $(FLEX_NO_BACKUP),-b) $(FLEXFLAGS) -o'$@' $<
	@$(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)
else
	@$(missing) flex $< '$@'
endif

%.c: %.y
	$(if $(BISON_CHECK_CMD),$(BISON_CHECK_CMD))
ifdef BISON
	$(BISON) $(BISONFLAGS) -o $@ $<
else
	@$(missing) bison $< $@
endif

620 621 622
%.i: %.c
	$(CPP) $(CPPFLAGS) -o $@ $<

623
%.gz: %
624
	$(GZIP) --best -c $< >$@
625 626

%.bz2: %
627
	$(BZIP2) -c $< >$@
628

P
Peter Eisentraut 已提交
629 630 631 632 633 634
# Direct builds of foo.c -> foo are disabled to avoid generating
# *.dSYM junk on Macs.  All builds should normally go through the
# foo.c -> foo.o -> foo steps.  This also ensures that dependency
# tracking (see below) is used.
%: %.c

635 636
ifndef PGXS

637 638 639 640
# Remake Makefile.global from Makefile.global.in if the latter
# changed. In order to trigger this rule, the including file must
# write `include $(top_builddir)/src/Makefile.global', not some
# shortcut thereof.
P
Peter Eisentraut 已提交
641
$(top_builddir)/src/Makefile.global: $(top_srcdir)/src/Makefile.global.in $(top_builddir)/config.status
642
	cd $(top_builddir) && ./config.status src/Makefile.global
P
Peter Eisentraut 已提交
643

644 645
# Remake pg_config.h from pg_config.h.in if the latter changed.
# config.status will not change the timestamp on pg_config.h if it
646
# doesn't change, so as to avoid recompiling the entire tree
647
# unnecessarily. Therefore we make config.status update a timestamp file
R
Robert Haas 已提交
648 649
# stamp-h every time it runs, so that we don't trigger this rule every time.
# (We do trigger the null rule for stamp-h to pg_config.h every time; so it's
P
Peter Eisentraut 已提交
650
# important for that rule to be empty!)
651 652
#
# Of course you need to turn on dependency tracking to get any
653
# dependencies on pg_config.h.
P
Peter Eisentraut 已提交
654
$(top_builddir)/src/include/pg_config.h: $(top_builddir)/src/include/stamp-h ;
655

656
$(top_builddir)/src/include/stamp-h: $(top_srcdir)/src/include/pg_config.h.in $(top_builddir)/config.status
657
	cd $(top_builddir) && ./config.status src/include/pg_config.h
658

659 660 661 662 663 664
# Also remake pg_config_ext.h from pg_config_ext.h.in, same logic as above.
$(top_builddir)/src/include/pg_config_ext.h: $(top_builddir)/src/include/stamp-ext-h ;

$(top_builddir)/src/include/stamp-ext-h: $(top_srcdir)/src/include/pg_config_ext.h.in $(top_builddir)/config.status
	cd $(top_builddir) && ./config.status src/include/pg_config_ext.h

665
# Also remake ecpg_config.h from ecpg_config.h.in if the latter changed, same
666
# logic as above.
P
Peter Eisentraut 已提交
667
$(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h: $(top_builddir)/src/interfaces/ecpg/include/stamp-h ;
668 669

 $(top_builddir)/src/interfaces/ecpg/include/stamp-h: $(top_builddir)/src/interfaces/ecpg/include/ecpg_config.h.in $(top_builddir)/config.status
670 671
	cd $(top_builddir) && ./config.status src/interfaces/ecpg/include/ecpg_config.h

672 673
# When configure changes, rerun configure with the same options as
# last time. To change configure, you need to run autoconf manually.
P
Peter Eisentraut 已提交
674 675 676
$(top_builddir)/config.status: $(top_srcdir)/configure
	cd $(top_builddir) && ./config.status --recheck

677 678
endif # not PGXS

P
Peter Eisentraut 已提交
679

680
install-strip:
681 682 683 684
# install-strip always uses install-sh, so that strip options can be
# passed.
	$(MAKE) use_install_sh=yes \
	    INSTALL_PROGRAM_ENV="STRIPPROG='$(STRIP)'" \
685 686 687 688 689 690
	    INSTALL_STLIB_ENV="STRIPPROG='$(STRIP_STATIC_LIB)'" \
	    INSTALL_SHLIB_ENV="STRIPPROG='$(STRIP_SHARED_LIB)'" \
	    INSTALL_STRIP_FLAG=-s \
	    install


P
Peter Eisentraut 已提交
691 692 693 694 695 696 697 698 699
##########################################################################
#
# Recursive make support
# ----------------------
# Instead of recursing through subdirectories with a for loop or
# repeated $(MAKE) -C whatever calls, this is a little smarter: it
# allows parallel make across directories and lets make -k and -q work
# correctly.

700 701 702 703 704 705 706
# We need the $(eval) function and order-only prerequisites, which are
# available in GNU make 3.80.  That also happens to be the version
# where the .VARIABLES variable was introduced, so this is a simple check.
ifndef .VARIABLES
$(error GNU make 3.80 or newer is required.  You are using version $(MAKE_VERSION))
endif

P
Peter Eisentraut 已提交
707
# This function is only for internal use below.  It should be called
708 709
# using $(eval).  It will set up a target so that it recurses into
# a given subdirectory.  Note that to avoid a nasty bug in make 3.80,
710 711 712 713
# this function has to avoid using any complicated constructs (like
# multiple targets on a line) and also not contain any lines that expand
# to more than about 200 bytes.  This is why we make it apply to just one
# subdirectory at a time, rather than to a list of subdirectories.
P
Peter Eisentraut 已提交
714
# $1: target name, e.g., all
715
# $2: subdir name
P
Peter Eisentraut 已提交
716 717
# $3: target to run in subdir, usually same as $1
define _create_recursive_target
718 719 720 721
.PHONY: $(1)-$(2)-recurse
$(1): $(1)-$(2)-recurse
$(1)-$(2)-recurse:
	$$(MAKE) -C $(2) $(3)
P
Peter Eisentraut 已提交
722 723
endef
# Note that the use of $$ on the last line above is important; we want
724 725
# $(MAKE) to be evaluated when the rule is run, not when the $(eval) is run
# to create the rule.  This is necessary to get make -q working.
P
Peter Eisentraut 已提交
726

727 728
# Call this function in a makefile that needs to recurse into subdirectories.
# In the normal case all arguments can be defaulted.
P
Peter Eisentraut 已提交
729 730
# $1: targets to make recursive (defaults to list of standard targets)
# $2: list of subdirs (defaults to SUBDIRS variable)
731 732
# $3: target to run in subdir (defaults to current element of $1)
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))))))
P
Peter Eisentraut 已提交
733

734 735 736 737 738 739 740 741 742 743
# If a makefile's list of SUBDIRS varies depending on configuration, then
# any subdirectories excluded from SUBDIRS should instead be added to
# ALWAYS_SUBDIRS, and then it must call recurse_always as well as recurse.
# This ensures that distprep, distclean, etc will apply to all subdirectories.
# In the normal case all arguments will be defaulted.
# $1: targets to make recursive (defaults to standard_always_targets)
# $2: list of subdirs (defaults to ALWAYS_SUBDIRS variable)
# $3: target to run in subdir (defaults to current element of $1)
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))))))

P
Peter Eisentraut 已提交
744

745 746
##########################################################################
#
P
Peter Eisentraut 已提交
747 748 749 750 751 752 753 754 755 756 757
# Automatic dependency generation
# -------------------------------
# When we configure with --enable-depend then we override the default
# compilation rule with the magic below. While or after creating the
# actual output file we also create a dependency list for the .c file.
# Next time we invoke make we will have top-notch information about
# whether this file needs to be updated. The dependency files are kept
# in the .deps subdirectory of each directory.

autodepend = @autodepend@

758
ifeq ($(autodepend), yes)
P
Peter Eisentraut 已提交
759

760 761 762 763
ifndef COMPILE.c
COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
endif

P
Peter Eisentraut 已提交
764
DEPDIR = .deps
765

P
Peter Eisentraut 已提交
766 767 768 769
ifeq ($(GCC), yes)

# GCC allows us to create object and dependency file in one invocation.
%.o : %.c
770 771
	@if test ! -d $(DEPDIR); then mkdir -p $(DEPDIR); fi
	$(COMPILE.c) -o $@ $< -MMD -MP -MF $(DEPDIR)/$(*F).Po
P
Peter Eisentraut 已提交
772 773 774 775

endif # GCC

# Include all the dependency files generated for the current
776 777 778 779 780 781
# directory. Note that make would complain if include was called with
# no arguments.
Po_files := $(wildcard $(DEPDIR)/*.Po)
ifneq (,$(Po_files))
include $(Po_files)
endif
P
Peter Eisentraut 已提交
782 783

# hook for clean-up
784
clean distclean maintainer-clean: clean-deps
P
Peter Eisentraut 已提交
785 786 787

.PHONY: clean-deps
clean-deps:
788
	@rm -rf $(DEPDIR)
P
Peter Eisentraut 已提交
789 790

endif # autodepend
P
Peter Eisentraut 已提交
791 792 793 794 795 796 797 798 799 800 801 802 803


##########################################################################
#
# Native language support

ifeq ($(enable_nls), yes)
ifneq (,$(wildcard $(srcdir)/nls.mk))

include $(top_srcdir)/src/nls-global.mk

endif # nls.mk
endif # enable_nls
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837


##########################################################################
#
# Coverage

# Explanation of involved files:
#   foo.c	source file
#   foo.o	object file
#   foo.gcno	gcov graph (a.k.a. "notes") file, created at compile time
#		(by gcc -ftest-coverage)
#   foo.gcda	gcov data file, created when the program is run (for
#		programs compiled with gcc -fprofile-arcs)
#   foo.c.gcov	gcov output file with coverage information, created by
#		gcov from foo.gcda (by "make coverage")
#   foo.c.gcov.out  stdout captured when foo.c.gcov is created, mildly
#		interesting
#   lcov.info	lcov tracefile, built from gcda files in one directory,
#		later collected by "make coverage-html"

ifeq ($(enable_coverage), yes)

# There is a strange interaction between lcov and existing .gcov
# output files.  Hence the rm command and the ordering dependency.

gcda_files := $(wildcard *.gcda)

lcov.info: $(gcda_files)
	rm -f *.gcov
	$(if $^,$(LCOV) -d . -c -o $@ $(LCOVFLAGS))

%.c.gcov: %.gcda | lcov.info
	$(GCOV) -b -f -p -o . $(GCOVFLAGS) $*.c >$*.c.gcov.out

838 839 840 841 842 843 844 845
coverage: $(gcda_files:.gcda=.c.gcov) lcov.info

.PHONY: coverage-html
coverage-html: coverage
	rm -rf coverage
	mkdir coverage
	$(GENHTML) --show-details --legend --output-directory=coverage --title=PostgreSQL --num-spaces=4 --prefix=$(abs_top_srcdir) `find . -name lcov.info -print`

846 847 848 849 850 851

# hook for clean-up
clean distclean maintainer-clean: clean-coverage

.PHONY: clean-coverage
clean-coverage:
852
	rm -rf coverage
853 854 855 856 857 858 859 860
	rm -f *.gcda *.gcno lcov.info *.gcov *.gcov.out


# User-callable target to reset counts between test runs
coverage-clean:
	rm -f `find . -name '*.gcda' -print`

endif # enable_coverage