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 # REGRESS -- list of regression test cases (without suffix)
42 # REGRESS_OPTS -- additional switches to pass to pg_regress
43 # EXTRA_CLEAN -- extra files to remove in 'make clean'
44 # PG_CPPFLAGS -- will be added to CPPFLAGS
45 # PG_LIBS -- will be added to PROGRAM link line
46 # SHLIB_LINK -- will be added to MODULE_big link line
47 # PG_CONFIG -- path to pg_config program for the PostgreSQL installation
48 # to build against (typically just "pg_config" to use the first one in
51 # Better look at some of the existing uses for examples...
55 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
61 # We assume that we are in src/makefiles/, so top is ...
62 top_builddir := $(dir $(PGXS))../..
63 include $(top_builddir)/src/Makefile.global
65 top_srcdir = $(top_builddir)
66 # If VPATH is set or Makefile is not in current directory we are building
67 # the extension with VPATH so we set the variable here.
71 ifeq ($(CURDIR),$(dir $(firstword $(MAKEFILE_LIST))))
75 srcdir = $(dir $(firstword $(MAKEFILE_LIST)))
80 # These might be set in Makefile.global, but if they were not found
81 # during the build of PostgreSQL, supply default values so that users
82 # of pgxs can use the variables.
92 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
95 override CFLAGS += $(CFLAGS_SL)
99 datamoduledir := $(MODULEDIR)
100 docmoduledir := $(MODULEDIR)
103 datamoduledir := extension
104 docmoduledir := extension
106 datamoduledir := contrib
107 docmoduledir := contrib
112 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
115 all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
118 # shared library parameters
121 include $(top_srcdir)/src/Makefile.shlib
127 install: all installdirs
128 ifneq (,$(EXTENSION))
129 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
131 ifneq (,$(DATA)$(DATA_built))
132 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
134 ifneq (,$(DATA_TSEARCH))
135 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
138 $(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
142 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
146 $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
149 $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
152 $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
153 endif # SCRIPTS_built
161 ifneq (,$(EXTENSION))
162 $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
164 ifneq (,$(DATA)$(DATA_built))
165 $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
167 ifneq (,$(DATA_TSEARCH))
168 $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
171 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
175 $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
178 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
179 $(MKDIR_P) '$(DESTDIR)$(bindir)'
183 installdirs: installdirs-lib
188 ifneq (,$(EXTENSION))
189 rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
191 ifneq (,$(DATA)$(DATA_built))
192 rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
194 ifneq (,$(DATA_TSEARCH))
195 rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
198 rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
201 rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
204 rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
207 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
210 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
214 uninstall: uninstall-lib
220 rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES)) $(WIN32RES)
226 rm -f $(SCRIPTS_built)
235 rm -rf $(EXTRA_CLEAN)
238 # things created by various check targets
239 rm -rf $(pg_regress_clean_files)
240 ifeq ($(PORTNAME), win)
249 distclean maintainer-clean: clean
254 # Select database to use for running the tests
255 ifneq ($(USE_MODULE_DB),)
256 REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE)
258 REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
261 # where to find psql for running the tests
264 # When doing a VPATH build, must copy over the data files so that the
265 # driver script can find them. We have to use an absolute path for
266 # the targets, because otherwise make will try to locate the missing
267 # files using VPATH, and will find them in $(srcdir), but the point
268 # here is that we want to copy them from $(srcdir) to the build
272 abs_builddir := $(shell pwd)
273 test_files_src := $(wildcard $(srcdir)/data/*.data)
274 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
276 all: $(test_files_build)
277 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
285 $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
288 # against installed postmaster
289 installcheck: submake $(REGRESS_PREP)
290 $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
294 @echo '"$(MAKE) check" is not supported.'
295 @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
297 check: all submake $(REGRESS_PREP)
298 $(pg_regress_check) --extra-install=$(subdir) $(REGRESS_OPTS) $(REGRESS)
305 ifneq (,$(MODULES)$(MODULE_big))
307 sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
312 $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)