doc: Fix descriptions related to the handling of non-ASCII characters
[pgsql.git] / src / makefiles / pgxs.mk
blob7ba8d5bc9806ca33e04879103f6cf64a1260bb11
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)
15 # include $(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 # HEADERS -- files to install into $(includedir_server)/$MODULEDIR/$MODULE_big
42 # HEADERS_built -- as above but built first (but NOT cleaned)
43 # HEADERS_$(MODULE) -- files to install into
44 # $(includedir_server)/$MODULEDIR/$MODULE; the value of $MODULE must be
45 # listed in MODULES or MODULE_big
46 # HEADERS_built_$(MODULE) -- as above but built first (also NOT cleaned)
47 # REGRESS -- list of regression test cases (without suffix)
48 # REGRESS_OPTS -- additional switches to pass to pg_regress
49 # TAP_TESTS -- switch to enable TAP tests
50 # ISOLATION -- list of isolation test cases
51 # ISOLATION_OPTS -- additional switches to pass to pg_isolation_regress
52 # NO_INSTALL -- don't define an install target, useful for test modules
53 # that don't need their build products to be installed
54 # NO_INSTALLCHECK -- don't define an installcheck target, useful e.g. if
55 # tests require special configuration, or don't use pg_regress
56 # EXTRA_CLEAN -- extra files to remove in 'make clean'
57 # PG_CPPFLAGS -- will be prepended to CPPFLAGS
58 # PG_CFLAGS -- will be appended to CFLAGS
59 # PG_CXXFLAGS -- will be appended to CXXFLAGS
60 # PG_LDFLAGS -- will be prepended to LDFLAGS
61 # PG_LIBS -- will be added to PROGRAM link line
62 # PG_LIBS_INTERNAL -- same, for references to libraries within build tree
63 # SHLIB_LINK -- will be added to MODULE_big link line
64 # SHLIB_LINK_INTERNAL -- same, for references to libraries within build tree
65 # PG_CONFIG -- path to pg_config program for the PostgreSQL installation
66 # to build against (typically just "pg_config" to use the first one in
67 # your PATH)
69 # Better look at some of the existing uses for examples...
71 ifndef PGXS
72 ifndef NO_PGXS
73 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
74 endif
75 endif
78 ifdef PGXS
80 # External extensions must assume generated headers are available
81 NO_GENERATED_HEADERS=yes
82 # The temp-install rule won't work, either
83 NO_TEMP_INSTALL=yes
85 # We assume that we are in src/makefiles/, so top is ...
86 top_builddir := $(dir $(PGXS))../..
87 include $(top_builddir)/src/Makefile.global
89 # These might be set in Makefile.global, but if they were not found
90 # during the build of PostgreSQL, supply default values so that users
91 # of pgxs can use the variables.
92 ifeq ($(BISON),)
93 BISON = bison
94 endif
95 ifeq ($(FLEX),)
96 FLEX = flex
97 endif
99 endif # PGXS
102 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
104 # See equivalent block in Makefile.shlib
105 ifdef MODULES
106 override LDFLAGS_SL += $(CFLAGS_SL_MODULE)
107 override CFLAGS += $(CFLAGS_SL) $(CFLAGS_SL_MODULE)
108 override CXXFLAGS += $(CFLAGS_SL) $(CXXFLAGS_SL_MODULE)
109 endif
111 ifdef MODULEDIR
112 datamoduledir := $(MODULEDIR)
113 docmoduledir := $(MODULEDIR)
114 incmoduledir := $(MODULEDIR)
115 else
116 ifdef EXTENSION
117 datamoduledir := extension
118 docmoduledir := extension
119 incmoduledir := extension
120 else
121 datamoduledir := contrib
122 docmoduledir := contrib
123 incmoduledir := contrib
124 endif
125 endif
127 ifdef PG_CPPFLAGS
128 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
129 endif
130 ifdef PG_CFLAGS
131 override CFLAGS := $(CFLAGS) $(PG_CFLAGS)
132 endif
133 ifdef PG_CXXFLAGS
134 override CXXFLAGS := $(CXXFLAGS) $(PG_CXXFLAGS)
135 endif
136 ifdef PG_LDFLAGS
137 override LDFLAGS := $(PG_LDFLAGS) $(LDFLAGS)
138 endif
140 # logic for HEADERS_* stuff
142 # get list of all names used with or without built_ prefix
143 # note that use of HEADERS_built_foo will get both "foo" and "built_foo",
144 # we cope with that later when filtering this list against MODULES.
145 # If someone wants to name a module "built_foo", they can do that and it
146 # works, but if they have MODULES = foo built_foo then they will need to
147 # force building of all headers and use HEADERS_built_foo and
148 # HEADERS_built_built_foo.
149 HEADER_alldirs := $(patsubst HEADERS_%,%,$(filter HEADERS_%, $(.VARIABLES)))
150 HEADER_alldirs += $(patsubst HEADERS_built_%,%,$(filter HEADERS_built_%, $(.VARIABLES)))
152 # collect all names of built headers to use as a dependency
153 HEADER_allbuilt :=
155 ifdef MODULE_big
157 # we can unconditionally add $(MODULE_big) here, because we will strip it
158 # back out below if it turns out not to actually define any headers.
159 HEADER_dirs := $(MODULE_big)
160 HEADER_unbuilt_$(MODULE_big) = $(HEADERS)
161 HEADER_built_$(MODULE_big) = $(HEADERS_built)
162 HEADER_allbuilt += $(HEADERS_built)
163 # treat "built" as an exclusion below as well as "built_foo"
164 HEADER_xdirs := built built_$(MODULE_big)
166 else # not MODULE_big, so check MODULES
168 # HEADERS is an error in the absence of MODULE_big to provide a dir name
169 ifdef HEADERS
170 $(error HEADERS requires MODULE_big to be set)
171 endif
172 # make list of modules that have either HEADERS_foo or HEADERS_built_foo
173 HEADER_dirs := $(foreach m,$(MODULES),$(if $(filter $(m) built_$(m),$(HEADER_alldirs)),$(m)))
174 # make list of conflicting names to exclude
175 HEADER_xdirs := $(addprefix built_,$(HEADER_dirs))
177 endif # MODULE_big or MODULES
179 # HEADERS_foo requires that "foo" is in MODULES as a sanity check
180 ifneq (,$(filter-out $(HEADER_dirs) $(HEADER_xdirs),$(HEADER_alldirs)))
181 $(error $(patsubst %,HEADERS_%,$(filter-out $(HEADER_dirs) $(HEADER_xdirs),$(HEADER_alldirs))) defined with no module)
182 endif
184 # assign HEADER_unbuilt_foo and HEADER_built_foo, but make sure
185 # that "built" takes precedence in the case of conflict, by removing
186 # conflicting module names when matching the unbuilt name
187 $(foreach m,$(filter-out $(HEADER_xdirs),$(HEADER_dirs)),$(eval HEADER_unbuilt_$(m) += $$(HEADERS_$(m))))
188 $(foreach m,$(HEADER_dirs),$(eval HEADER_built_$(m) += $$(HEADERS_built_$(m))))
189 $(foreach m,$(HEADER_dirs),$(eval HEADER_allbuilt += $$(HEADERS_built_$(m))))
191 # expand out the list of headers for each dir, attaching source prefixes
192 header_file_list = $(HEADER_built_$(1)) $(addprefix $(srcdir)/,$(HEADER_unbuilt_$(1)))
193 $(foreach m,$(HEADER_dirs),$(eval HEADER_files_$(m) := $$(call header_file_list,$$(m))))
195 # note that the caller's HEADERS* vars have all been expanded now, and
196 # later changes will have no effect.
198 # remove entries in HEADER_dirs that produced an empty list of files,
199 # to ensure we don't try and install them
200 HEADER_dirs := $(foreach m,$(HEADER_dirs),$(if $(strip $(HEADER_files_$(m))),$(m)))
202 # Functions for generating install/uninstall commands; the blank lines
203 # before the "endef" are required, don't lose them
204 # $(call install_headers,dir,headers)
205 define install_headers
206 $(MKDIR_P) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
207 $(INSTALL_DATA) $(2) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
209 endef
210 # $(call uninstall_headers,dir,headers)
211 define uninstall_headers
212 rm -f $(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notdir $(2)))
214 endef
216 # end of HEADERS_* stuff
219 all: $(PROGRAM) $(DATA_built) $(HEADER_allbuilt) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
221 ifeq ($(with_llvm), yes)
222 all: $(addsuffix .bc, $(MODULES)) $(patsubst %.o,%.bc, $(OBJS))
223 endif
225 ifdef MODULE_big
226 # shared library parameters
227 NAME = $(MODULE_big)
229 include $(top_srcdir)/src/Makefile.shlib
231 all: all-lib
232 endif # MODULE_big
235 ifndef NO_INSTALL
237 install: all installdirs
238 ifneq (,$(EXTENSION))
239 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
240 endif # EXTENSION
241 ifneq (,$(DATA)$(DATA_built))
242 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
243 endif # DATA
244 ifneq (,$(DATA_TSEARCH))
245 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
246 endif # DATA_TSEARCH
247 ifdef MODULES
248 $(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
249 ifeq ($(with_llvm), yes)
250 $(foreach mod, $(MODULES), $(call install_llvm_module,$(mod),$(mod).bc))
251 endif # with_llvm
252 endif # MODULES
253 ifdef DOCS
254 ifdef docdir
255 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
256 endif # docdir
257 endif # DOCS
258 ifdef PROGRAM
259 $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
260 endif # PROGRAM
261 ifdef SCRIPTS
262 $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
263 endif # SCRIPTS
264 ifdef SCRIPTS_built
265 $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
266 endif # SCRIPTS_built
267 ifneq (,$(strip $(HEADER_dirs)))
268 $(foreach dir,$(HEADER_dirs),$(call install_headers,$(dir),$(HEADER_files_$(dir))))
269 endif # HEADERS
270 ifdef MODULE_big
271 ifeq ($(with_llvm), yes)
272 $(call install_llvm_module,$(MODULE_big),$(OBJS))
273 endif # with_llvm
275 install: install-lib
276 endif # MODULE_big
279 installdirs:
280 ifneq (,$(EXTENSION))
281 $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
282 endif
283 ifneq (,$(DATA)$(DATA_built))
284 $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
285 endif
286 ifneq (,$(DATA_TSEARCH))
287 $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
288 endif
289 ifneq (,$(MODULES))
290 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
291 endif
292 ifdef DOCS
293 ifdef docdir
294 $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
295 endif # docdir
296 endif # DOCS
297 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
298 $(MKDIR_P) '$(DESTDIR)$(bindir)'
299 endif
301 ifdef MODULE_big
302 installdirs: installdirs-lib
303 endif # MODULE_big
306 uninstall:
307 ifneq (,$(EXTENSION))
308 rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
309 endif
310 ifneq (,$(DATA)$(DATA_built))
311 rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
312 endif
313 ifneq (,$(DATA_TSEARCH))
314 rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
315 endif
316 ifdef MODULES
317 rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
318 ifeq ($(with_llvm), yes)
319 $(foreach mod, $(MODULES), $(call uninstall_llvm_module,$(mod)))
320 endif # with_llvm
321 endif # MODULES
322 ifdef DOCS
323 rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
324 endif
325 ifdef PROGRAM
326 rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
327 endif
328 ifdef SCRIPTS
329 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
330 endif
331 ifdef SCRIPTS_built
332 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
333 endif
334 ifneq (,$(strip $(HEADER_dirs)))
335 $(foreach dir,$(HEADER_dirs),$(call uninstall_headers,$(dir),$(HEADER_files_$(dir))))
336 endif # HEADERS
338 ifdef MODULE_big
339 ifeq ($(with_llvm), yes)
340 $(call uninstall_llvm_module,$(MODULE_big))
341 endif # with_llvm
343 uninstall: uninstall-lib
344 endif # MODULE_big
346 else # NO_INSTALL
348 # Need this so that temp-install builds artifacts not meant for
349 # installation (Normally, check should depend on all, but we don't do
350 # that because of parallel make risk (dbf2ec1a1c0).)
351 install: all
353 endif # NO_INSTALL
356 clean:
357 ifdef MODULES
358 rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES)) $(if $(PGFILEDESC),$(WIN32RES)) \
359 $(addsuffix .bc, $(MODULES))
360 endif
361 ifdef DATA_built
362 rm -f $(DATA_built)
363 endif
364 ifdef SCRIPTS_built
365 rm -f $(SCRIPTS_built)
366 endif
367 ifdef PROGRAM
368 rm -f $(PROGRAM)$(X)
369 endif
370 ifdef OBJS
371 rm -f $(OBJS) $(patsubst %.o,%.bc, $(OBJS))
372 endif
373 ifdef EXTRA_CLEAN
374 rm -rf $(EXTRA_CLEAN)
375 endif
376 ifdef REGRESS
377 # things created by various check targets
378 rm -rf $(pg_regress_clean_files)
379 ifeq ($(PORTNAME), win)
380 rm -f regress.def
381 endif
382 endif # REGRESS
383 ifdef TAP_TESTS
384 rm -rf tmp_check/
385 endif
386 ifdef ISOLATION
387 rm -rf output_iso/ tmp_check_iso/
388 endif
390 ifdef MODULE_big
391 clean: clean-lib
392 endif
394 distclean maintainer-clean: clean
397 ifdef REGRESS
399 REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
401 # When doing a VPATH build, must copy over the data files so that the
402 # driver script can find them. We have to use an absolute path for
403 # the targets, because otherwise make will try to locate the missing
404 # files using VPATH, and will find them in $(srcdir), but the point
405 # here is that we want to copy them from $(srcdir) to the build
406 # directory.
408 ifdef VPATH
409 abs_builddir := $(shell pwd)
410 test_files_src := $(wildcard $(srcdir)/data/*.data)
411 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
413 all: $(test_files_build)
414 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
415 $(MKDIR_P) $(dir $@)
416 ln -s $< $@
417 endif # VPATH
418 endif # REGRESS
420 .PHONY: submake
421 submake:
422 ifndef PGXS
423 $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
424 $(MAKE) -C $(top_builddir)/src/test/isolation all
425 endif
427 ifdef ISOLATION
428 ISOLATION_OPTS += --dbname=$(ISOLATION_TESTDB)
429 endif
431 # Standard rules to run regression tests including multiple test suites.
432 # Runs against an installed postmaster.
433 ifndef NO_INSTALLCHECK
434 installcheck: submake $(REGRESS_PREP)
435 ifdef REGRESS
436 $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
437 endif
438 ifdef ISOLATION
439 $(pg_isolation_regress_installcheck) $(ISOLATION_OPTS) $(ISOLATION)
440 endif
441 ifdef TAP_TESTS
442 $(prove_installcheck)
443 endif
444 endif # NO_INSTALLCHECK
446 # Runs independently of any installation
447 ifdef PGXS
448 check:
449 @echo '"$(MAKE) check" is not supported.'
450 @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
451 else
452 check: submake $(REGRESS_PREP)
453 ifdef REGRESS
454 $(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
455 endif
456 ifdef ISOLATION
457 $(pg_isolation_regress_check) $(ISOLATION_OPTS) $(ISOLATION)
458 endif
459 ifdef TAP_TESTS
460 $(prove_check)
461 endif
462 endif # PGXS
464 ifndef NO_TEMP_INSTALL
465 checkprep: EXTRA_INSTALL+=$(subdir)
466 endif
469 # STANDARD RULES
471 ifneq (,$(MODULES)$(MODULE_big))
472 %.sql: %.sql.in
473 sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
474 endif
476 ifdef PROGRAM
477 $(PROGRAM): $(OBJS)
478 $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS_INTERNAL) $(LDFLAGS) $(LDFLAGS_EX) $(PG_LIBS) $(LIBS) -o $@$(X)
479 endif