1 # PGXS: PostgreSQL extensions makefile
3 # $PostgreSQL: pgsql/src/makefiles/pgxs.mk,v 1.18 2010/01/04 16:34:11 tgl Exp $
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 objects to be built from source files with
21 # same stem (do not include suffix in this list)
22 # MODULE_big -- a shared object to build from multiple source files
23 # (list object files in OBJS)
24 # PROGRAM -- a binary program to build (list object files in OBJS)
26 # The following variables can also be set:
28 # MODULEDIR -- subdirectory into which DATA and DOCS files should be
29 # installed (if not set, default is "contrib")
30 # DATA -- random files to install into $PREFIX/share/$MODULEDIR
31 # DATA_built -- random files to install into $PREFIX/share/$MODULEDIR,
32 # which need to be built first
33 # DATA_TSEARCH -- random files to install into $PREFIX/share/tsearch_data
34 # DOCS -- random files to install under $PREFIX/doc/$MODULEDIR
35 # SCRIPTS -- script files (not binaries) to install into $PREFIX/bin
36 # SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
37 # which need to be built first
38 # REGRESS -- list of regression test cases (without suffix)
39 # EXTRA_CLEAN -- extra files to remove in 'make clean'
40 # PG_CPPFLAGS -- will be added to CPPFLAGS
41 # PG_LIBS -- will be added to PROGRAM link line
42 # SHLIB_LINK -- will be added to MODULE_big link line
43 # PG_CONFIG -- path to pg_config program for the PostgreSQL installation
44 # to build against (typically just "pg_config" to use the first one in
47 # Better look at some of the existing uses for examples...
51 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
57 # We assume that we are in src/makefiles/, so top is ...
58 top_builddir := $(dir $(PGXS))../..
59 include $(top_builddir)/src/Makefile.global
61 top_srcdir = $(top_builddir)
67 override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
70 override CFLAGS += $(CFLAGS_SL)
71 SHLIB_LINK += $(BE_DLLLIBS)
75 datamoduledir = $(MODULEDIR)
76 docmoduledir = $(MODULEDIR)
78 datamoduledir = contrib
79 docmoduledir = contrib
83 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
86 all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES))
89 # shared library parameters
92 include $(top_srcdir)/src/Makefile.shlib
98 install: all installdirs
99 ifneq (,$(DATA)$(DATA_built))
100 @for file in $(addprefix $(srcdir)/, $(DATA)) $(DATA_built); do \
101 echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/$(datamoduledir)'"; \
102 $(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/$(datamoduledir)'; \
105 ifneq (,$(DATA_TSEARCH))
106 @for file in $(addprefix $(srcdir)/, $(DATA_TSEARCH)); do \
107 echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/tsearch_data'"; \
108 $(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/tsearch_data'; \
112 @for file in $(addsuffix $(DLSUFFIX), $(MODULES)); do \
113 echo "$(INSTALL_SHLIB) $$file '$(DESTDIR)$(pkglibdir)'"; \
114 $(INSTALL_SHLIB) $$file '$(DESTDIR)$(pkglibdir)'; \
119 @for file in $(addprefix $(srcdir)/, $(DOCS)); do \
120 echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(docdir)/$(docmoduledir)'"; \
121 $(INSTALL_DATA) $$file '$(DESTDIR)$(docdir)/$(docmoduledir)'; \
126 $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
129 @for file in $(addprefix $(srcdir)/, $(SCRIPTS)); do \
130 echo "$(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'"; \
131 $(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'; \
135 @for file in $(SCRIPTS_built); do \
136 echo "$(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'"; \
137 $(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'; \
139 endif # SCRIPTS_built
147 ifneq (,$(DATA)$(DATA_built))
148 $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
150 ifneq (,$(DATA_TSEARCH))
151 $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
154 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
158 $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
161 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
162 $(MKDIR_P) '$(DESTDIR)$(bindir)'
166 installdirs: installdirs-lib
171 ifneq (,$(DATA)$(DATA_built))
172 rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
174 ifneq (,$(DATA_TSEARCH))
175 rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
178 rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
181 rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
184 rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
187 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
190 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
194 uninstall: uninstall-lib
200 rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES))
206 rm -f $(SCRIPTS_built)
218 # things created by various check targets
219 rm -rf results tmp_check log
220 rm -f regression.diffs regression.out regress.out run_check.out
221 ifeq ($(PORTNAME), win)
230 distclean maintainer-clean: clean
235 # Calling makefile can set REGRESS_OPTS, but this is the default:
237 REGRESS_OPTS = --dbname=$(CONTRIB_TESTDB)
240 # where to find psql for running the tests
243 # When doing a VPATH build, must copy over the data files so that the
244 # driver script can find them. We have to use an absolute path for
245 # the targets, because otherwise make will try to locate the missing
246 # files using VPATH, and will find them in $(srcdir), but the point
247 # here is that we want to copy them from $(srcdir) to the build
251 abs_builddir := $(shell pwd)
252 test_files_src := $(wildcard $(srcdir)/data/*.data)
253 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
255 all: $(test_files_build)
256 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
263 $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
266 # against installed postmaster
267 installcheck: submake
268 $(top_builddir)/src/test/regress/pg_regress --inputdir=$(srcdir) --psqldir=$(PSQLDIR) $(REGRESS_OPTS) $(REGRESS)
270 # in-tree test doesn't work yet (no way to install my shared library)
272 # $(top_builddir)/src/test/regress/pg_regress --temp-install \
273 # --top-builddir=$(top_builddir) $(REGRESS_OPTS) $(REGRESS)
275 @echo "'make check' is not supported."
276 @echo "Do 'make install', then 'make installcheck' instead."
283 ifneq (,$(MODULES)$(MODULE_big))
285 sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
290 $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LDFLAGS) $(LIBS) -o $@