# source /var/lib/pgsql/.bash_profile
# USE_PGXS=1 make
# USE_PGXS=1 make install
下面简单分析一下:
某个具体 contrib 的 Makefile文件
# PGXS build needs PostgreSQL 9.2 or later. Earlier versions didn't install
# plpgsql.h, so you needed the full source tree to access it.
ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/xxoo
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif
下面这句话很关键:
PGXS build needs PostgreSQL 9.2 or later
查看pg_config
$ which pg_config
/usr/pgsql-9.6/bin/pg_config
# This file contains generic rules to build many kinds of simple
# extension modules. You only need to set a few variables and include
# this file, the rest will be done here.
#
# Use the following layout for your Makefile:
#
# [variable assignments, see below]
#
# PG_CONFIG = pg_config
# PGXS := $(shell $(PG_CONFIG) --pgxs)
# include $(PGXS)
#
# [custom rules, rarely necessary]
#
# Set one of these three variables to specify what is built:
#
# MODULES -- list of shared-library objects to be built from source files
# with same stem (do not include library suffixes in this list)
# MODULE_big -- a shared library to build from multiple source files
# (list object files in OBJS)
# PROGRAM -- an executable program to build (list object files in OBJS)
#
# The following variables can also be set:
#
# EXTENSION -- name of extension (there must be a $EXTENSION.control file)
# MODULEDIR -- subdirectory of $PREFIX/share into which DATA and DOCS files
# should be installed (if not set, default is "extension" if EXTENSION
# is set, or "contrib" if not)
# DATA -- random files to install into $PREFIX/share/$MODULEDIR
# DATA_built -- random files to install into $PREFIX/share/$MODULEDIR,
# which need to be built first
# DATA_TSEARCH -- random files to install into $PREFIX/share/tsearch_data
# DOCS -- random files to install under $PREFIX/doc/$MODULEDIR
# SCRIPTS -- script files (not binaries) to install into $PREFIX/bin
# SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
# which need to be built first
# REGRESS -- list of regression test cases (without suffix)
# REGRESS_OPTS -- additional switches to pass to pg_regress
# EXTRA_CLEAN -- extra files to remove in 'make clean'
# PG_CPPFLAGS -- will be added to CPPFLAGS
# PG_LIBS -- will be added to PROGRAM link line
# SHLIB_LINK -- will be added to MODULE_big link line
# PG_CONFIG -- path to pg_config program for the PostgreSQL installation
# to build against (typically just "pg_config" to use the first one in
# your PATH)
#
# Better look at some of the existing uses for examples...
pgxs 是 postgrsql 9.2 之后针对编译 extension 的解决方案。如果是之前的版本,就需要 postgresql full source 完全编译。