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