]> granicus.if.org Git - postgresql/blob - src/makefiles/pgxs.mk
Define integer limits independently from the system definitions.
[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 #   EXTRA_CLEAN -- extra files to remove in 'make clean'
44 #   PG_CPPFLAGS -- will be added to CPPFLAGS
45 #   PG_LIBS -- will be added to PROGRAM link line
46 #   SHLIB_LINK -- will be added to MODULE_big link line
47 #   PG_CONFIG -- path to pg_config program for the PostgreSQL installation
48 #     to build against (typically just "pg_config" to use the first one in
49 #     your PATH)
50 #
51 # Better look at some of the existing uses for examples...
52
53 ifndef PGXS
54 ifndef NO_PGXS
55 $(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
56 endif
57 endif
58
59
60 ifdef PGXS
61 # We assume that we are in src/makefiles/, so top is ...
62 top_builddir := $(dir $(PGXS))../..
63 include $(top_builddir)/src/Makefile.global
64
65 top_srcdir = $(top_builddir)
66 # If VPATH is set or Makefile is not in current directory we are building
67 # the extension with VPATH so we set the variable here.
68 ifdef VPATH
69 srcdir = $(VPATH)
70 else
71 ifeq ($(CURDIR),$(dir $(firstword $(MAKEFILE_LIST))))
72 srcdir = .
73 VPATH =
74 else
75 srcdir = $(dir $(firstword $(MAKEFILE_LIST)))
76 VPATH = $(srcdir)
77 endif
78 endif
79
80 # These might be set in Makefile.global, but if they were not found
81 # during the build of PostgreSQL, supply default values so that users
82 # of pgxs can use the variables.
83 ifeq ($(BISON),)
84 BISON = bison
85 endif
86 ifeq ($(FLEX),)
87 FLEX = flex
88 endif
89 endif
90
91
92 override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
93
94 ifdef MODULES
95 override CFLAGS += $(CFLAGS_SL)
96 endif
97
98 ifdef MODULEDIR
99 datamoduledir := $(MODULEDIR)
100 docmoduledir := $(MODULEDIR)
101 else
102 ifdef EXTENSION
103 datamoduledir := extension
104 docmoduledir := extension
105 else
106 datamoduledir := contrib
107 docmoduledir := contrib
108 endif
109 endif
110
111 ifdef PG_CPPFLAGS
112 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
113 endif
114
115 all: $(PROGRAM) $(DATA_built) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
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 endif # MODULES
140 ifdef DOCS
141 ifdef docdir
142         $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
143 endif # docdir
144 endif # DOCS
145 ifdef PROGRAM
146         $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
147 endif # PROGRAM
148 ifdef SCRIPTS
149         $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
150 endif # SCRIPTS
151 ifdef SCRIPTS_built
152         $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
153 endif # SCRIPTS_built
154
155 ifdef MODULE_big
156 install: install-lib
157 endif # MODULE_big
158
159
160 installdirs:
161 ifneq (,$(EXTENSION))
162         $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
163 endif
164 ifneq (,$(DATA)$(DATA_built))
165         $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
166 endif
167 ifneq (,$(DATA_TSEARCH))
168         $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
169 endif
170 ifneq (,$(MODULES))
171         $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
172 endif
173 ifdef DOCS
174 ifdef docdir
175         $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
176 endif # docdir
177 endif # DOCS
178 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
179         $(MKDIR_P) '$(DESTDIR)$(bindir)'
180 endif
181
182 ifdef MODULE_big
183 installdirs: installdirs-lib
184 endif # MODULE_big
185
186
187 uninstall:
188 ifneq (,$(EXTENSION))
189         rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
190 endif
191 ifneq (,$(DATA)$(DATA_built))
192         rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
193 endif
194 ifneq (,$(DATA_TSEARCH))
195         rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
196 endif
197 ifdef MODULES
198         rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
199 endif
200 ifdef DOCS
201         rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
202 endif
203 ifdef PROGRAM
204         rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
205 endif
206 ifdef SCRIPTS
207         rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
208 endif
209 ifdef SCRIPTS_built
210         rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
211 endif
212
213 ifdef MODULE_big
214 uninstall: uninstall-lib
215 endif # MODULE_big
216
217
218 clean:
219 ifdef MODULES
220         rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES)) $(WIN32RES)
221 endif
222 ifdef DATA_built
223         rm -f $(DATA_built)
224 endif
225 ifdef SCRIPTS_built
226         rm -f $(SCRIPTS_built)
227 endif
228 ifdef PROGRAM
229         rm -f $(PROGRAM)$(X)
230 endif
231 ifdef OBJS
232         rm -f $(OBJS)
233 endif
234 ifdef EXTRA_CLEAN
235         rm -rf $(EXTRA_CLEAN)
236 endif
237 ifdef REGRESS
238 # things created by various check targets
239         rm -rf $(pg_regress_clean_files)
240 ifeq ($(PORTNAME), win)
241         rm -f regress.def
242 endif
243 endif # REGRESS
244
245 ifdef MODULE_big
246 clean: clean-lib
247 endif
248
249 distclean maintainer-clean: clean
250
251
252 ifdef REGRESS
253
254 # Select database to use for running the tests
255 ifneq ($(USE_MODULE_DB),)
256   REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB_MODULE)
257 else
258   REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
259 endif
260
261 # where to find psql for running the tests
262 PSQLDIR = $(bindir)
263
264 # When doing a VPATH build, must copy over the data files so that the
265 # driver script can find them.  We have to use an absolute path for
266 # the targets, because otherwise make will try to locate the missing
267 # files using VPATH, and will find them in $(srcdir), but the point
268 # here is that we want to copy them from $(srcdir) to the build
269 # directory.
270
271 ifdef VPATH
272 abs_builddir := $(shell pwd)
273 test_files_src := $(wildcard $(srcdir)/data/*.data)
274 test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
275
276 all: $(test_files_build)
277 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
278         $(MKDIR_P) $(dir $@)
279         ln -s $< $@
280 endif # VPATH
281
282 .PHONY: submake
283 submake:
284 ifndef PGXS
285         $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
286 endif
287
288 # against installed postmaster
289 installcheck: submake $(REGRESS_PREP)
290         $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
291
292 ifdef PGXS
293 check:
294         @echo '"$(MAKE) check" is not supported.'
295         @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
296 else
297 check: all submake $(REGRESS_PREP)
298         $(pg_regress_check) --extra-install=$(subdir) $(REGRESS_OPTS) $(REGRESS)
299 endif
300 endif # REGRESS
301
302
303 # STANDARD RULES
304
305 ifneq (,$(MODULES)$(MODULE_big))
306 %.sql: %.sql.in
307         sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
308 endif
309
310 ifdef PROGRAM
311 $(PROGRAM): $(OBJS)
312         $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS) $(LDFLAGS) $(LDFLAGS_EX) $(LIBS) -o $@$(X)
313 endif