1 # PGXS: PostgreSQL extensions makefile
3 # src/makefiles/pgxs.mk
5 # This file contains generic rules to build many kinds of simple
6 # extension modules. You only need to set a few variables and include
7 # this file, the rest will be done here.
9 # Use the following layout for your Makefile:
11 # [variable assignments, see below]
13 # PG_CONFIG = pg_config
14 # PGXS := $(shell $(PG_CONFIG) --pgxs)
17 # [custom rules, rarely necessary]
19 # Set one of these three variables to specify what is built:
21 # MODULES -- list of shared-library objects to be built from source files
22 # with same stem (do not include library suffixes in this list)
23 # MODULE_big -- a shared library to build from multiple source files
24 # (list object files in OBJS)
25 # PROGRAM -- an executable program to build (list object files in OBJS)
27 # The following variables can also be set:
29 # EXTENSION -- name of extension (there must be a $EXTENSION.control file)
30 # MODULEDIR -- subdirectory of $PREFIX/share into which DATA and DOCS files
31 # should be installed (if not set, default is "extension" if EXTENSION
32 # is set, or "contrib" if not)
33 # DATA -- random files to install into $PREFIX/share/$MODULEDIR
34 # DATA_built -- random files to install into $PREFIX/share/$MODULEDIR,
35 # which need to be built first
36 # DATA_TSEARCH -- random files to install into $PREFIX/share/tsearch_data
37 # DOCS -- random files to install under $PREFIX/doc/$MODULEDIR
38 # SCRIPTS -- script files (not binaries) to install into $PREFIX/bin
39 # SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
40 # which need to be built first
41 # HEADERS -- files to install into $(includedir_server)/$MODULEDIR/$MODULE_big
42 # HEADERS_built -- as above but built first (but NOT cleaned)
43 # HEADERS_$(MODULE) -- files to install into
44 # $(includedir_server)/$MODULEDIR/$MODULE; the value of $MODULE must be
45 # listed in MODULES or MODULE_big
46 # HEADERS_built_$(MODULE) -- as above but built first (also NOT cleaned)
47 # REGRESS -- list of regression test cases (without suffix)
48 # REGRESS_OPTS -- additional switches to pass to pg_regress
49 # TAP_TESTS -- switch to enable TAP tests
50 # ISOLATION -- list of isolation test cases
51 # ISOLATION_OPTS -- additional switches to pass to pg_isolation_regress
52 # NO_INSTALL -- don't define an install target, useful for test modules
53 # that don't need their build products to be installed
54 # NO_INSTALLCHECK -- don't define an installcheck target, useful e.g. if
55 # tests require special configuration, or don't use pg_regress
56 # EXTRA_CLEAN -- extra files to remove in 'make clean'
57 # PG_CPPFLAGS -- will be prepended to CPPFLAGS
58 # PG_CFLAGS -- will be appended to CFLAGS
59 # PG_CXXFLAGS -- will be appended to CXXFLAGS
60 # PG_LDFLAGS -- will be prepended to LDFLAGS
61 # PG_LIBS -- will be added to PROGRAM link line
62 # PG_LIBS_INTERNAL -- same, for references to libraries within build tree
63 # SHLIB_LINK -- will be added to MODULE_big link line
64 # SHLIB_LINK_INTERNAL -- same, for references to libraries within build tree
65 # PG_CONFIG -- path to pg_config program for the PostgreSQL installation
66 # to build against (typically just "pg_config" to use the first one in
69 # Better look at some of the existing uses for examples...
73 $(error pgxs error
: makefile variable PGXS or NO_PGXS must be set
)
80 # External extensions must assume generated headers are available
81 NO_GENERATED_HEADERS
=yes
82 # The temp-install rule won't work, either
85 # We assume that we are in src/makefiles/, so top is ...
86 top_builddir
:= $(dir $(PGXS
))..
/..
87 include $(top_builddir
)/src
/Makefile.global
89 # These might be set in Makefile.global, but if they were not found
90 # during the build of PostgreSQL, supply default values so that users
91 # of pgxs can use the variables.
102 override CPPFLAGS
:= -I.
-I
$(srcdir) $(CPPFLAGS
)
105 override CFLAGS
+= $(CFLAGS_SL
)
109 datamoduledir
:= $(MODULEDIR
)
110 docmoduledir
:= $(MODULEDIR
)
111 incmoduledir
:= $(MODULEDIR
)
114 datamoduledir
:= extension
115 docmoduledir
:= extension
116 incmoduledir
:= extension
118 datamoduledir
:= contrib
119 docmoduledir
:= contrib
120 incmoduledir
:= contrib
125 override CPPFLAGS
:= $(PG_CPPFLAGS
) $(CPPFLAGS
)
128 override CFLAGS
:= $(CFLAGS
) $(PG_CFLAGS
)
131 override CXXFLAGS
:= $(CXXFLAGS
) $(PG_CXXFLAGS
)
134 override LDFLAGS
:= $(PG_LDFLAGS
) $(LDFLAGS
)
137 # logic for HEADERS_* stuff
139 # get list of all names used with or without built_ prefix
140 # note that use of HEADERS_built_foo will get both "foo" and "built_foo",
141 # we cope with that later when filtering this list against MODULES.
142 # If someone wants to name a module "built_foo", they can do that and it
143 # works, but if they have MODULES = foo built_foo then they will need to
144 # force building of all headers and use HEADERS_built_foo and
145 # HEADERS_built_built_foo.
146 HEADER_alldirs
:= $(patsubst HEADERS_
%,%,$(filter HEADERS_
%, $(.VARIABLES
)))
147 HEADER_alldirs
+= $(patsubst HEADERS_built_
%,%,$(filter HEADERS_built_
%, $(.VARIABLES
)))
149 # collect all names of built headers to use as a dependency
154 # we can unconditionally add $(MODULE_big) here, because we will strip it
155 # back out below if it turns out not to actually define any headers.
156 HEADER_dirs
:= $(MODULE_big
)
157 HEADER_unbuilt_
$(MODULE_big
) = $(HEADERS
)
158 HEADER_built_
$(MODULE_big
) = $(HEADERS_built
)
159 HEADER_allbuilt
+= $(HEADERS_built
)
160 # treat "built" as an exclusion below as well as "built_foo"
161 HEADER_xdirs
:= built built_
$(MODULE_big
)
163 else # not MODULE_big, so check MODULES
165 # HEADERS is an error in the absence of MODULE_big to provide a dir name
167 $(error HEADERS requires MODULE_big to be set
)
169 # make list of modules that have either HEADERS_foo or HEADERS_built_foo
170 HEADER_dirs
:= $(foreach m
,$(MODULES
),$(if
$(filter $(m
) built_
$(m
),$(HEADER_alldirs
)),$(m
)))
171 # make list of conflicting names to exclude
172 HEADER_xdirs
:= $(addprefix built_
,$(HEADER_dirs
))
174 endif # MODULE_big or MODULES
176 # HEADERS_foo requires that "foo" is in MODULES as a sanity check
177 ifneq (,$(filter-out $(HEADER_dirs
) $(HEADER_xdirs
),$(HEADER_alldirs
)))
178 $(error
$(patsubst %,HEADERS_
%,$(filter-out $(HEADER_dirs
) $(HEADER_xdirs
),$(HEADER_alldirs
))) defined with no module
)
181 # assign HEADER_unbuilt_foo and HEADER_built_foo, but make sure
182 # that "built" takes precedence in the case of conflict, by removing
183 # conflicting module names when matching the unbuilt name
184 $(foreach m
,$(filter-out $(HEADER_xdirs
),$(HEADER_dirs
)),$(eval HEADER_unbuilt_
$(m
) += $$(HEADERS_
$(m
))))
185 $(foreach m
,$(HEADER_dirs
),$(eval HEADER_built_
$(m
) += $$(HEADERS_built_
$(m
))))
186 $(foreach m
,$(HEADER_dirs
),$(eval HEADER_allbuilt
+= $$(HEADERS_built_
$(m
))))
188 # expand out the list of headers for each dir, attaching source prefixes
189 header_file_list
= $(HEADER_built_
$(1)) $(addprefix $(srcdir)/,$(HEADER_unbuilt_
$(1)))
190 $(foreach m
,$(HEADER_dirs
),$(eval HEADER_files_
$(m
) := $$(call header_file_list
,$$(m
))))
192 # note that the caller's HEADERS* vars have all been expanded now, and
193 # later changes will have no effect.
195 # remove entries in HEADER_dirs that produced an empty list of files,
196 # to ensure we don't try and install them
197 HEADER_dirs
:= $(foreach m
,$(HEADER_dirs
),$(if
$(strip $(HEADER_files_
$(m
))),$(m
)))
199 # Functions for generating install/uninstall commands; the blank lines
200 # before the "endef" are required, don't lose them
201 # $(call install_headers,dir,headers)
202 define install_headers
203 $(MKDIR_P
) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
204 $(INSTALL_DATA
) $(2) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
207 # $(call uninstall_headers,dir,headers)
208 define uninstall_headers
209 rm -f
$(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notdir $(2)))
213 # end of HEADERS_* stuff
216 all: $(PROGRAM
) $(DATA_built
) $(HEADER_allbuilt
) $(SCRIPTS_built
) $(addsuffix $(DLSUFFIX
), $(MODULES
)) $(addsuffix .control
, $(EXTENSION
))
218 ifeq ($(with_llvm
), yes
)
219 all: $(addsuffix .bc
, $(MODULES
)) $(patsubst %.o
,%.bc
, $(OBJS
))
223 # shared library parameters
226 include $(top_srcdir
)/src
/Makefile.shlib
234 install: all installdirs
235 ifneq (,$(EXTENSION
))
236 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(addsuffix .control
, $(EXTENSION
))) '$(DESTDIR)$(datadir)/extension/'
238 ifneq (,$(DATA
)$(DATA_built
))
239 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(DATA
)) $(DATA_built
) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
241 ifneq (,$(DATA_TSEARCH
))
242 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(DATA_TSEARCH
)) '$(DESTDIR)$(datadir)/tsearch_data/'
245 $(INSTALL_SHLIB
) $(addsuffix $(DLSUFFIX
), $(MODULES
)) '$(DESTDIR)$(pkglibdir)/'
246 ifeq ($(with_llvm
), yes
)
247 $(foreach mod
, $(MODULES
), $(call install_llvm_module
,$(mod
),$(mod
).bc
))
252 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(DOCS
)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
256 $(INSTALL_PROGRAM
) $(PROGRAM
)$(X
) '$(DESTDIR)$(bindir)'
259 $(INSTALL_SCRIPT
) $(addprefix $(srcdir)/, $(SCRIPTS
)) '$(DESTDIR)$(bindir)/'
262 $(INSTALL_SCRIPT
) $(SCRIPTS_built
) '$(DESTDIR)$(bindir)/'
263 endif # SCRIPTS_built
264 ifneq (,$(strip $(HEADER_dirs
)))
265 $(foreach dir,$(HEADER_dirs
),$(call install_headers
,$(dir),$(HEADER_files_
$(dir))))
268 ifeq ($(with_llvm
), yes
)
269 $(call install_llvm_module
,$(MODULE_big
),$(OBJS
))
277 ifneq (,$(EXTENSION
))
278 $(MKDIR_P
) '$(DESTDIR)$(datadir)/extension'
280 ifneq (,$(DATA
)$(DATA_built
))
281 $(MKDIR_P
) '$(DESTDIR)$(datadir)/$(datamoduledir)'
283 ifneq (,$(DATA_TSEARCH
))
284 $(MKDIR_P
) '$(DESTDIR)$(datadir)/tsearch_data'
287 $(MKDIR_P
) '$(DESTDIR)$(pkglibdir)'
291 $(MKDIR_P
) '$(DESTDIR)$(docdir)/$(docmoduledir)'
294 ifneq (,$(PROGRAM
)$(SCRIPTS
)$(SCRIPTS_built
))
295 $(MKDIR_P
) '$(DESTDIR)$(bindir)'
299 installdirs: installdirs-lib
304 ifneq (,$(EXTENSION
))
305 rm -f
$(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control
, $(EXTENSION
))))
307 ifneq (,$(DATA
)$(DATA_built
))
308 rm -f
$(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA
) $(DATA_built
)))
310 ifneq (,$(DATA_TSEARCH
))
311 rm -f
$(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH
)))
314 rm -f
$(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX
), $(MODULES
)))
315 ifeq ($(with_llvm
), yes
)
316 $(foreach mod
, $(MODULES
), $(call uninstall_llvm_module
,$(mod
)))
320 rm -f
$(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS
))
323 rm -f
'$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
326 rm -f
$(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS
))
329 rm -f
$(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built
))
331 ifneq (,$(strip $(HEADER_dirs
)))
332 $(foreach dir,$(HEADER_dirs
),$(call uninstall_headers
,$(dir),$(HEADER_files_
$(dir))))
336 ifeq ($(with_llvm
), yes
)
337 $(call uninstall_llvm_module
,$(MODULE_big
))
340 uninstall: uninstall-lib
345 # Need this so that temp-install builds artifacts not meant for
346 # installation (Normally, check should depend on all, but we don't do
347 # that because of parallel make risk (dbf2ec1a1c0).)
355 rm -f
$(addsuffix $(DLSUFFIX
), $(MODULES
)) $(addsuffix .o
, $(MODULES
)) $(if
$(PGFILEDESC
),$(WIN32RES
)) \
356 $(addsuffix .bc
, $(MODULES
))
362 rm -f
$(SCRIPTS_built
)
368 rm -f
$(OBJS
) $(patsubst %.o
,%.bc
, $(OBJS
))
371 rm -rf
$(EXTRA_CLEAN
)
374 # things created by various check targets
375 rm -rf
$(pg_regress_clean_files
)
376 ifeq ($(PORTNAME
), win
)
384 rm -rf output_iso
/ tmp_check_iso
/
391 distclean maintainer-clean
: clean
396 REGRESS_OPTS
+= --dbname
=$(CONTRIB_TESTDB
)
398 # When doing a VPATH build, must copy over the data files so that the
399 # driver script can find them. We have to use an absolute path for
400 # the targets, because otherwise make will try to locate the missing
401 # files using VPATH, and will find them in $(srcdir), but the point
402 # here is that we want to copy them from $(srcdir) to the build
406 abs_builddir
:= $(shell pwd
)
407 test_files_src
:= $(wildcard $(srcdir)/data
/*.data
)
408 test_files_build
:= $(patsubst $(srcdir)/%, $(abs_builddir
)/%, $(test_files_src
))
410 all: $(test_files_build
)
411 $(test_files_build
): $(abs_builddir
)/%: $(srcdir)/%
420 $(MAKE
) -C
$(top_builddir
)/src
/test/regress pg_regress
$(X
)
421 $(MAKE
) -C
$(top_builddir
)/src
/test/isolation
all
425 ISOLATION_OPTS
+= --dbname
=$(ISOLATION_TESTDB
)
428 # Standard rules to run regression tests including multiple test suites.
429 # Runs against an installed postmaster.
430 ifndef NO_INSTALLCHECK
431 installcheck: submake
$(REGRESS_PREP
)
433 $(pg_regress_installcheck
) $(REGRESS_OPTS
) $(REGRESS
)
436 $(pg_isolation_regress_installcheck
) $(ISOLATION_OPTS
) $(ISOLATION
)
439 $(prove_installcheck
)
441 endif # NO_INSTALLCHECK
443 # Runs independently of any installation
446 @echo
'"$(MAKE) check" is not supported.'
447 @echo
'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
449 check: submake
$(REGRESS_PREP
)
451 $(pg_regress_check
) $(REGRESS_OPTS
) $(REGRESS
)
454 $(pg_isolation_regress_check
) $(ISOLATION_OPTS
) $(ISOLATION
)
461 ifndef NO_TEMP_INSTALL
462 checkprep
: EXTRA_INSTALL
+=$(subdir
)
468 ifneq (,$(MODULES
)$(MODULE_big
))
470 sed
's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
475 $(CC
) $(CFLAGS
) $(OBJS
) $(PG_LIBS_INTERNAL
) $(LDFLAGS
) $(LDFLAGS_EX
) $(PG_LIBS
) $(LIBS
) -o
$@
$(X
)