35.16. Extension Building Infrastructure
If you are thinking about distributing yourPostgres Pro extension modules, setting up a portable build system for them can be fairly difficult. Therefore thePostgres Pro installation provides a build infrastructure for extensions, calledPGXS, so that simple extension modules can be built simply against an already installed server.PGXS is mainly intended for extensions that include C code, although it can be used for pure-SQL extensions too. Note thatPGXS is not intended to be a universal build system framework that can be used to build any software interfacing toPostgres Pro; it simply automates common build rules for simple server extension modules. For more complicated packages, you might need to write your own build system. To use thePGXS infrastructure for your extension, you must write a simple makefile. In the makefile, you need to set some variables and include the globalPGXS makefile. Here is an example that builds an extension module named The last three lines should always be the same. Earlier in the file, you assign variables or add custommake rules. Set one of these three variables to specify what is built: list of shared-library objects to be built from source files with same stem (do not include library suffixes in this list) a shared library to build from multiple source files (list object files in an executable program to build (list object files in The following variables can also be set: extension name(s); for each name you must provide an subdirectory of random files to install into random files to install into random files to install under random files to install under script files (not binaries) to install into script files (not binaries) to install into list of regression test cases (without suffix), see below additional switches to pass topg_regress don't define an extra files to remove in will be prepended to will be appended to will be appended to will be prepended to will be added to will be added to path topg_config program for thePostgres Pro installation to build against (typically just Put this makefile as You can also run Alternatively, you can set up a directory for a VPATH build in a similar way to how it is done for the core code. One way to do this is using the core script This procedure can work with a greater variety of directory layouts. The scripts listed in the The easiest way to create the expected files is to create empty files, then do a test run (which will of course report differences). Inspect the actual result files found in theisbn_issn
, consisting of a shared library containing some C code, an extension control file, a SQL script, and a documentation text file:MODULES = isbn_issnEXTENSION = isbn_issnDATA = isbn_issn--1.0.sqlDOCS = README.isbn_issnPG_CONFIG = pg_configPGXS := $(shell $(PG_CONFIG) --pgxs)include $(PGXS)
MODULES
MODULE_big
OBJS
)PROGRAM
OBJS
)EXTENSION
file, which will be installed intoextension
.controlprefix
/share/extensionMODULEDIR
into which DATA and DOCS files should be installed (if not set, default isprefix
/shareextension
ifEXTENSION
is set, orcontrib
if not)DATA
prefix
/share/$MODULEDIRDATA_built
, which need to be built firstprefix
/share/$MODULEDIRDATA_TSEARCH
prefix
/share/tsearch_dataDOCS
prefix
/doc/$MODULEDIRSCRIPTS
prefix
/binSCRIPTS_built
, which need to be built firstprefix
/binREGRESS
REGRESS_OPTS
NO_INSTALLCHECK
installcheck
target, useful e.g., if tests require special configuration, or don't usepg_regressEXTRA_CLEAN
make clean
PG_CPPFLAGS
CPPFLAGS
PG_CFLAGS
CFLAGS
PG_CXXFLAGS
CXXFLAGS
PG_LDFLAGS
LDFLAGS
PG_LIBS
PROGRAM
link lineSHLIB_LINK
MODULE_big
link linePG_CONFIG
pg_config
to use the first one in yourPATH
)Makefile
in the directory which holds your extension. Then you can domake
to compile, and thenmake install
to install your module. By default, the extension is compiled and installed for thePostgres Pro installation that corresponds to the firstpg_config
program found in yourPATH
. You can use a different installation by settingPG_CONFIG
to point to itspg_config
program, either within the makefile or on themake
command line.make
in a directory outside the source tree of your extension, if you want to keep the build directory separate. This procedure is also called aVPATH build. Here's how:mkdir build_dircd build_dirmake -f /path/to/extension/source/tree/Makefilemake -f /path/to/extension/source/tree/Makefile install
config/prep_buildtree
. Once this has been done you can build by setting themake
variableVPATH
like this:make VPATH=/path/to/extension/source/treemake VPATH=/path/to/extension/source/tree install
REGRESS
variable are used for regression testing of your module, which can be invoked bymake installcheck
after doingmake install
. For this to work you must have a runningPostgres Pro server. The script files listed inREGRESS
must appear in a subdirectory namedsql/
in your extension's directory. These files must have extension.sql
, which must not be included in theREGRESS
list in the makefile. For each test there should also be a file containing the expected output in a subdirectory namedexpected/
, with the same stem and extension.out
.make installcheck
executes each test script withpsql, and compares the resulting output to the matching expected file. Any differences will be written to the fileregression.diffs
indiff -c
format. Note that trying to run a test that is missing its expected file will be reported as“trouble”, so make sure you have all expected files.Tip
results/
directory, then copy them toexpected/
if they match what you expect from the test.