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
)
104 # See equivalent block in Makefile.shlib
106 override LDFLAGS_SL
+= $(CFLAGS_SL_MODULE
)
107 override CFLAGS
+= $(CFLAGS_SL
) $(CFLAGS_SL_MODULE
)
108 override CXXFLAGS
+= $(CFLAGS_SL
) $(CXXFLAGS_SL_MODULE
)
112 datamoduledir
:= $(MODULEDIR
)
113 docmoduledir
:= $(MODULEDIR
)
114 incmoduledir
:= $(MODULEDIR
)
117 datamoduledir
:= extension
118 docmoduledir
:= extension
119 incmoduledir
:= extension
121 datamoduledir
:= contrib
122 docmoduledir
:= contrib
123 incmoduledir
:= contrib
128 override CPPFLAGS
:= $(PG_CPPFLAGS
) $(CPPFLAGS
)
131 override CFLAGS
:= $(CFLAGS
) $(PG_CFLAGS
)
134 override CXXFLAGS
:= $(CXXFLAGS
) $(PG_CXXFLAGS
)
137 override LDFLAGS
:= $(PG_LDFLAGS
) $(LDFLAGS
)
140 # logic for HEADERS_* stuff
142 # get list of all names used with or without built_ prefix
143 # note that use of HEADERS_built_foo will get both "foo" and "built_foo",
144 # we cope with that later when filtering this list against MODULES.
145 # If someone wants to name a module "built_foo", they can do that and it
146 # works, but if they have MODULES = foo built_foo then they will need to
147 # force building of all headers and use HEADERS_built_foo and
148 # HEADERS_built_built_foo.
149 HEADER_alldirs
:= $(patsubst HEADERS_
%,%,$(filter HEADERS_
%, $(.VARIABLES
)))
150 HEADER_alldirs
+= $(patsubst HEADERS_built_
%,%,$(filter HEADERS_built_
%, $(.VARIABLES
)))
152 # collect all names of built headers to use as a dependency
157 # we can unconditionally add $(MODULE_big) here, because we will strip it
158 # back out below if it turns out not to actually define any headers.
159 HEADER_dirs
:= $(MODULE_big
)
160 HEADER_unbuilt_
$(MODULE_big
) = $(HEADERS
)
161 HEADER_built_
$(MODULE_big
) = $(HEADERS_built
)
162 HEADER_allbuilt
+= $(HEADERS_built
)
163 # treat "built" as an exclusion below as well as "built_foo"
164 HEADER_xdirs
:= built built_
$(MODULE_big
)
166 else # not MODULE_big, so check MODULES
168 # HEADERS is an error in the absence of MODULE_big to provide a dir name
170 $(error HEADERS requires MODULE_big to be set
)
172 # make list of modules that have either HEADERS_foo or HEADERS_built_foo
173 HEADER_dirs
:= $(foreach m
,$(MODULES
),$(if
$(filter $(m
) built_
$(m
),$(HEADER_alldirs
)),$(m
)))
174 # make list of conflicting names to exclude
175 HEADER_xdirs
:= $(addprefix built_
,$(HEADER_dirs
))
177 endif # MODULE_big or MODULES
179 # HEADERS_foo requires that "foo" is in MODULES as a sanity check
180 ifneq (,$(filter-out $(HEADER_dirs
) $(HEADER_xdirs
),$(HEADER_alldirs
)))
181 $(error
$(patsubst %,HEADERS_
%,$(filter-out $(HEADER_dirs
) $(HEADER_xdirs
),$(HEADER_alldirs
))) defined with no module
)
184 # assign HEADER_unbuilt_foo and HEADER_built_foo, but make sure
185 # that "built" takes precedence in the case of conflict, by removing
186 # conflicting module names when matching the unbuilt name
187 $(foreach m
,$(filter-out $(HEADER_xdirs
),$(HEADER_dirs
)),$(eval HEADER_unbuilt_
$(m
) += $$(HEADERS_
$(m
))))
188 $(foreach m
,$(HEADER_dirs
),$(eval HEADER_built_
$(m
) += $$(HEADERS_built_
$(m
))))
189 $(foreach m
,$(HEADER_dirs
),$(eval HEADER_allbuilt
+= $$(HEADERS_built_
$(m
))))
191 # expand out the list of headers for each dir, attaching source prefixes
192 header_file_list
= $(HEADER_built_
$(1)) $(addprefix $(srcdir)/,$(HEADER_unbuilt_
$(1)))
193 $(foreach m
,$(HEADER_dirs
),$(eval HEADER_files_
$(m
) := $$(call header_file_list
,$$(m
))))
195 # note that the caller's HEADERS* vars have all been expanded now, and
196 # later changes will have no effect.
198 # remove entries in HEADER_dirs that produced an empty list of files,
199 # to ensure we don't try and install them
200 HEADER_dirs
:= $(foreach m
,$(HEADER_dirs
),$(if
$(strip $(HEADER_files_
$(m
))),$(m
)))
202 # Functions for generating install/uninstall commands; the blank lines
203 # before the "endef" are required, don't lose them
204 # $(call install_headers,dir,headers)
205 define install_headers
206 $(MKDIR_P
) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
207 $(INSTALL_DATA
) $(2) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
210 # $(call uninstall_headers,dir,headers)
211 define uninstall_headers
212 rm -f
$(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notdir $(2)))
216 # end of HEADERS_* stuff
219 all: $(PROGRAM
) $(DATA_built
) $(HEADER_allbuilt
) $(SCRIPTS_built
) $(addsuffix $(DLSUFFIX
), $(MODULES
)) $(addsuffix .control
, $(EXTENSION
))
221 ifeq ($(with_llvm
), yes
)
222 all: $(addsuffix .bc
, $(MODULES
)) $(patsubst %.o
,%.bc
, $(OBJS
))
226 # shared library parameters
229 include $(top_srcdir
)/src
/Makefile.shlib
237 install: all installdirs
238 ifneq (,$(EXTENSION
))
239 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(addsuffix .control
, $(EXTENSION
))) '$(DESTDIR)$(datadir)/extension/'
241 ifneq (,$(DATA
)$(DATA_built
))
242 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(DATA
)) $(DATA_built
) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
244 ifneq (,$(DATA_TSEARCH
))
245 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(DATA_TSEARCH
)) '$(DESTDIR)$(datadir)/tsearch_data/'
248 $(INSTALL_SHLIB
) $(addsuffix $(DLSUFFIX
), $(MODULES
)) '$(DESTDIR)$(pkglibdir)/'
249 ifeq ($(with_llvm
), yes
)
250 $(foreach mod
, $(MODULES
), $(call install_llvm_module
,$(mod
),$(mod
).bc
))
255 $(INSTALL_DATA
) $(addprefix $(srcdir)/, $(DOCS
)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
259 $(INSTALL_PROGRAM
) $(PROGRAM
)$(X
) '$(DESTDIR)$(bindir)'
262 $(INSTALL_SCRIPT
) $(addprefix $(srcdir)/, $(SCRIPTS
)) '$(DESTDIR)$(bindir)/'
265 $(INSTALL_SCRIPT
) $(SCRIPTS_built
) '$(DESTDIR)$(bindir)/'
266 endif # SCRIPTS_built
267 ifneq (,$(strip $(HEADER_dirs
)))
268 $(foreach dir,$(HEADER_dirs
),$(call install_headers
,$(dir),$(HEADER_files_
$(dir))))
271 ifeq ($(with_llvm
), yes
)
272 $(call install_llvm_module
,$(MODULE_big
),$(OBJS
))
280 ifneq (,$(EXTENSION
))
281 $(MKDIR_P
) '$(DESTDIR)$(datadir)/extension'
283 ifneq (,$(DATA
)$(DATA_built
))
284 $(MKDIR_P
) '$(DESTDIR)$(datadir)/$(datamoduledir)'
286 ifneq (,$(DATA_TSEARCH
))
287 $(MKDIR_P
) '$(DESTDIR)$(datadir)/tsearch_data'
290 $(MKDIR_P
) '$(DESTDIR)$(pkglibdir)'
294 $(MKDIR_P
) '$(DESTDIR)$(docdir)/$(docmoduledir)'
297 ifneq (,$(PROGRAM
)$(SCRIPTS
)$(SCRIPTS_built
))
298 $(MKDIR_P
) '$(DESTDIR)$(bindir)'
302 installdirs: installdirs-lib
307 ifneq (,$(EXTENSION
))
308 rm -f
$(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control
, $(EXTENSION
))))
310 ifneq (,$(DATA
)$(DATA_built
))
311 rm -f
$(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA
) $(DATA_built
)))
313 ifneq (,$(DATA_TSEARCH
))
314 rm -f
$(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH
)))
317 rm -f
$(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX
), $(MODULES
)))
318 ifeq ($(with_llvm
), yes
)
319 $(foreach mod
, $(MODULES
), $(call uninstall_llvm_module
,$(mod
)))
323 rm -f
$(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS
))
326 rm -f
'$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
329 rm -f
$(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS
))
332 rm -f
$(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built
))
334 ifneq (,$(strip $(HEADER_dirs
)))
335 $(foreach dir,$(HEADER_dirs
),$(call uninstall_headers
,$(dir),$(HEADER_files_
$(dir))))
339 ifeq ($(with_llvm
), yes
)
340 $(call uninstall_llvm_module
,$(MODULE_big
))
343 uninstall: uninstall-lib
348 # Need this so that temp-install builds artifacts not meant for
349 # installation (Normally, check should depend on all, but we don't do
350 # that because of parallel make risk (dbf2ec1a1c0).)
358 rm -f
$(addsuffix $(DLSUFFIX
), $(MODULES
)) $(addsuffix .o
, $(MODULES
)) $(if
$(PGFILEDESC
),$(WIN32RES
)) \
359 $(addsuffix .bc
, $(MODULES
))
365 rm -f
$(SCRIPTS_built
)
371 rm -f
$(OBJS
) $(patsubst %.o
,%.bc
, $(OBJS
))
374 rm -rf
$(EXTRA_CLEAN
)
377 # things created by various check targets
378 rm -rf
$(pg_regress_clean_files
)
379 ifeq ($(PORTNAME
), win
)
387 rm -rf output_iso
/ tmp_check_iso
/
399 REGRESS_OPTS
+= --dbname
=$(CONTRIB_TESTDB
)
401 # When doing a VPATH build, must copy over the data files so that the
402 # driver script can find them. We have to use an absolute path for
403 # the targets, because otherwise make will try to locate the missing
404 # files using VPATH, and will find them in $(srcdir), but the point
405 # here is that we want to copy them from $(srcdir) to the build
409 abs_builddir
:= $(shell pwd
)
410 test_files_src
:= $(wildcard $(srcdir)/data
/*.data
)
411 test_files_build
:= $(patsubst $(srcdir)/%, $(abs_builddir
)/%, $(test_files_src
))
413 all: $(test_files_build
)
414 $(test_files_build
): $(abs_builddir
)/%: $(srcdir)/%
423 $(MAKE
) -C
$(top_builddir
)/src
/test/regress pg_regress
$(X
)
424 $(MAKE
) -C
$(top_builddir
)/src
/test/isolation
all
428 ISOLATION_OPTS
+= --dbname
=$(ISOLATION_TESTDB
)
431 # Standard rules to run regression tests including multiple test suites.
432 # Runs against an installed postmaster.
433 ifndef NO_INSTALLCHECK
434 installcheck: submake
$(REGRESS_PREP
)
436 $(pg_regress_installcheck
) $(REGRESS_OPTS
) $(REGRESS
)
439 $(pg_isolation_regress_installcheck
) $(ISOLATION_OPTS
) $(ISOLATION
)
442 $(prove_installcheck
)
444 endif # NO_INSTALLCHECK
446 # Runs independently of any installation
449 @echo
'"$(MAKE) check" is not supported.'
450 @echo
'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
452 check: submake
$(REGRESS_PREP
)
454 $(pg_regress_check
) $(REGRESS_OPTS
) $(REGRESS
)
457 $(pg_isolation_regress_check
) $(ISOLATION_OPTS
) $(ISOLATION
)
464 ifndef NO_TEMP_INSTALL
465 checkprep
: EXTRA_INSTALL
+=$(subdir
)
471 ifneq (,$(MODULES
)$(MODULE_big
))
473 sed
's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
478 $(CC
) $(CFLAGS
) $(OBJS
) $(PG_LIBS_INTERNAL
) $(LDFLAGS
) $(LDFLAGS_EX
) $(PG_LIBS
) $(LIBS
) -o
$@
$(X
)