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