]> granicus.if.org Git - postgresql/blob - src/makefiles/pgxs.mk
78e113916ca9fc3488c807699fcb926193996777
[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 #   [custom rules, rarely necessary]
13 #
14 #   PG_CONFIG = pg_config
15 #   PGXS := $(shell $(PG_CONFIG) --pgxs)
16 #   include $(PGXS)
17 #
18 # Set one of these three variables to specify what is built:
19 #
20 #   MODULES -- list of shared-library objects to be built from source files
21 #     with same stem (do not include library suffixes in this list)
22 #   MODULE_big -- a shared library to build from multiple source files
23 #     (list object files in OBJS)
24 #   PROGRAM -- an executable program to build (list object files in OBJS)
25 #
26 # The following variables can also be set:
27 #
28 #   EXTENSION -- name of extension (there must be a $EXTENSION.control file)
29 #   MODULEDIR -- subdirectory of $PREFIX/share into which DATA and DOCS files
30 #     should be installed (if not set, default is "extension" if EXTENSION
31 #     is set, or "contrib" if not)
32 #   DATA -- random files to install into $PREFIX/share/$MODULEDIR
33 #   DATA_built -- random files to install into $PREFIX/share/$MODULEDIR,
34 #     which need to be built first
35 #   DATA_TSEARCH -- random files to install into $PREFIX/share/tsearch_data
36 #   DOCS -- random files to install under $PREFIX/doc/$MODULEDIR
37 #   SCRIPTS -- script files (not binaries) to install into $PREFIX/bin
38 #   SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
39 #     which need to be built first
40 #   REGRESS -- list of regression test cases (without suffix)
41 #   REGRESS_OPTS -- additional switches to pass to pg_regress
42 #   EXTRA_CLEAN -- extra files to remove in 'make clean'
43 #   PG_CPPFLAGS -- will be added to CPPFLAGS
44 #   PG_LIBS -- will be added to PROGRAM link line
45 #   SHLIB_LINK -- will be added to MODULE_big link line
46 #   PG_CONFIG -- path to pg_config program for the PostgreSQL installation
47 #     to build against (typically just "pg_config" to use the first one in
48 #     your PATH)
49 #
50 # Better look at some of the existing uses for examples...
51
52 ifndef PGXS
53 ifndef NO_PGXS
54 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
55 endif
56 endif
57
58
59 ifdef PGXS
60 # We assume that we are in src/makefiles/, so top is ...
61 top_builddir := $(dir $(PGXS))../..
62 include $(top_builddir)/src/Makefile.global
63
64 top_srcdir = $(top_builddir)
65 srcdir = .
66 VPATH =
67
68 # These might be set in Makefile.global, but if they were not found
69 # during the build of PostgreSQL, supply default values so that users
70 # of pgxs can use the variables.
71 ifeq ($(BISON),)
72 BISON = bison
73 endif
74 ifeq ($(FLEX),)
75 FLEX = flex
76 endif
77 endif
78
79
80 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
81
82 ifdef MODULES
83 override CFLAGS += $(CFLAGS_SL)
84 endif
85
86 ifdef MODULEDIR
87 datamoduledir := $(MODULEDIR)
88 docmoduledir := $(MODULEDIR)
89 else
90 ifdef EXTENSION
91 datamoduledir := extension
92 docmoduledir := extension
93 else
94 datamoduledir := contrib
95 docmoduledir := contrib
96 endif
97 endif
98
99 ifdef PG_CPPFLAGS
100 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
101 endif
102
103 all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
104
105 ifdef MODULE_big
106 # shared library parameters
107 NAME = $(MODULE_big)
108
109 include $(top_srcdir)/src/Makefile.shlib
110
111 all: all-lib
112 endif # MODULE_big
113
114
115 install: all installdirs
116 ifneq (,$(EXTENSION))
117         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
118 endif # EXTENSION
119 ifneq (,$(DATA)$(DATA_built))
120         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
121 endif # DATA
122 ifneq (,$(DATA_TSEARCH))
123         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
124 endif # DATA_TSEARCH
125 ifdef MODULES
126         $(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
127 endif # MODULES
128 ifdef DOCS
129 ifdef docdir
130         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
131 endif # docdir
132 endif # DOCS
133 ifdef PROGRAM
134         $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
135 endif # PROGRAM
136 ifdef SCRIPTS
137         $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
138 endif # SCRIPTS
139 ifdef SCRIPTS_built
140         $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
141 endif # SCRIPTS_built
142
143 ifdef MODULE_big
144 install: install-lib
145 endif # MODULE_big
146
147
148 installdirs:
149 ifneq (,$(EXTENSION))
150         $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
151 endif
152 ifneq (,$(DATA)$(DATA_built))
153         $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
154 endif
155 ifneq (,$(DATA_TSEARCH))
156         $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
157 endif
158 ifneq (,$(MODULES))
159         $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
160 endif
161 ifdef DOCS
162 ifdef docdir
163         $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
164 endif # docdir
165 endif # DOCS
166 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
167         $(MKDIR_P) '$(DESTDIR)$(bindir)'
168 endif
169
170 ifdef MODULE_big
171 installdirs: installdirs-lib
172 endif # MODULE_big
173
174
175 uninstall:
176 ifneq (,$(EXTENSION))
177         rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
178 endif
179 ifneq (,$(DATA)$(DATA_built))
180         rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
181 endif
182 ifneq (,$(DATA_TSEARCH))
183         rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
184 endif
185 ifdef MODULES
186         rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
187 endif
188 ifdef DOCS
189         rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
190 endif
191 ifdef PROGRAM
192         rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
193 endif
194 ifdef SCRIPTS
195         rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
196 endif
197 ifdef SCRIPTS_built
198         rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
199 endif
200
201 ifdef MODULE_big
202 uninstall: uninstall-lib
203 endif # MODULE_big
204
205
206 clean:
207 ifdef MODULES
208         rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES))
209 endif
210 ifdef DATA_built
211         rm -f $(DATA_built)
212 endif
213 ifdef SCRIPTS_built
214         rm -f $(SCRIPTS_built)
215 endif
216 ifdef PROGRAM
217         rm -f $(PROGRAM)$(X)
218 endif
219 ifdef OBJS
220         rm -f $(OBJS)
221 endif
222 ifdef EXTRA_CLEAN
223         rm -rf $(EXTRA_CLEAN)
224 endif
225 ifdef REGRESS
226 # things created by various check targets
227         rm -rf $(pg_regress_clean_files)
228 ifeq ($(PORTNAME), win)
229         rm -f regress.def
230 endif
231 endif # REGRESS
232
233 ifdef MODULE_big
234 clean: clean-lib
235 endif
236
237 distclean maintainer-clean: clean
238
239
240 ifdef REGRESS
241
242 # Select database to use for running the tests
243 ifdef USE_MODULE_DB
244   REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE)
245 else
246   REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
247 endif
248
249 # where to find psql for running the tests
250 PSQLDIR = $(bindir)
251
252 # When doing a VPATH build, must copy over the data files so that the
253 # driver script can find them.  We have to use an absolute path for
254 # the targets, because otherwise make will try to locate the missing
255 # files using VPATH, and will find them in $(srcdir), but the point
256 # here is that we want to copy them from $(srcdir) to the build
257 # directory.
258
259 ifdef VPATH
260 abs_builddir := $(shell pwd)
261 test_files_src := $(wildcard $(srcdir)/data/*.data)
262 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
263
264 all: $(test_files_build)
265 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
266         ln -s $< $@
267 endif # VPATH
268
269 .PHONY: submake
270 submake:
271 ifndef PGXS
272         $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
273 endif
274
275 # against installed postmaster
276 installcheck: submake $(REGRESS_PREP)
277         $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
278
279 ifdef PGXS
280 check:
281         @echo '"$(MAKE) check" is not supported.'
282         @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
283 else
284 check: all submake $(REGRESS_PREP)
285         $(pg_regress_check) --extra-install=$(subdir) $(REGRESS_OPTS) $(REGRESS)
286 endif
287 endif # REGRESS
288
289
290 # STANDARD RULES
291
292 ifneq (,$(MODULES)$(MODULE_big))
293 %.sql: %.sql.in
294         sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
295 endif
296
297 ifdef PROGRAM
298 $(PROGRAM): $(OBJS)
299         $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@
300 endif