I've rebased the current set of pending patches I had, to fix pgxs and added 2 
new patches.

Bugfixes have already been presented and sent in another thread, except the 
last one which only fix comment in pgxs.mk.

The new feature consists in a new variable to allow the installation of 
contrib header files.
A new variable MODULEHEADER can be used in extension Makefile to list the
header files to install.

The installation path default to $includedir/$includedir_contrib/$extension.
2 new variables are set to define directories: $includedir_contrib and
$includedir_extension, the former default to include/contrib and the later to
$includedir_contrib/$extension ($extension is the name of the extension).

This allows for example to install hstore header and be able to include them
in another extension like that:

  # include "contrib/hstore/hstore.h"

For packagers of PostgreSQL, this allows to have a postgresql-X.Y-contrib-dev 
package.
For developers of extension it's killing the copy-and-paste-this-function 
dance previously required.

I've not updated contribs' Makfefile: I'm not sure what we want to expose.

I've 2 other patches to write to automatize a bit more the detection of things 
to do when building with USE_PGXS, based on the layout. Better get a good 
consensus on this before writing them.


Bugfix:
0001-fix-SHLIB_PREREQS-when-building-with-USE_PGXS.patch
0002-Create-data-directory-if-extension-when-required.patch
0003-set-VPATH-for-out-of-tree-extension-builds.patch
0004-adds-support-for-VPATH-with-USE_PGXS.patch
0006-Fix-suggested-layout-for-extension.patch

New feature:
0005-Allows-extensions-to-install-header-file.patch

I'll do a documentation patch based on what is accepted in HEAD and/or 
previous branches.
-- 
Cédric Villemain +33 (0)6 20 30 22 52
http://2ndQuadrant.fr/
PostgreSQL: Support 24x7 - Développement, Expertise et Formation
From c23041f31b5a312702d79bbe759a56628f3e37e5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <ced...@2ndquadrant.fr>
Date: Tue, 28 May 2013 14:11:18 +0200
Subject: [PATCH 1/6] fix SHLIB_PREREQS when building with USE_PGXS

commit 19e231b introduced SHLIB_PREREQS but failed to port that to PGXS build.

The issue is that "submake-*" can not be built with PGXS, in this case they
must check that expected files are present (and installed).
Maybe it is better to only check if they have been built ?

This fix the build of dblink and postgres_fdw (make USE_PGXS=1)
---
 src/Makefile.global.in |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 8bfb77d..c3c595e 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -415,13 +415,24 @@ libpq_pgport = -L$(top_builddir)/src/port -lpgport \
 			   -L$(top_builddir)/src/common -lpgcommon $(libpq)
 endif
 
-
+# If PGXS is not defined, builds as usual:
+# build dependancies required by SHLIB_PREREQS
+# If the build is with PGXS, then any requirement is supposed to be already
+# build and we just take care that the expected files exist
+ifndef PGXS
 submake-libpq:
 	$(MAKE) -C $(libpq_builddir) all
+else
+submake-libpq: $(libdir)/libpq.so ;
+endif
 
+ifndef PGXS
 submake-libpgport:
 	$(MAKE) -C $(top_builddir)/src/port all
 	$(MAKE) -C $(top_builddir)/src/common all
+else
+submake-libpgport: $(libdir)/libpgport.a $(libdir)/libpgcommon.a ;
+endif
 
 .PHONY: submake-libpq submake-libpgport
 
-- 
1.7.10.4

From 3d3f4df6792c0e98b0a915b8704504f27738bf26 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <ced...@2ndquadrant.fr>
Date: Tue, 28 May 2013 14:17:04 +0200
Subject: [PATCH 2/6] Create data directory if extension when required

There is a hack to link the regression data files from the srcdir
to the builddir when doing 'make VPATH'. but it failed when used in
conjunction with USE_PGXS and out-of-tree build of an extension.

Issue is the absence of the data/ directory in the builddir.
---
 src/makefiles/pgxs.mk |    1 +
 1 file changed, 1 insertion(+)

diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index bbcfe04..6a19b0f 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -263,6 +263,7 @@ test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src)
 
 all: $(test_files_build)
 $(test_files_build): $(abs_builddir)/%: $(srcdir)/%
+	$(MKDIR_P) $(dir $@)
 	ln -s $< $@
 endif # VPATH
 
-- 
1.7.10.4

From 66b394ae867bde2ad968027f0708ae59a140d81b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <ced...@2ndquadrant.fr>
Date: Tue, 28 May 2013 14:51:43 +0200
Subject: [PATCH 3/6] set VPATH for out-of-tree extension builds

If the makefile is not in the current directory (where we launch 'make')
then assume we are building out-of-src tree and set the VPATH to the
directory of the first makefile...

Thus it fixes:
mkdir /tmp/a && cd /tmp/a
make -f extension_src/Makefile USE_PGXS=1
---
 src/makefiles/pgxs.mk |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index 6a19b0f..50fd99d 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -61,9 +61,18 @@ ifdef PGXS
 top_builddir := $(dir $(PGXS))../..
 include $(top_builddir)/src/Makefile.global
 
+# If Makefile is not in current directory we are building the extension with
+# VPATH so we set the variable here
+# XXX what about top_srcdir ?
+ifeq ($(CURDIR),$(dir $(firstword $(MAKEFILE_LIST))))
 top_srcdir = $(top_builddir)
 srcdir = .
 VPATH =
+else
+top_srcdir = $(top_builddir)
+srcdir = $(dir $(firstword $(MAKEFILE_LIST)))
+VPATH = $(srcdir)
+endif
 
 # These might be set in Makefile.global, but if they were not found
 # during the build of PostgreSQL, supply default values so that users
-- 
1.7.10.4

From f446d646c3459c9ec81856b3b3ab0560a419d29e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <ced...@2ndquadrant.fr>
Date: Tue, 28 May 2013 15:17:27 +0200
Subject: [PATCH 4/6] adds support for VPATH with USE_PGXS

It just change recipe for install: in pgxs.mk.

I didn't touch MODULE and PROGRAM (yet)
---
 src/makefiles/pgxs.mk |   43 +++++++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 18 deletions(-)

diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index 50fd99d..f70d5f7 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -121,33 +121,40 @@ all: all-lib
 endif # MODULE_big
 
 
-install: all installdirs
-ifneq (,$(EXTENSION))
-	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
-endif # EXTENSION
-ifneq (,$(DATA)$(DATA_built))
-	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
-endif # DATA
-ifneq (,$(DATA_TSEARCH))
-	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
-endif # DATA_TSEARCH
+install: all installdirs installcontrol installdata installdatatsearch installdocs installscripts
 ifdef MODULES
 	$(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
 endif # MODULES
+ifdef PROGRAM
+	$(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
+endif # PROGRAM
+
+installcontrol: $(addsuffix .control, $(EXTENSION))
+ifneq (,$(EXTENSION))
+	$(INSTALL_DATA) $< '$(DESTDIR)$(datadir)/extension/'
+endif
+
+installdata: $(DATA) $(DATA_built)
+ifneq (,$(DATA)$(DATA_built))
+	$(INSTALL_DATA) $^ '$(DESTDIR)$(datadir)/$(datamoduledir)/'
+endif
+
+installdatatsearch: $(DATA_TSEARCH)
+ifneq (,$(DATA_TSEARCH))
+	$(INSTALL_DATA) $^ '$(DESTDIR)$(datadir)/tsearch_data/'
+endif
+
+installdocs: $(DOCS)
 ifdef DOCS
 ifdef docdir
-	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
+	$(INSTALL_DATA) $^ '$(DESTDIR)$(docdir)/$(docmoduledir)/'
 endif # docdir
 endif # DOCS
-ifdef PROGRAM
-	$(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
-endif # PROGRAM
+
+installscripts: $(SCRIPTS) $(SCRIPTS_built)
 ifdef SCRIPTS
-	$(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
+	$(INSTALL_SCRIPT) $^ '$(DESTDIR)$(bindir)/'
 endif # SCRIPTS
-ifdef SCRIPTS_built
-	$(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
-endif # SCRIPTS_built
 
 ifdef MODULE_big
 install: install-lib
-- 
1.7.10.4

From b9d215eaced393a61c1b4398b7cbb164aa3cefdd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <ced...@2ndquadrant.fr>
Date: Tue, 18 Jun 2013 15:19:22 +0200
Subject: [PATCH 6/6] Fix suggested layout for extension

custom rules must come after pgxs inclusion, not before. It is because any
rule added before pgxs will break the default 'all' target.
---
 src/makefiles/pgxs.mk |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index 4f25890..0842c77 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -9,12 +9,13 @@
 # Use the following layout for your Makefile:
 #
 #   [variable assignments, see below]
-#   [custom rules, rarely necessary]
 #
 #   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
-- 
1.7.10.4

From 04b3da98d3526fdf8c3d3650a49381e4633ff3ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <ced...@2ndquadrant.fr>
Date: Tue, 18 Jun 2013 15:08:27 +0200
Subject: [PATCH 5/6] Allows extensions to install header file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

A new variable MODULEHEADER can be used in extension Makefile to list the
header files to install.

The installation path default to $includedir/$includedir_contrib/$extension.
2 new variables are set to define directories: $includedir_contrib and
$includedir_extension, the former default to include/contrib and the later to
$includedir_contrib/$extension ($extension is the name of the extension).

This allows for example to install hstore header and be able to include them
in another extension like that:

  # include "contrib/hstore/hstore.h"
---
 src/Makefile.global.in |    1 +
 src/makefiles/pgxs.mk  |   15 ++++++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index c3c595e..96fd0f6 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -149,6 +149,7 @@ endif # PGXS
 
 includedir_server = $(pkgincludedir)/server
 includedir_internal = $(pkgincludedir)/internal
+includedir_contrib = $(pkgincludedir)/contrib
 pgxsdir = $(pkglibdir)/pgxs
 
 
diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index f70d5f7..4f25890 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -39,6 +39,7 @@
 #     which need to be built first
 #   REGRESS -- list of regression test cases (without suffix)
 #   REGRESS_OPTS -- additional switches to pass to pg_regress
+#   MODULEHEADER -- list of header to install in $INCLUDEDIR_CONTRIB/$EXTENSION
 #   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
@@ -105,6 +106,10 @@ docmoduledir := contrib
 endif
 endif
 
+ifdef MODULEHEADER
+includedir_extension := $(includedir_contrib)/$(EXTENSION)
+endif
+
 ifdef PG_CPPFLAGS
 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
 endif
@@ -121,7 +126,7 @@ all: all-lib
 endif # MODULE_big
 
 
-install: all installdirs installcontrol installdata installdatatsearch installdocs installscripts
+install: all installdirs installcontrol installdata installdatatsearch installdocs installscripts installheader
 ifdef MODULES
 	$(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
 endif # MODULES
@@ -156,6 +161,11 @@ ifdef SCRIPTS
 	$(INSTALL_SCRIPT) $^ '$(DESTDIR)$(bindir)/'
 endif # SCRIPTS
 
+installheader: $(MODULEHEADER)
+ifneq (,$(MODULEHEADER))
+	$(INSTALL_DATA) $^ '$(DESTDIR)$(includedir_extension)/'
+endif
+
 ifdef MODULE_big
 install: install-lib
 endif # MODULE_big
@@ -182,6 +192,9 @@ endif # DOCS
 ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
 	$(MKDIR_P) '$(DESTDIR)$(bindir)'
 endif
+ifneq (,$(MODULEHEADER))
+	$(MKDIR_P) '$(DESTDIR)/$(includedir_extension)'
+endif
 
 ifdef MODULE_big
 installdirs: installdirs-lib
-- 
1.7.10.4

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to