From 04b3da98d3526fdf8c3d3650a49381e4633ff3ec Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric=20Villemain?= <cedric@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

