]> granicus.if.org Git - postgresql/blob - src/makefiles/pgxs.mk
bfae02f90ce773c02ccd06a7a306893ad1e42e14
[postgresql] / src / makefiles / pgxs.mk
1 # PGXS: PostgreSQL extensions makefile
2
3 # src/makefiles/pgxs.mk
4
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.
8 #
9 # Use the following layout for your Makefile:
10 #
11 #   [variable assignments, see below]
12 #
13 #   PG_CONFIG = pg_config
14 #   PGXS := $(shell $(PG_CONFIG) --pgxs)
15 #   include $(PGXS)
16 #
17 #   [custom rules, rarely necessary]
18 #
19 # Set one of these three variables to specify what is built:
20 #
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)
26 #
27 # The following variables can also be set:
28 #
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 #   NO_INSTALLCHECK -- don't define an installcheck target, useful e.g. if
44 #     tests require special configuration, or don't use pg_regress
45 #   EXTRA_CLEAN -- extra files to remove in 'make clean'
46 #   PG_CPPFLAGS -- will be added to CPPFLAGS
47 #   PG_LIBS -- will be added to PROGRAM link line
48 #   PG_LIBS_INTERNAL -- same, for references to libraries within build tree
49 #   SHLIB_LINK -- will be added to MODULE_big link line
50 #   SHLIB_LINK_INTERNAL -- same, for references to libraries within build tree
51 #   PG_CONFIG -- path to pg_config program for the PostgreSQL installation
52 #     to build against (typically just "pg_config" to use the first one in
53 #     your PATH)
54 #
55 # Better look at some of the existing uses for examples...
56
57 ifndef PGXS
58 ifndef NO_PGXS
59 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
60 endif
61 endif
62
63
64 ifdef PGXS
65
66 # External extensions must assume generated headers are available
67 NO_GENERATED_HEADERS=yes
68 # The temp-install rule won't work, either
69 NO_TEMP_INSTALL=yes
70
71 # We assume that we are in src/makefiles/, so top is ...
72 top_builddir := $(dir $(PGXS))../..
73 include $(top_builddir)/src/Makefile.global
74
75 # These might be set in Makefile.global, but if they were not found
76 # during the build of PostgreSQL, supply default values so that users
77 # of pgxs can use the variables.
78 ifeq ($(BISON),)
79 BISON = bison
80 endif
81 ifeq ($(FLEX),)
82 FLEX = flex
83 endif
84
85 endif # PGXS
86
87
88 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
89
90 ifdef MODULES
91 override CFLAGS += $(CFLAGS_SL)
92 endif
93
94 ifdef MODULEDIR
95 datamoduledir := $(MODULEDIR)
96 docmoduledir := $(MODULEDIR)
97 else
98 ifdef EXTENSION
99 datamoduledir := extension
100 docmoduledir := extension
101 else
102 datamoduledir := contrib
103 docmoduledir := contrib
104 endif
105 endif
106
107 ifdef PG_CPPFLAGS
108 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
109 endif
110
111 all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
112
113 ifeq ($(with_llvm), yes)
114 all: $(addsuffix .bc, $(MODULES)) $(patsubst %.o,%.bc, $(OBJS))
115 endif
116
117 ifdef MODULE_big
118 # shared library parameters
119 NAME = $(MODULE_big)
120
121 include $(top_srcdir)/src/Makefile.shlib
122
123 all: all-lib
124 endif # MODULE_big
125
126
127 install: all installdirs
128 ifneq (,$(EXTENSION))
129         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
130 endif # EXTENSION
131 ifneq (,$(DATA)$(DATA_built))
132         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
133 endif # DATA
134 ifneq (,$(DATA_TSEARCH))
135         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
136 endif # DATA_TSEARCH
137 ifdef MODULES
138         $(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
139 ifeq ($(with_llvm), yes)
140         $(foreach mod, $(MODULES), $(call install_llvm_module,$(mod),$(mod).bc))
141 endif # with_llvm
142 endif # MODULES
143 ifdef DOCS
144 ifdef docdir
145         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
146 endif # docdir
147 endif # DOCS
148 ifdef PROGRAM
149         $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
150 endif # PROGRAM
151 ifdef SCRIPTS
152         $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
153 endif # SCRIPTS
154 ifdef SCRIPTS_built
155         $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
156 endif # SCRIPTS_built
157 ifdef MODULE_big
158 ifeq ($(with_llvm), yes)
159         $(call install_llvm_module,$(MODULE_big),$(OBJS))
160 endif # with_llvm
161
162 install: install-lib
163 endif # MODULE_big
164
165
166 installdirs:
167 ifneq (,$(EXTENSION))
168         $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
169 endif
170 ifneq (,$(DATA)$(DATA_built))
171         $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
172 endif
173 ifneq (,$(DATA_TSEARCH))
174         $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
175 endif
176 ifneq (,$(MODULES))
177         $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
178 endif
179 ifdef DOCS
180 ifdef docdir
181         $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
182 endif # docdir
183 endif # DOCS
184 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
185         $(MKDIR_P) '$(DESTDIR)$(bindir)'
186 endif
187
188 ifdef MODULE_big
189 installdirs: installdirs-lib
190 endif # MODULE_big
191
192
193 uninstall:
194 ifneq (,$(EXTENSION))
195         rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
196 endif
197 ifneq (,$(DATA)$(DATA_built))
198         rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
199 endif
200 ifneq (,$(DATA_TSEARCH))
201         rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
202 endif
203 ifdef MODULES
204         rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
205 ifeq ($(with_llvm), yes)
206         $(foreach mod, $(MODULES), $(call uninstall_llvm_module,$(mod)))
207 endif # with_llvm
208 endif # MODULES
209 ifdef DOCS
210         rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
211 endif
212 ifdef PROGRAM
213         rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
214 endif
215 ifdef SCRIPTS
216         rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
217 endif
218 ifdef SCRIPTS_built
219         rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
220 endif
221
222 ifdef MODULE_big
223 ifeq ($(with_llvm), yes)
224         $(call uninstall_llvm_module,$(MODULE_big))
225 endif # with_llvm
226
227 uninstall: uninstall-lib
228 endif # MODULE_big
229
230
231 clean:
232 ifdef MODULES
233         rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES)) $(if $(PGFILEDESC),$(WIN32RES)) \
234             $(addsuffix .bc, $(MODULES))
235 endif
236 ifdef DATA_built
237         rm -f $(DATA_built)
238 endif
239 ifdef SCRIPTS_built
240         rm -f $(SCRIPTS_built)
241 endif
242 ifdef PROGRAM
243         rm -f $(PROGRAM)$(X)
244 endif
245 ifdef OBJS
246         rm -f $(OBJS) $(patsubst %.o,%.bc, $(OBJS))
247 endif
248 ifdef EXTRA_CLEAN
249         rm -rf $(EXTRA_CLEAN)
250 endif
251 ifdef REGRESS
252 # things created by various check targets
253         rm -rf $(pg_regress_clean_files)
254 ifeq ($(PORTNAME), win)
255         rm -f regress.def
256 endif
257 endif # REGRESS
258
259 ifdef MODULE_big
260 clean: clean-lib
261 endif
262
263 distclean maintainer-clean: clean
264
265
266 ifdef REGRESS
267
268 # Select database to use for running the tests
269 ifneq ($(USE_MODULE_DB),)
270   REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE)
271 else
272   REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
273 endif
274
275 # When doing a VPATH build, must copy over the data files so that the
276 # driver script can find them.  We have to use an absolute path for
277 # the targets, because otherwise make will try to locate the missing
278 # files using VPATH, and will find them in $(srcdir), but the point
279 # here is that we want to copy them from $(srcdir) to the build
280 # directory.
281
282 ifdef VPATH
283 abs_builddir := $(shell pwd)
284 test_files_src := $(wildcard $(srcdir)/data/*.data)
285 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
286
287 all: $(test_files_build)
288 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
289         $(MKDIR_P) $(dir $@)
290         ln -s $< $@
291 endif # VPATH
292
293 .PHONY: submake
294 submake:
295 ifndef PGXS
296         $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
297 endif
298
299 # against installed postmaster
300 ifndef NO_INSTALLCHECK
301 installcheck: submake $(REGRESS_PREP)
302         $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
303 endif
304
305 ifdef PGXS
306 check:
307         @echo '"$(MAKE) check" is not supported.'
308         @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
309 else
310 check: submake $(REGRESS_PREP)
311         $(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
312
313 temp-install: EXTRA_INSTALL+=$(subdir)
314 endif
315 endif # REGRESS
316
317
318 # STANDARD RULES
319
320 ifneq (,$(MODULES)$(MODULE_big))
321 %.sql: %.sql.in
322         sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
323 endif
324
325 ifdef PROGRAM
326 $(PROGRAM): $(OBJS)
327         $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS_INTERNAL) $(LDFLAGS) $(LDFLAGS_EX) $(PG_LIBS) $(LIBS) -o $@$(X)
328 endif