From b187e31cb4e27892b8ca71e5e3feb3de389ee1e1 Mon Sep 17 00:00:00 2001
From: Craig Ringer <craig@2ndquadrant.com>
Date: Fri, 7 Feb 2020 11:05:24 +0800
Subject: [PATCH] PGXS support for built control files

Teach PGXS how to find the extension control file via the vpath,
rather than assuming that it's always in the $(srcdir).

This allows extensions with more complex needs to template their extension
files without breaking vpath support.

Extensions can work around this issue on older PostgreSQL releases by:

* Setting MODULE_DIR instead of EXTENSION
* Adding their extension control file to DATA_built
---
 src/makefiles/pgxs.mk | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index 037307c076..dcd3b3e48c 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -207,7 +207,6 @@ endef
 
 # end of HEADERS_* stuff
 
-
 all: $(PROGRAM) $(DATA_built) $(HEADER_allbuilt) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
 
 ifeq ($(with_llvm), yes)
@@ -223,11 +222,18 @@ include $(top_srcdir)/src/Makefile.shlib
 all: all-lib
 endif # MODULE_big
 
-
-install: all installdirs
+# Resolve the extension control file along the VPATH, so we can find both built
+# and static file control files.
+#
 ifneq (,$(EXTENSION))
-	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
-endif # EXTENSION
+install_controlfile: $(addsuffix .control, $(EXTENSION)) | installdirs
+	$(INSTALL_DATA) $< '$(DESTDIR)$(datadir)/extension/'
+else
+install_controlfile: ;
+endif
+
+
+install: all installdirs install_controlfile
 ifneq (,$(DATA)$(DATA_built))
 	$(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
 endif # DATA
-- 
2.24.1

