When calling unsupported "make check" with a pgxs module, return a nonzero
[PostgreSQL.git] / src / makefiles / pgxs.mk
blob2796d6a90b21fe72073b1733d2ed9113076fe0fa
1 # PGXS: PostgreSQL extensions makefile
3 # $PostgreSQL$
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)
16 # include $(PGXS)
18 # The following variables can be set:
20 # MODULES -- list of shared objects to be build from source file with
21 # same stem (do not include suffix in this list)
22 # DATA -- random files to install into $PREFIX/share/contrib
23 # DATA_built -- random files to install into $PREFIX/share/contrib,
24 # which need to be built first
25 # DATA_TSEARCH -- random files to install into $PREFIX/share/tsearch_data
26 # DOCS -- random files to install under $PREFIX/doc/contrib
27 # SCRIPTS -- script files (not binaries) to install into $PREFIX/bin
28 # SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
29 # which need to be built first
30 # REGRESS -- list of regression test cases (without suffix)
32 # or at most one of these two:
34 # PROGRAM -- a binary program to build (list objects files in OBJS)
35 # MODULE_big -- a shared object to build (list object files in OBJS)
37 # The following can also be set:
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
45 # your PATH)
47 # Better look at some of the existing uses for examples...
49 ifndef PGXS
50 ifndef NO_PGXS
51 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
52 endif
53 endif
56 ifdef PGXS
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)
62 srcdir = .
63 VPATH =
64 endif
67 override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
69 ifdef MODULES
70 override CFLAGS += $(CFLAGS_SL)
71 SHLIB_LINK += $(BE_DLLLIBS)
72 endif
74 ifdef PG_CPPFLAGS
75 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
76 endif
78 all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES))
80 ifdef MODULE_big
81 # shared library parameters
82 NAME = $(MODULE_big)
84 include $(top_srcdir)/src/Makefile.shlib
86 all: all-lib
87 endif # MODULE_big
90 install: all installdirs
91 ifneq (,$(DATA)$(DATA_built))
92 @for file in $(addprefix $(srcdir)/, $(DATA)) $(DATA_built); do \
93 echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/contrib'"; \
94 $(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/contrib'; \
95 done
96 endif # DATA
97 ifneq (,$(DATA_TSEARCH))
98 @for file in $(addprefix $(srcdir)/, $(DATA_TSEARCH)); do \
99 echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/tsearch_data'"; \
100 $(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/tsearch_data'; \
101 done
102 endif # DATA_TSEARCH
103 ifdef MODULES
104 @for file in $(addsuffix $(DLSUFFIX), $(MODULES)); do \
105 echo "$(INSTALL_SHLIB) $$file '$(DESTDIR)$(pkglibdir)'"; \
106 $(INSTALL_SHLIB) $$file '$(DESTDIR)$(pkglibdir)'; \
107 done
108 endif # MODULES
109 ifdef DOCS
110 ifdef docdir
111 @for file in $(addprefix $(srcdir)/, $(DOCS)); do \
112 echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(docdir)/contrib'"; \
113 $(INSTALL_DATA) $$file '$(DESTDIR)$(docdir)/contrib'; \
114 done
115 endif # docdir
116 endif # DOCS
117 ifdef PROGRAM
118 $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
119 endif # PROGRAM
120 ifdef SCRIPTS
121 @for file in $(addprefix $(srcdir)/, $(SCRIPTS)); do \
122 echo "$(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'"; \
123 $(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'; \
124 done
125 endif # SCRIPTS
126 ifdef SCRIPTS_built
127 @for file in $(SCRIPTS_built); do \
128 echo "$(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'"; \
129 $(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'; \
130 done
131 endif # SCRIPTS_built
133 ifdef MODULE_big
134 install: install-lib
135 endif # MODULE_big
138 installdirs:
139 ifneq (,$(DATA)$(DATA_built))
140 $(mkinstalldirs) '$(DESTDIR)$(datadir)/contrib'
141 endif
142 ifneq (,$(DATA_TSEARCH))
143 $(mkinstalldirs) '$(DESTDIR)$(datadir)/tsearch_data'
144 endif
145 ifneq (,$(MODULES))
146 $(mkinstalldirs) '$(DESTDIR)$(pkglibdir)'
147 endif
148 ifdef DOCS
149 ifdef docdir
150 $(mkinstalldirs) '$(DESTDIR)$(docdir)/contrib'
151 endif # docdir
152 endif # DOCS
153 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
154 $(mkinstalldirs) '$(DESTDIR)$(bindir)'
155 endif
157 ifdef MODULE_big
158 installdirs: installdirs-lib
159 endif # MODULE_big
162 uninstall:
163 ifneq (,$(DATA)$(DATA_built))
164 rm -f $(addprefix '$(DESTDIR)$(datadir)'/contrib/, $(notdir $(DATA) $(DATA_built)))
165 endif
166 ifneq (,$(DATA_TSEARCH))
167 rm -f $(addprefix '$(DESTDIR)$(datadir)'/tsearch_data/, $(notdir $(DATA_TSEARCH)))
168 endif
169 ifdef MODULES
170 rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
171 endif
172 ifdef DOCS
173 rm -f $(addprefix '$(DESTDIR)$(docdir)'/contrib/, $(DOCS))
174 endif
175 ifdef PROGRAM
176 rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
177 endif
178 ifdef SCRIPTS
179 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
180 endif
181 ifdef SCRIPTS_built
182 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
183 endif
185 ifdef MODULE_big
186 uninstall: uninstall-lib
187 endif # MODULE_big
190 clean:
191 ifdef MODULES
192 rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES))
193 endif
194 ifdef DATA_built
195 rm -f $(DATA_built)
196 endif
197 ifdef SCRIPTS_built
198 rm -f $(SCRIPTS_built)
199 endif
200 ifdef PROGRAM
201 rm -f $(PROGRAM)$(X)
202 endif
203 ifdef OBJS
204 rm -f $(OBJS)
205 endif
206 ifdef EXTRA_CLEAN
207 rm -f $(EXTRA_CLEAN)
208 endif
209 ifdef REGRESS
210 # things created by various check targets
211 rm -rf results tmp_check log
212 rm -f regression.diffs regression.out regress.out run_check.out
213 ifeq ($(PORTNAME), win)
214 rm -f regress.def
215 endif
216 endif # REGRESS
218 ifdef MODULE_big
219 clean: clean-lib
220 endif
222 distclean maintainer-clean: clean
225 ifdef REGRESS
227 # Calling makefile can set REGRESS_OPTS, but this is the default:
228 ifndef REGRESS_OPTS
229 REGRESS_OPTS = --dbname=$(CONTRIB_TESTDB)
230 endif
232 # where to find psql for running the tests
233 PSQLDIR = $(bindir)
235 # When doing a VPATH build, must copy over the data files so that the
236 # driver script can find them. We have to use an absolute path for
237 # the targets, because otherwise make will try to locate the missing
238 # files using VPATH, and will find them in $(srcdir), but the point
239 # here is that we want to copy them from $(srcdir) to the build
240 # directory.
242 ifdef VPATH
243 abs_builddir := $(shell pwd)
244 test_files_src := $(wildcard $(srcdir)/data/*.data)
245 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
247 all: $(test_files_build)
248 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
249 ln -s $< $@
250 endif # VPATH
252 .PHONY: submake
253 submake:
254 ifndef PGXS
255 $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
256 endif
258 # against installed postmaster
259 installcheck: submake
260 $(top_builddir)/src/test/regress/pg_regress --inputdir=$(srcdir) --psqldir=$(PSQLDIR) $(REGRESS_OPTS) $(REGRESS)
262 # in-tree test doesn't work yet (no way to install my shared library)
263 #check: all submake
264 # $(top_builddir)/src/test/regress/pg_regress --temp-install \
265 # --top-builddir=$(top_builddir) $(REGRESS_OPTS) $(REGRESS)
266 check:
267 @echo "'make check' is not supported."
268 @echo "Do 'make install', then 'make installcheck' instead."
269 @exit 1
270 endif # REGRESS
273 # STANDARD RULES
275 ifneq (,$(MODULES)$(MODULE_big))
276 %.sql: %.sql.in
277 sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
278 endif
280 ifdef PROGRAM
281 $(PROGRAM): $(OBJS)
282 $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LDFLAGS) $(LIBS) -o $@
283 endif