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]
12 # [custom rules, rarely necessary]
14 # PG_CONFIG = pg_config
15 # PGXS := $(shell $(PG_CONFIG) --pgxs)
18 # Set one of these three variables to specify what is built:
20 # MODULES -- list of shared-library objects to be built from source files
21 # with same stem (do not include library suffixes in this list)
22 # MODULE_big -- a shared library to build from multiple source files
23 # (list object files in OBJS)
24 # PROGRAM -- an executable program to build (list object files in OBJS)
26 # The following variables can also be set:
28 # EXTENSION -- name of extension (there must be a $EXTENSION.control file)
29 # MODULEDIR -- subdirectory of $PREFIX/share into which DATA and DOCS files
30 # should be installed (if not set, default is "extension" if EXTENSION
31 # is set, or "contrib" if not)
32 # DATA -- random files to install into $PREFIX/share/$MODULEDIR
33 # DATA_built -- random files to install into $PREFIX/share/$MODULEDIR,
34 # which need to be built first
35 # DATA_TSEARCH -- random files to install into $PREFIX/share/tsearch_data
36 # DOCS -- random files to install under $PREFIX/doc/$MODULEDIR
37 # SCRIPTS -- script files (not binaries) to install into $PREFIX/bin
38 # SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
39 # which need to be built first
40 # REGRESS -- list of regression test cases (without suffix)
41 # REGRESS_OPTS -- additional switches to pass to pg_regress
42 # EXTRA_CLEAN -- extra files to remove in 'make clean'
43 # PG_CPPFLAGS -- will be added to CPPFLAGS
44 # PG_LIBS -- will be added to PROGRAM link line
45 # SHLIB_LINK -- will be added to MODULE_big link line
46 # PG_CONFIG -- path to pg_config program for the PostgreSQL installation
47 # to build against (typically just "pg_config" to use the first one in
50 # Better look at some of the existing uses for examples...
54 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
60 # We assume that we are in src/makefiles/, so top is ...
61 top_builddir := $(dir $(PGXS))../..
62 include $(top_builddir)/src/Makefile.global
64 top_srcdir = $(top_builddir)
68 # These might be set in Makefile.global, but if they were not found
69 # during the build of PostgreSQL, supply default values so that users
70 # of pgxs can use the variables.
80 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
83 override CFLAGS += $(CFLAGS_SL)
87 datamoduledir := $(MODULEDIR)
88 docmoduledir := $(MODULEDIR)
91 datamoduledir := extension
92 docmoduledir := extension
94 datamoduledir := contrib
95 docmoduledir := contrib
100 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
103 all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
106 # shared library parameters
109 include $(top_srcdir)/src/Makefile.shlib
115 install: all installdirs
116 ifneq (,$(EXTENSION))
117 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
119 ifneq (,$(DATA)$(DATA_built))
120 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
122 ifneq (,$(DATA_TSEARCH))
123 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
126 $(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
130 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
134 $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
137 $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
140 $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
141 endif # SCRIPTS_built
149 ifneq (,$(EXTENSION))
150 $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
152 ifneq (,$(DATA)$(DATA_built))
153 $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
155 ifneq (,$(DATA_TSEARCH))
156 $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
159 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
163 $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
166 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
167 $(MKDIR_P) '$(DESTDIR)$(bindir)'
171 installdirs: installdirs-lib
176 ifneq (,$(EXTENSION))
177 rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
179 ifneq (,$(DATA)$(DATA_built))
180 rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
182 ifneq (,$(DATA_TSEARCH))
183 rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
186 rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
189 rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
192 rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
195 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
198 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
202 uninstall: uninstall-lib
208 rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES))
214 rm -f $(SCRIPTS_built)
223 rm -rf $(EXTRA_CLEAN)
226 # things created by various check targets
227 rm -rf $(pg_regress_clean_files)
228 ifeq ($(PORTNAME), win)
237 distclean maintainer-clean: clean
242 # Select database to use for running the tests
244 REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE)
246 REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
249 # where to find psql for running the tests
252 # When doing a VPATH build, must copy over the data files so that the
253 # driver script can find them. We have to use an absolute path for
254 # the targets, because otherwise make will try to locate the missing
255 # files using VPATH, and will find them in $(srcdir), but the point
256 # here is that we want to copy them from $(srcdir) to the build
260 abs_builddir := $(shell pwd)
261 test_files_src := $(wildcard $(srcdir)/data/*.data)
262 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
264 all: $(test_files_build)
265 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
272 $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
275 # against installed postmaster
276 installcheck: submake $(REGRESS_PREP)
277 $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
281 @echo '"$(MAKE) check" is not supported.'
282 @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
284 check: all submake $(REGRESS_PREP)
285 $(pg_regress_check) --extra-install=$(subdir) $(REGRESS_OPTS) $(REGRESS)
292 ifneq (,$(MODULES)$(MODULE_big))
294 sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
299 $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@