Consistently use "superuser" instead of "super user"
[pgsql.git] / src / makefiles / pgxs.mk
blob0f71fa293d09902d1427a7092660c22203ffb0b4
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 ifdef MODULES
105 override CFLAGS += $(CFLAGS_SL)
106 endif
108 ifdef MODULEDIR
109 datamoduledir := $(MODULEDIR)
110 docmoduledir := $(MODULEDIR)
111 incmoduledir := $(MODULEDIR)
112 else
113 ifdef EXTENSION
114 datamoduledir := extension
115 docmoduledir := extension
116 incmoduledir := extension
117 else
118 datamoduledir := contrib
119 docmoduledir := contrib
120 incmoduledir := contrib
121 endif
122 endif
124 ifdef PG_CPPFLAGS
125 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
126 endif
127 ifdef PG_CFLAGS
128 override CFLAGS := $(CFLAGS) $(PG_CFLAGS)
129 endif
130 ifdef PG_CXXFLAGS
131 override CXXFLAGS := $(CXXFLAGS) $(PG_CXXFLAGS)
132 endif
133 ifdef PG_LDFLAGS
134 override LDFLAGS := $(PG_LDFLAGS) $(LDFLAGS)
135 endif
137 # logic for HEADERS_* stuff
139 # get list of all names used with or without built_ prefix
140 # note that use of HEADERS_built_foo will get both "foo" and "built_foo",
141 # we cope with that later when filtering this list against MODULES.
142 # If someone wants to name a module "built_foo", they can do that and it
143 # works, but if they have MODULES = foo built_foo then they will need to
144 # force building of all headers and use HEADERS_built_foo and
145 # HEADERS_built_built_foo.
146 HEADER_alldirs := $(patsubst HEADERS_%,%,$(filter HEADERS_%, $(.VARIABLES)))
147 HEADER_alldirs += $(patsubst HEADERS_built_%,%,$(filter HEADERS_built_%, $(.VARIABLES)))
149 # collect all names of built headers to use as a dependency
150 HEADER_allbuilt :=
152 ifdef MODULE_big
154 # we can unconditionally add $(MODULE_big) here, because we will strip it
155 # back out below if it turns out not to actually define any headers.
156 HEADER_dirs := $(MODULE_big)
157 HEADER_unbuilt_$(MODULE_big) = $(HEADERS)
158 HEADER_built_$(MODULE_big) = $(HEADERS_built)
159 HEADER_allbuilt += $(HEADERS_built)
160 # treat "built" as an exclusion below as well as "built_foo"
161 HEADER_xdirs := built built_$(MODULE_big)
163 else # not MODULE_big, so check MODULES
165 # HEADERS is an error in the absence of MODULE_big to provide a dir name
166 ifdef HEADERS
167 $(error HEADERS requires MODULE_big to be set)
168 endif
169 # make list of modules that have either HEADERS_foo or HEADERS_built_foo
170 HEADER_dirs := $(foreach m,$(MODULES),$(if $(filter $(m) built_$(m),$(HEADER_alldirs)),$(m)))
171 # make list of conflicting names to exclude
172 HEADER_xdirs := $(addprefix built_,$(HEADER_dirs))
174 endif # MODULE_big or MODULES
176 # HEADERS_foo requires that "foo" is in MODULES as a sanity check
177 ifneq (,$(filter-out $(HEADER_dirs) $(HEADER_xdirs),$(HEADER_alldirs)))
178 $(error $(patsubst %,HEADERS_%,$(filter-out $(HEADER_dirs) $(HEADER_xdirs),$(HEADER_alldirs))) defined with no module)
179 endif
181 # assign HEADER_unbuilt_foo and HEADER_built_foo, but make sure
182 # that "built" takes precedence in the case of conflict, by removing
183 # conflicting module names when matching the unbuilt name
184 $(foreach m,$(filter-out $(HEADER_xdirs),$(HEADER_dirs)),$(eval HEADER_unbuilt_$(m) += $$(HEADERS_$(m))))
185 $(foreach m,$(HEADER_dirs),$(eval HEADER_built_$(m) += $$(HEADERS_built_$(m))))
186 $(foreach m,$(HEADER_dirs),$(eval HEADER_allbuilt += $$(HEADERS_built_$(m))))
188 # expand out the list of headers for each dir, attaching source prefixes
189 header_file_list = $(HEADER_built_$(1)) $(addprefix $(srcdir)/,$(HEADER_unbuilt_$(1)))
190 $(foreach m,$(HEADER_dirs),$(eval HEADER_files_$(m) := $$(call header_file_list,$$(m))))
192 # note that the caller's HEADERS* vars have all been expanded now, and
193 # later changes will have no effect.
195 # remove entries in HEADER_dirs that produced an empty list of files,
196 # to ensure we don't try and install them
197 HEADER_dirs := $(foreach m,$(HEADER_dirs),$(if $(strip $(HEADER_files_$(m))),$(m)))
199 # Functions for generating install/uninstall commands; the blank lines
200 # before the "endef" are required, don't lose them
201 # $(call install_headers,dir,headers)
202 define install_headers
203 $(MKDIR_P) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
204 $(INSTALL_DATA) $(2) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
206 endef
207 # $(call uninstall_headers,dir,headers)
208 define uninstall_headers
209 rm -f $(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notdir $(2)))
211 endef
213 # end of HEADERS_* stuff
216 all: $(PROGRAM) $(DATA_built) $(HEADER_allbuilt) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
218 ifeq ($(with_llvm), yes)
219 all: $(addsuffix .bc, $(MODULES)) $(patsubst %.o,%.bc, $(OBJS))
220 endif
222 ifdef MODULE_big
223 # shared library parameters
224 NAME = $(MODULE_big)
226 include $(top_srcdir)/src/Makefile.shlib
228 all: all-lib
229 endif # MODULE_big
232 ifndef NO_INSTALL
234 install: all installdirs
235 ifneq (,$(EXTENSION))
236 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
237 endif # EXTENSION
238 ifneq (,$(DATA)$(DATA_built))
239 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
240 endif # DATA
241 ifneq (,$(DATA_TSEARCH))
242 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
243 endif # DATA_TSEARCH
244 ifdef MODULES
245 $(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
246 ifeq ($(with_llvm), yes)
247 $(foreach mod, $(MODULES), $(call install_llvm_module,$(mod),$(mod).bc))
248 endif # with_llvm
249 endif # MODULES
250 ifdef DOCS
251 ifdef docdir
252 $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
253 endif # docdir
254 endif # DOCS
255 ifdef PROGRAM
256 $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
257 endif # PROGRAM
258 ifdef SCRIPTS
259 $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
260 endif # SCRIPTS
261 ifdef SCRIPTS_built
262 $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
263 endif # SCRIPTS_built
264 ifneq (,$(strip $(HEADER_dirs)))
265 $(foreach dir,$(HEADER_dirs),$(call install_headers,$(dir),$(HEADER_files_$(dir))))
266 endif # HEADERS
267 ifdef MODULE_big
268 ifeq ($(with_llvm), yes)
269 $(call install_llvm_module,$(MODULE_big),$(OBJS))
270 endif # with_llvm
272 install: install-lib
273 endif # MODULE_big
276 installdirs:
277 ifneq (,$(EXTENSION))
278 $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
279 endif
280 ifneq (,$(DATA)$(DATA_built))
281 $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
282 endif
283 ifneq (,$(DATA_TSEARCH))
284 $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
285 endif
286 ifneq (,$(MODULES))
287 $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
288 endif
289 ifdef DOCS
290 ifdef docdir
291 $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
292 endif # docdir
293 endif # DOCS
294 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
295 $(MKDIR_P) '$(DESTDIR)$(bindir)'
296 endif
298 ifdef MODULE_big
299 installdirs: installdirs-lib
300 endif # MODULE_big
303 uninstall:
304 ifneq (,$(EXTENSION))
305 rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
306 endif
307 ifneq (,$(DATA)$(DATA_built))
308 rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
309 endif
310 ifneq (,$(DATA_TSEARCH))
311 rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
312 endif
313 ifdef MODULES
314 rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
315 ifeq ($(with_llvm), yes)
316 $(foreach mod, $(MODULES), $(call uninstall_llvm_module,$(mod)))
317 endif # with_llvm
318 endif # MODULES
319 ifdef DOCS
320 rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
321 endif
322 ifdef PROGRAM
323 rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
324 endif
325 ifdef SCRIPTS
326 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
327 endif
328 ifdef SCRIPTS_built
329 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
330 endif
331 ifneq (,$(strip $(HEADER_dirs)))
332 $(foreach dir,$(HEADER_dirs),$(call uninstall_headers,$(dir),$(HEADER_files_$(dir))))
333 endif # HEADERS
335 ifdef MODULE_big
336 ifeq ($(with_llvm), yes)
337 $(call uninstall_llvm_module,$(MODULE_big))
338 endif # with_llvm
340 uninstall: uninstall-lib
341 endif # MODULE_big
343 else # NO_INSTALL
345 # Need this so that temp-install builds artifacts not meant for
346 # installation (Normally, check should depend on all, but we don't do
347 # that because of parallel make risk (dbf2ec1a1c0).)
348 install: all
350 endif # NO_INSTALL
353 clean:
354 ifdef MODULES
355 rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES)) $(if $(PGFILEDESC),$(WIN32RES)) \
356 $(addsuffix .bc, $(MODULES))
357 endif
358 ifdef DATA_built
359 rm -f $(DATA_built)
360 endif
361 ifdef SCRIPTS_built
362 rm -f $(SCRIPTS_built)
363 endif
364 ifdef PROGRAM
365 rm -f $(PROGRAM)$(X)
366 endif
367 ifdef OBJS
368 rm -f $(OBJS) $(patsubst %.o,%.bc, $(OBJS))
369 endif
370 ifdef EXTRA_CLEAN
371 rm -rf $(EXTRA_CLEAN)
372 endif
373 ifdef REGRESS
374 # things created by various check targets
375 rm -rf $(pg_regress_clean_files)
376 ifeq ($(PORTNAME), win)
377 rm -f regress.def
378 endif
379 endif # REGRESS
380 ifdef TAP_TESTS
381 rm -rf tmp_check/
382 endif
383 ifdef ISOLATION
384 rm -rf output_iso/ tmp_check_iso/
385 endif
387 ifdef MODULE_big
388 clean: clean-lib
389 endif
391 distclean maintainer-clean: clean
394 ifdef REGRESS
396 REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
398 # When doing a VPATH build, must copy over the data files so that the
399 # driver script can find them. We have to use an absolute path for
400 # the targets, because otherwise make will try to locate the missing
401 # files using VPATH, and will find them in $(srcdir), but the point
402 # here is that we want to copy them from $(srcdir) to the build
403 # directory.
405 ifdef VPATH
406 abs_builddir := $(shell pwd)
407 test_files_src := $(wildcard $(srcdir)/data/*.data)
408 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
410 all: $(test_files_build)
411 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
412 $(MKDIR_P) $(dir $@)
413 ln -s $< $@
414 endif # VPATH
415 endif # REGRESS
417 .PHONY: submake
418 submake:
419 ifndef PGXS
420 $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
421 $(MAKE) -C $(top_builddir)/src/test/isolation all
422 endif
424 ifdef ISOLATION
425 ISOLATION_OPTS += --dbname=$(ISOLATION_TESTDB)
426 endif
428 # Standard rules to run regression tests including multiple test suites.
429 # Runs against an installed postmaster.
430 ifndef NO_INSTALLCHECK
431 installcheck: submake $(REGRESS_PREP)
432 ifdef REGRESS
433 $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
434 endif
435 ifdef ISOLATION
436 $(pg_isolation_regress_installcheck) $(ISOLATION_OPTS) $(ISOLATION)
437 endif
438 ifdef TAP_TESTS
439 $(prove_installcheck)
440 endif
441 endif # NO_INSTALLCHECK
443 # Runs independently of any installation
444 ifdef PGXS
445 check:
446 @echo '"$(MAKE) check" is not supported.'
447 @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
448 else
449 check: submake $(REGRESS_PREP)
450 ifdef REGRESS
451 $(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
452 endif
453 ifdef ISOLATION
454 $(pg_isolation_regress_check) $(ISOLATION_OPTS) $(ISOLATION)
455 endif
456 ifdef TAP_TESTS
457 $(prove_check)
458 endif
459 endif # PGXS
461 ifndef NO_TEMP_INSTALL
462 checkprep: EXTRA_INSTALL+=$(subdir)
463 endif
466 # STANDARD RULES
468 ifneq (,$(MODULES)$(MODULE_big))
469 %.sql: %.sql.in
470 sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
471 endif
473 ifdef PROGRAM
474 $(PROGRAM): $(OBJS)
475 $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS_INTERNAL) $(LDFLAGS) $(LDFLAGS_EX) $(PG_LIBS) $(LIBS) -o $@$(X)
476 endif