[postgis-tickets] [SCM] PostGIS branch out-of-tree-builds created. 3.2.0-310-ga30769a03

git at osgeo.org git at osgeo.org
Wed Jan 19 14:01:19 PST 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, out-of-tree-builds has been created
        at  a30769a031d66a1eba1c3c422b2808d90e7f04ee (commit)

- Log -----------------------------------------------------------------
commit a30769a031d66a1eba1c3c422b2808d90e7f04ee
Author: Sandro Santilli <strk at kbt.io>
Date:   Wed Jan 19 15:42:11 2022 +0100

    Steps toward supporting out-of-tree builds
    
    References #5060

diff --git a/GNUmakefile.in b/GNUmakefile.in
index 963bcb984..f2e8c058c 100644
--- a/GNUmakefile.in
+++ b/GNUmakefile.in
@@ -16,6 +16,8 @@ POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@
 POSTGIS_MICRO_VERSION=@POSTGIS_MICRO_VERSION@
 
 PERL = @PERL@
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
 
 # todo: add more rules here, like uninstall, clean...
 all install uninstall noop clean distclean check-unit:
@@ -184,26 +186,28 @@ ifeq (@PHONY_REVISION@,yes)
 endif
 
 postgis_revision.h:
-	$(PERL) utils/repo_revision.pl
+	$(PERL) $(top_srcdir)/utils/repo_revision.pl
 
 .PHONY: utils liblwgeom ChangeLog raster
 
-topsrcdir = $(realpath ./)
-include regress/core/tests.mk
-include regress/loader/tests.mk
-include regress/dumper/tests.mk
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
+
+include $(top_builddir)/regress/core/tests.mk
+include $(top_srcdir)/regress/loader/tests.mk
+include $(top_srcdir)/regress/dumper/tests.mk
 ifeq ($(HAVE_SFCGAL),yes)
 	override RUNTESTFLAGS := $(RUNTESTFLAGS) --sfcgal
-	include sfcgal/regress/tests.mk
+	include $(top_srcdir)/sfcgal/regress/tests.mk
 endif
 ifeq (@TOPOLOGY@,topology)
-	include topology/test/tests.mk
+	include $(top_srcdir)/topology/test/tests.mk
 endif
 ifeq (@RASTER@,raster)
-	include raster/test/regress/tests.mk
+	include $(top_srcdir)/raster/test/regress/tests.mk
 endif
 
-include regress/runtest.mk
+include $(top_srcdir)/regress/runtest.mk
 
 check-regress: staged-install check-regress-deps
 
diff --git a/configure.ac b/configure.ac
index 7f3a16310..8764220de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -88,9 +88,9 @@ AC_SUBST([EXESUFFIX])
 dnl
 dnl Version Information imported from Version.config
 dnl
-POSTGIS_MAJOR_VERSION=`cat Version.config | grep ^POSTGIS_MAJOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
-POSTGIS_MINOR_VERSION=`cat Version.config | grep ^POSTGIS_MINOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
-POSTGIS_MICRO_VERSION=`cat Version.config | grep ^POSTGIS_MICRO_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
+POSTGIS_MAJOR_VERSION=`cat ${srcdir}/Version.config | grep ^POSTGIS_MAJOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
+POSTGIS_MINOR_VERSION=`cat ${srcdir}/Version.config | grep ^POSTGIS_MINOR_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
+POSTGIS_MICRO_VERSION=`cat ${srcdir}/Version.config | grep ^POSTGIS_MICRO_VERSION | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
 
 AC_DEFINE_UNQUOTED([POSTGIS_MAJOR_VERSION], ["$POSTGIS_MAJOR_VERSION"], [PostGIS major version])
 AC_DEFINE_UNQUOTED([POSTGIS_MINOR_VERSION], ["$POSTGIS_MINOR_VERSION"], [PostGIS minor version])
@@ -119,9 +119,9 @@ AC_SUBST([LIBINCLUDEMINORVERSION])
 dnl
 dnl Liblwgeom version information imported from Version.config
 dnl
-LIBLWGEOM_CURRENT=`cat Version.config | grep ^LIBLWGEOM_IFACE_CUR | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
-LIBLWGEOM_AGE=`cat Version.config | grep ^LIBLWGEOM_IFACE_AGE | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
-LIBLWGEOM_REV=`cat Version.config | grep ^LIBLWGEOM_IFACE_REV | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
+LIBLWGEOM_CURRENT=`cat ${srcdir}/Version.config | grep ^LIBLWGEOM_IFACE_CUR | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
+LIBLWGEOM_AGE=`cat ${srcdir}/Version.config | grep ^LIBLWGEOM_IFACE_AGE | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
+LIBLWGEOM_REV=`cat ${srcdir}/Version.config | grep ^LIBLWGEOM_IFACE_REV | sed 's/[[^=]]*=\([[0-9]]\)/\1/g'`
 AC_SUBST([LIBLWGEOM_CURRENT])
 AC_SUBST([LIBLWGEOM_AGE])
 AC_SUBST([LIBLWGEOM_REV])
diff --git a/deps/flatgeobuf/Makefile.in b/deps/flatgeobuf/Makefile.in
index fd5c74171..17e35b556 100644
--- a/deps/flatgeobuf/Makefile.in
+++ b/deps/flatgeobuf/Makefile.in
@@ -19,16 +19,22 @@
 # **********************************************************************
 # *
 # * Copyright 2021 Björn Harrtell
+# * Copyright 2022 Sandro Santilli <strk at kbt.io>
 # *
 # **********************************************************************/
 
-CXX = @FLATGEOBUF_CXX@
-CXXFLAGS =-I../../liblwgeom -Iinclude @CPPFLAGS@ @CXXFLAGS@ @PICFLAGS@
-LDFLAGS = @LDFLAGS@
 top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
 libdir = @libdir@
+
+CXX = @FLATGEOBUF_CXX@
+CXXFLAGS =-I$(top_srcdir)/liblwgeom -I$(top_builddir)/liblwgeom -I$(srcdir)/include @CPPFLAGS@ @CXXFLAGS@ @PICFLAGS@
+LDFLAGS = @LDFLAGS@
 LIBTOOL = @LIBTOOL@
 
+VPATH = $(srcdir)
+
 FLATGEOBUF_OBJS = \
 	flatgeobuf_c.o geometrywriter.o geometryreader.o packedrtree.o
 
diff --git a/deps/ryu/Makefile.in b/deps/ryu/Makefile.in
index 8201bc312..6bbd5472a 100644
--- a/deps/ryu/Makefile.in
+++ b/deps/ryu/Makefile.in
@@ -19,16 +19,21 @@
 # **********************************************************************
 # *
 # * Copyright 2019 Raúl Marín
+# * Copyright 2022 Sandro Santilli <strk at kbt.io>
 # *
 # **********************************************************************/
 
-CC=@CC@
-CFLAGS = -I.. @CPPFLAGS@ @CFLAGS@ @PICFLAGS@ -DRYU_NO_TRAILING_ZEROS
 top_builddir = @top_builddir@
+srcdir = @srcdir@
+
+CC=@CC@
+CFLAGS = -I$(srcdir)/.. @CPPFLAGS@ @CFLAGS@ @PICFLAGS@ -DRYU_NO_TRAILING_ZEROS
 SHELL = @SHELL@
 INSTALL = @INSTALL@
 LIBTOOL = @LIBTOOL@
 
+VPATH = $(srcdir)
+
 RYU_OBJS = d2s.o
 LT_RYU_OBJS =  $(RYU_OBJS:.o=.lo)
 
diff --git a/deps/wagyu/Makefile.in b/deps/wagyu/Makefile.in
index 03d227911..98b5cb76d 100644
--- a/deps/wagyu/Makefile.in
+++ b/deps/wagyu/Makefile.in
@@ -19,16 +19,22 @@
 # **********************************************************************
 # *
 # * Copyright 2019 Raúl Marín
+# * Copyright 2022 Sandro Santilli <strk at kbt.io>
 # *
 # **********************************************************************/
 
-CXX = @WAGYU_CXX@
-CXXFLAGS =-I../../liblwgeom -Iinclude @CPPFLAGS@ @CXXFLAGS@ @PICFLAGS@
-LDFLAGS = @LDFLAGS@
 top_builddir = @top_builddir@
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
 libdir = @libdir@
+
+CXX = @WAGYU_CXX@
+CXXFLAGS =-I$(top_srcdir)/liblwgeom -I$(top_builddir)/liblwgeom -I$(srcdir)/include @CPPFLAGS@ @CXXFLAGS@ @PICFLAGS@
+LDFLAGS = @LDFLAGS@
 LIBTOOL = @LIBTOOL@
 
+VPATH = $(srcdir)
+
 WAGYU_OBJS = \
 	lwgeom_wagyu.o
 
diff --git a/doc/Makefile.in b/doc/Makefile.in
index b925df08d..f63f08eeb 100644
--- a/doc/Makefile.in
+++ b/doc/Makefile.in
@@ -7,7 +7,7 @@
 #
 # PostGIS documentation build Makefile
 #
-# Copyright 2003-2012 Sandro Santilli <strk at kbt.io>
+# Copyright 2003-2022 Sandro Santilli <strk at kbt.io>
 # Copyright 2004-2012 Paul Ramsey <pramsey at cleverelephant.ca>
 # Copyright 2009-2011 Regina Obe <lr at pcorp.us>
 # Copyright 2008-2010 Mark Cave-Ayland
@@ -23,6 +23,11 @@
 
 translations = it_IT pt_BR fr es pl ko_KR de ja ru
 
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+builddir = @builddir@
+top_builddir = @top_builddir@
+
 POSTGIS_MAJOR_VERSION=@POSTGIS_MAJOR_VERSION@
 POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@
 POSTGIS_MICRO_VERSION=@POSTGIS_MICRO_VERSION@
@@ -164,6 +169,8 @@ XML_INPUTS = $(XML_SOURCES) $(XML_GENERATED_SOURCES)
 
 XML_INPUTS_POT = $(XML_SOURCES:%.xml=po/templates/%.xml.pot)
 
+VPATH = $(srcdir)
+
 .PHONY: $(XML_INPUTS_POT)
 ifeq ($(XML2POT),)
 $(XML_INPUTS_POT): requirements_not_met_xml2pot
@@ -213,44 +220,45 @@ ifeq ($(XSLTPROC),)
 postgis_aggs_mm.xml: requirements_not_met_xsltproc
 else
 postgis_aggs_mm.xml: ./xsl/postgis_aggs_mm.xml.xsl Makefile postgis-out.xml $(XML_SOURCES)
-	$(XSLTPROC) --novalid ./xsl/postgis_aggs_mm.xml.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/postgis_aggs_mm.xml.xsl postgis-out.xml > $@
 endif
 
 postgis_comments.sql: ./xsl/postgis_comments.sql.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/postgis_comments.sql.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/postgis_comments.sql.xsl postgis-out.xml > $@
 
 postgis_cheatsheet.html: ./xsl/postgis_cheatsheet.html.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/postgis_cheatsheet.html.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/postgis_cheatsheet.html.xsl postgis-out.xml > $@
 
 raster_comments.sql: ./xsl/raster_comments.sql.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/raster_comments.sql.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/raster_comments.sql.xsl postgis-out.xml > $@
 
 raster_cheatsheet.html: ./xsl/raster_cheatsheet.html.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/raster_cheatsheet.html.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/raster_cheatsheet.html.xsl postgis-out.xml > $@
 
 topology_comments.sql: ./xsl/topology_comments.sql.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/topology_comments.sql.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/topology_comments.sql.xsl postgis-out.xml > $@
 
 topology_cheatsheet.html: ./xsl/topology_cheatsheet.html.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/topology_cheatsheet.html.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/topology_cheatsheet.html.xsl postgis-out.xml > $@
 
 sfcgal_comments.sql: ./xsl/sfcgal_comments.sql.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/sfcgal_comments.sql.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/sfcgal_comments.sql.xsl postgis-out.xml > $@
 
 sfcgal_cheatsheet.html: ./xsl/sfcgal_cheatsheet.html.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/sfcgal_cheatsheet.html.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/sfcgal_cheatsheet.html.xsl postgis-out.xml > $@
 
 tiger_geocoder_comments.sql: ./xsl/tiger_geocoder_comments.sql.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/tiger_geocoder_comments.sql.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/tiger_geocoder_comments.sql.xsl postgis-out.xml > $@
 
 tiger_geocoder_cheatsheet.html: ./xsl/tiger_geocoder_cheatsheet.html.xsl $(XML_INPUTS)
-	$(XSLTPROC) --novalid ./xsl/tiger_geocoder_cheatsheet.html.xsl postgis-out.xml > $@
+	$(XSLTPROC) --novalid --path $(srcdir) $(srcdir)/xsl/tiger_geocoder_cheatsheet.html.xsl postgis-out.xml > $@
 
 postgis-out.xml: postgis.xml Makefile
 	$(PERL) -lpe "s'@@LAST_RELEASE_VERSION@@'${POSTGIS_MAJOR_VERSION}.${POSTGIS_MINOR_VERSION}.${POSTGIS_MICRO_VERSION}'g;s'@@POSTGIS_DOWNLOAD_URL@@'${POSTGIS_DOWNLOAD_URL}'g;" $< > $@
 
 chunked-html: postgis-out.xml Makefile images $(XML_INPUTS)
 	$(XSLTPROC) $(XSLTPROC_COMMONOPTS) \
+		--path $(srcdir)
 		--output html/ \
 		$(CHUNK_HTML_DOCBOOK_XSL) \
 		$<
diff --git a/extensions/address_standardizer/Makefile.in b/extensions/address_standardizer/Makefile.in
index 3a3632c69..7ddce035b 100644
--- a/extensions/address_standardizer/Makefile.in
+++ b/extensions/address_standardizer/Makefile.in
@@ -1,4 +1,4 @@
-include ../upgradeable_versions.mk
+include @srcdir@/../upgradeable_versions.mk
 OBJS = \
     address_parser.o \
     address_standardizer.o \
@@ -66,7 +66,7 @@ REGRESS = test-init-extensions test-parseaddress test-standardize_address_1 test
 # and adding the version number
 sql/%.sql: %.sql.in
 	mkdir -p sql
-	$(SQLPP) -I../libpgcommon $< | grep -v '^#' | \
+	$(SQLPP) -I at buiddir@/../libpgcommon $< | grep -v '^#' | \
 	$(PERL) -lpe "s'MODULE_PATHNAME'\$(MODULEPATH)'g" > $@
 
 %.control: %.control.in Makefile
@@ -122,7 +122,7 @@ sql/$(EXTENSION)_data_us--ANY--$(EXTVERSION).sql: sql/$(EXTENSION)_data_us--$(EX
 	mkdir -p sql
 	cat $^ > $@
 
-include ../upgrade-paths-rules.mk
+include @srcdir@/../upgrade-paths-rules.mk
 
 install: install-upgrade-paths-data-us
 # address_standardizer is already defined, we have to additionally create
@@ -208,3 +208,5 @@ PG_CONFIG := @PG_CONFIG@
 PGXS := @PGXS@
 include $(PGXS)
 PERL = @PERL@
+
+VPATH = @srcdir@
diff --git a/extensions/postgis/Makefile.in b/extensions/postgis/Makefile.in
index 9f3331cb4..62fb52410 100644
--- a/extensions/postgis/Makefile.in
+++ b/extensions/postgis/Makefile.in
@@ -1,4 +1,4 @@
-include ../upgradeable_versions.mk
+include @srcdir@/../upgradeable_versions.mk
 
 EXTENSION     = postgis
 EXTVERSION    = @POSTGIS_LIB_VERSION@
@@ -67,6 +67,8 @@ EXTRA_CLEAN = sql/
 
 CURV_big=@POSTGIS_MAJOR_VERSION@@POSTGIS_MINOR_VERSION@
 
+VPATH = @srcdir@
+
 all: sql/$(EXTENSION)--$(EXTVERSION).sql sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql sql/$(EXTENSION)--ANY--$(EXTVERSION).sql
 
 $(EXTENSION).control: $(EXTENSION).control.in Makefile
@@ -84,24 +86,22 @@ sql/raster_unpackage.sql: ../../utils/create_extension_unpackage.pl
 sql/raster_unpackage.sql: unpackage_raster_if_needed.sql
 sql/raster_unpackage.sql: $(RASTER_DROP_SCRIPTS) | sql
 
-	sed '/UNPACKAGE_CODE/q' unpackage_raster_if_needed.sql > $@
+	sed '/UNPACKAGE_CODE/q' @srcdir@/unpackage_raster_if_needed.sql > $@
 
-	cat $(RASTER_DROP_SCRIPTS) \
-		| $(PERL) ../../utils/create_extension_unpackage.pl postgis >> $@
+	cat $^ \
+		| $(PERL) @top_srcdir@/utils/create_extension_unpackage.pl postgis >> $@
 
 	sed -ne '/UNPACKAGE_CODE/{s///; :a' -e 'n;p;ba' -e '}' \
-		unpackage_raster_if_needed.sql  >> $@
+		@srcdir@/unpackage_raster_if_needed.sql  >> $@
 
 sql/$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION_SCRIPTS) | sql
 	printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@
 	cat $^ >> $@
 
-sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) sql/$(EXTENSION)--ANY--$(EXTVERSION).sql ../../utils/create_unpackaged.pl Makefile | sql
+sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) | sql/$(EXTENSION)--ANY--$(EXTVERSION).sql ../../utils/create_unpackaged.pl Makefile sql
 	# Ensure version is correct
 	cat sql/$(EXTENSION)--ANY--$(EXTVERSION).sql > $@
-	cat $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) \
-		| $(PERL) ../../utils/create_unpackaged.pl postgis \
-		>> $@
+	cat $^ | $(PERL) @top_srcdir@/utils/create_unpackaged.pl postgis >> $@
 
 sql/$(EXTENSION)--unpackaged.sql: Makefile | sql
 	echo "-- Nothing to do here" > $@
@@ -117,7 +117,7 @@ sql/spatial_ref_sys.sql: ../../spatial_ref_sys.sql | sql
 	$(MAKE) -C ../../doc comments
 
 sql/spatial_ref_sys_config_dump.sql: ../../spatial_ref_sys.sql ../../utils/create_spatial_ref_sys_config_dump.pl | sql
-	$(PERL) ../../utils/create_spatial_ref_sys_config_dump.pl $< > $@
+	$(PERL) @top_srcdir@/utils/create_spatial_ref_sys_config_dump.pl $< > $@
 
 sql/postgis_upgrade_for_extension.sql: ../../postgis/postgis_before_upgrade.sql sql/postgis_upgrade_for_extension.sql.in ../../postgis/postgis_after_upgrade.sql | sql
 	#strip BEGIN/COMMIT since these are not allowed in extensions
@@ -125,10 +125,10 @@ sql/postgis_upgrade_for_extension.sql: ../../postgis/postgis_before_upgrade.sql
 	cat $^ | $(PERL) -pe 's/BEGIN\;//g ; s/COMMIT\;//g' > $@
 
 sql/postgis_upgrade_for_extension.sql.in: sql/postgis_for_extension.sql ../../utils/postgis_proc_upgrade.pl | sql
-	$(PERL) ../../utils/postgis_proc_upgrade.pl $< UNUSED > $@
+	$(PERL) @top_srcdir@/utils/postgis_proc_upgrade.pl $< UNUSED > $@
 
 sql/postgis_for_extension.sql: ../../postgis/postgis.sql.in ../../postgis_revision.h | sql
-	$(SQLPP) -I../../libpgcommon $< | grep -v '^#' | \
+	$(SQLPP) -I at builddir@/../../postgis $< | grep -v '^#' | \
 	$(PERL) -lpe \
 		"s'MODULE_PATHNAME'\$(MODULEPATH)'g" \
 		| $(PERL) -pe 's/BEGIN\;//g ; s/COMMIT\;//g' > $@
@@ -139,9 +139,9 @@ sql/postgis_upgrade.sql: sql/postgis_upgrade_for_extension.sql | sql
 
 sql/$(EXTENSION)--ANY--$(EXTVERSION).sql: $(EXTENSION_UPGRADE_SCRIPTS) | sql
 	printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@
-	cat $(EXTENSION_UPGRADE_SCRIPTS) >> $@
+	cat $^ >> $@
 
-include ../upgrade-paths-rules.mk
+include @srcdir@/../upgrade-paths-rules.mk
 
 distclean: clean
 	rm -f Makefile
diff --git a/extensions/postgis_raster/Makefile.in b/extensions/postgis_raster/Makefile.in
index f61fbee7d..f5c34c0ac 100644
--- a/extensions/postgis_raster/Makefile.in
+++ b/extensions/postgis_raster/Makefile.in
@@ -1,4 +1,4 @@
-include ../upgradeable_versions.mk
+include @srcdir@/../upgradeable_versions.mk
 
 EXTENSION     = postgis_raster
 EXTVERSION    = @POSTGIS_LIB_VERSION@
@@ -59,6 +59,8 @@ EXTRA_CLEAN = sql
 
 CURV_big=@POSTGIS_MAJOR_VERSION@@POSTGIS_MINOR_VERSION@
 
+VPATH = @srcdir@
+
 all: sql/$(EXTENSION)--$(EXTVERSION).sql sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql
 
 sql:
@@ -75,13 +77,13 @@ sql/$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION_SCRIPTS) | sql
 	printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@
 	cat $^ >> $@
 
-sql/$(EXTENSION)--unpackaged.sql: Makefile | sql
+sql/$(EXTENSION)--unpackaged.sql: Makefile
 	echo "-- Nothing to do here" > $@
 
-sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) ../../utils/create_unpackaged.pl sql/$(EXTENSION)--ANY--$(EXTVERSION).sql Makefile | sql
+sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) | ../../utils/create_unpackaged.pl sql/$(EXTENSION)--ANY--$(EXTVERSION).sql Makefile sql
 	# Ensure version is correct
 	cat sql/$(EXTENSION)--ANY--$(EXTVERSION).sql > $@
-	cat $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) | $(PERL) ../../utils/create_unpackaged.pl postgis_raster >> $@
+	cat $^ | $(PERL) @top_srcdir@/utils/create_unpackaged.pl postgis_raster >> $@
 
 unpackaged_check.sql: unpackaged_check.sql.in Makefile
 	cat $< \
@@ -93,7 +95,7 @@ sql/rtpostgis.sql: sql/rtpostgis_for_extension.sql | sql
 	$(PERL) -pe 's/BEGIN\;//g ; s/COMMIT\;//g' $< > $@
 
 sql/rtpostgis_for_extension.sql: ../../raster/rt_pg/rtpostgis.sql.in ../../postgis_revision.h | sql
-	$(SQLPP) -I../../postgis/ -I../../ $< | grep -v '^#' | \
+	$(SQLPP) -I at builddir@/../../postgis/ -I../../ $< | grep -v '^#' | \
 	$(PERL) -lpe "s'MODULE_PATHNAME'\$(MODULEPATH)'g" > $@
 
 sql/rtpostgis_upgrade.sql: sql/rtpostgis_upgrade_for_extension.sql | sql
@@ -107,7 +109,7 @@ sql/rtpostgis_upgrade_for_extension.sql: ../../raster/rt_pg/rtpostgis_upgrade_cl
 
 
 sql/rtpostgis_upgrade_for_extension.sql.in: sql/rtpostgis_for_extension.sql ../../utils/postgis_proc_upgrade.pl | sql
-	$(PERL) ../../utils/postgis_proc_upgrade.pl $< UNUSED > $@
+	$(PERL) @top_srcdir@/utils/postgis_proc_upgrade.pl $< UNUSED > $@
 
 
 ../../doc/raster_comments.sql:
@@ -118,9 +120,9 @@ sql/raster_comments.sql: ../../doc/raster_comments.sql | sql
 
 sql/$(EXTENSION)--ANY--$(EXTVERSION).sql: $(EXTENSION_UPGRADE_SCRIPTS) | sql
 	printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@
-	cat $(EXTENSION_UPGRADE_SCRIPTS) >> $@
+	cat $^ >> $@
 
-include ../upgrade-paths-rules.mk
+include @srcdir@/../upgrade-paths-rules.mk
 
 distclean: clean
 	rm -f Makefile
diff --git a/extensions/postgis_sfcgal/Makefile.in b/extensions/postgis_sfcgal/Makefile.in
index b3c001957..75c3248cf 100644
--- a/extensions/postgis_sfcgal/Makefile.in
+++ b/extensions/postgis_sfcgal/Makefile.in
@@ -1,4 +1,4 @@
-include ../upgradeable_versions.mk
+include @srcdir@/../upgradeable_versions.mk
 
 EXTENSION    = postgis_sfcgal
 EXTVERSION    = @POSTGIS_LIB_VERSION@
@@ -32,19 +32,19 @@ DATA_built = \
 # Scripts making up the extension minor upgrade file
 # NOTE: order matters
 EXTENSION_UPGRADE_SCRIPTS = \
-	sql_bits/sfcgal_upgrade_minor.sql
+	sql/sfcgal_upgrade_minor.sql
 
 # Scripts making up the extension upgrade-from-unpackaged file
 # NOTE: order matters
 EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS = \
-	sql_bits/sfcgal.sql \
+	sql/sfcgal.sql \
 	../../utils/create_unpackaged.pl
 
 # Scripts making up the extension file
 # NOTE: order matters
 EXTENSION_SCRIPTS = \
-	sql_bits/sfcgal.sql \
-	sql_bits/sfcgal_comments.sql
+	sql/sfcgal.sql \
+	sql/sfcgal_comments.sql
 
 EXTRA_CLEAN = sql
 
@@ -63,15 +63,13 @@ sql/$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION_SCRIPTS) | sql
 	printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@
 	cat $^ > $@
 
-sql_bits/sfcgal.sql: ../../sfcgal/sfcgal.sql
-	mkdir -p sql_bits
+sql/sfcgal.sql: ../../sfcgal/sfcgal.sql | sql
 	$(PERL) -pe 's/BEGIN\;//g ; s/COMMIT\;//g' $< > $@
 
 ../../doc/sfcgal_comments.sql:
 	$(MAKE) -C ../../doc comments
 
-sql_bits/sfcgal_comments.sql: ../../doc/sfcgal_comments.sql
-	mkdir -p sql_bits
+sql/sfcgal_comments.sql: ../../doc/sfcgal_comments.sql | sql
 	cp $< $@
 
 sql/$(EXTENSION)--unpackaged.sql: Makefile | sql
@@ -84,22 +82,20 @@ sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: $(EXTENSION_UNPACKAGED_UPGRADE_
 	# Ensure version is correct
 	cat sql/$(EXTENSION)--ANY--$(EXTVERSION).sql > $@
 	cat $(EXTENSION_UNPACKAGED_UPGRADE_SCRIPTS) \
-		| $(PERL) ../../utils/create_unpackaged.pl ${EXTENSION} \
+		| $(PERL) @top_srcdir@/utils/create_unpackaged.pl ${EXTENSION} \
 		>> $@
 
-sql_bits/sfcgal_upgrade.sql : ../../sfcgal/sfcgal_upgrade.sql
-	mkdir -p sql_bits
+sql/sfcgal_upgrade.sql : ../../sfcgal/sfcgal_upgrade.sql | sql
 	$(PERL) -pe 's/BEGIN\;//g ; s/COMMIT\;//g' $< > $@
 
-sql_bits/sfcgal_upgrade_minor.sql: ../postgis_extension_helper.sql sql_bits/sfcgal_upgrade.sql ../../doc/sfcgal_comments.sql ../postgis_extension_helper_uninstall.sql
-	mkdir -p sql_bits
+sql/sfcgal_upgrade_minor.sql: ../postgis_extension_helper.sql sql/sfcgal_upgrade.sql ../../doc/sfcgal_comments.sql ../postgis_extension_helper_uninstall.sql | sql
 	printf '\\echo Use "CREATE EXTENSION $(EXTENSION)" to load this file. \\quit\n' > $@
 	cat $^ >> $@
 
 sql/$(EXTENSION)--ANY--$(EXTVERSION).sql: $(EXTENSION_UPGRADE_SCRIPTS)
 	cat $(EXTENSION_UPGRADE_SCRIPTS) > $@
 
-include ../upgrade-paths-rules.mk
+include @srcdir@/../upgrade-paths-rules.mk
 
 distclean: clean
 	rm Makefile
@@ -108,3 +104,5 @@ PG_CONFIG := @PG_CONFIG@
 PGXS := @PGXS@
 include $(PGXS)
 PERL = @PERL@
+
+VPATH = @srcdir@
diff --git a/extensions/postgis_tiger_geocoder/Makefile.in b/extensions/postgis_tiger_geocoder/Makefile.in
index d57d0bd49..bbf691875 100644
--- a/extensions/postgis_tiger_geocoder/Makefile.in
+++ b/extensions/postgis_tiger_geocoder/Makefile.in
@@ -1,4 +1,4 @@
-include ../upgradeable_versions.mk
+include @srcdir@/../upgradeable_versions.mk
 
 EXTENSION    = postgis_tiger_geocoder
 EXTVERSION    = @POSTGIS_LIB_VERSION@
@@ -82,7 +82,7 @@ sql/$(EXTENSION).sql: sql_bits/tiger_geocoder.sql  sql_bits/mark_editable_object
 sql/$(EXTENSION)--ANY--$(EXTVERSION).sql: ../postgis_extension_helper.sql sql_bits/remove_from_extension.sql.in sql/tiger_geocoder_upgrade_minor.sql sql_bits/mark_editable_objects.sql.in sql_bits/tiger_geocoder_comments.sql | sql
 	cat $^ > $@
 	echo "SELECT postgis_extension_drop_if_exists('${EXTENSION}', 'DROP SCHEMA tiger_data');" >> $@
-	cat ../postgis_extension_helper_uninstall.sql  >> $@
+	cat @srcdir@/../postgis_extension_helper_uninstall.sql  >> $@
 
 sql/$(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql: sql/$(EXTENSION)--$(EXTVERSION)--$(EXTVERSION)next.sql | sql
 	cp $< $@
@@ -91,7 +91,7 @@ sql/$(EXTENSION)--$(EXTVERSION)next--$(EXTVERSION).sql: sql/$(EXTENSION)--$(EXTV
 #strip CREATE SCHEMA since we force extension
 # to create schema by setting schema to tiger_geocoder in control
 #also remove tiger_data from extension if it is part of it
-sql_bits/tiger_geocoder_minor.sql.in: ../../extras/tiger_geocoder/utility/set_search_path.sql \
+sql/tiger_geocoder_minor.sql.in: ../../extras/tiger_geocoder/utility/set_search_path.sql \
   sql_bits/upgrade_before.sql.in \
   	../../extras/tiger_geocoder/geocode_settings.sql \
   ../../extras/tiger_geocoder/tiger_loader_2020.sql \
@@ -121,8 +121,8 @@ sql_bits/tiger_geocoder_minor.sql.in: ../../extras/tiger_geocoder/utility/set_se
 	../../extras/tiger_geocoder/geocode/geocode_intersection.sql \
 	../../extras/tiger_geocoder/geocode/geocode.sql \
 	../../extras/tiger_geocoder/geocode/reverse_geocode.sql \
-	../../extras/tiger_geocoder/geocode/census_tracts_functions.sql
-	mkdir -p sql_bits
+	../../extras/tiger_geocoder/geocode/census_tracts_functions.sql \
+	| sql
 	cat $^ > $@
 
 #also remove tiger_data from extension if it is part of it so data gets backed up
@@ -165,7 +165,7 @@ sql_bits/tiger_geocoder.sql.in: sql_bits/norm_addy_create.sql.in \
 	mkdir -p sql_bits
 	cat $^ > $@
 	echo "SELECT postgis_extension_drop_if_exists('${EXTENSION}', 'DROP SCHEMA tiger_data');" >> $@
-	cat ../postgis_extension_helper_uninstall.sql  >> $@
+	cat @srcdir@/../postgis_extension_helper_uninstall.sql  >> $@
 
 sql_bits/tiger_geocoder.sql: sql_bits/tiger_geocoder.sql.in
 	mkdir -p sql_bits
@@ -210,7 +210,7 @@ sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: sql_bits/tiger_geocoder--unpack
 #aggregates are special
 #they can be dropped but we need to remove
 #them from the extension first
-sql/tiger_geocoder_upgrade_minor.sql:  sql_bits/tiger_geocoder_minor.sql.in | sql
+sql/tiger_geocoder_upgrade_minor.sql:  sql/tiger_geocoder_minor.sql.in | sql
 	sed -e '/^\(CREATE\|ALTER\) \(CAST\|TYPE\|TABLE\|SCHEMA\|DOMAIN\|TRIGGER\).*;/d' \
 	 	 -e '/^\(CREATE\|ALTER\) \(CAST\|TYPE\|TABLE\|SCHEMA\|DOMAIN\|TRIGGER\)/,/\;/d' \
 	 	 -e 's/BEGIN;//g' -e 's/COMMIT;//g' \
@@ -251,3 +251,5 @@ PG_CONFIG := @PG_CONFIG@
 PGXS := @PGXS@
 include $(PGXS)
 PERL=@PERL@
+
+VPATH = @srcdir@
diff --git a/extensions/postgis_topology/Makefile.in b/extensions/postgis_topology/Makefile.in
index cad83f060..9eee66347 100644
--- a/extensions/postgis_topology/Makefile.in
+++ b/extensions/postgis_topology/Makefile.in
@@ -1,4 +1,4 @@
-include ../upgradeable_versions.mk
+include @srcdir@/../upgradeable_versions.mk
 
 EXTENSION     = postgis_topology
 EXTVERSION    = @POSTGIS_LIB_VERSION@
@@ -9,9 +9,9 @@ MODULEPATH    = $$libdir/$(EXTENSION)- at POSTGIS_MAJOR_VERSION@
 # NOTE: order matters
 EXTENSION_SCRIPTS = \
 	extlock.sql \
-	sql_bits/topology.sql \
+	sql/topology.sql \
 	sql_bits/mark_editable_objects.sql.in \
-	sql_bits/topology_comments.sql
+	sql/topology_comments.sql
 
 ifeq (@LIBINCLUDEMINORVERSION@,yes)
 MODULEPATH=$$libdir/$(EXTENSION)-$(MINORVERSION)
@@ -46,11 +46,10 @@ EXTENSION_UPGRADE_SCRIPTS = \
 	sql_bits/remove_from_extension.sql.in \
 	sql/topology_upgrade.sql \
 	sql_bits/mark_editable_objects.sql.in \
-	sql_bits/topology_comments.sql \
+	sql/topology_comments.sql \
 	../postgis_extension_helper_uninstall.sql
 
-SQL_BITS     = $(wildcard sql_bits/*.sql)
-EXTRA_CLEAN = sql/ ${SQL_BITS}
+EXTRA_CLEAN = sql/
 
 
 all: sql/$(EXTENSION)--$(EXTVERSION).sql sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql sql/$(EXTENSION)--ANY--$(EXTVERSION).sql
@@ -69,13 +68,13 @@ sql/$(EXTENSION)--$(EXTVERSION).sql: $(EXTENSION_SCRIPTS) | sql
 #strip BEGIN/COMMIT since these are not allowed in extensions
 #strip CREATE SCHEMA since we force extension
 # to create schema by setting schema to topology in control
-sql_bits/topology.sql: ../../topology/topology.sql
+sql/topology.sql: ../../topology/topology.sql | sql
 	sed -e 's/BEGIN;//g' -e 's/COMMIT;//g' -e '/^CREATE SCHEMA/d;'  $< > $@
 
 ../../doc/topology_comments.sql:
 	$(MAKE) -C ../../doc comments
 
-sql_bits/topology_comments.sql: ../../doc/topology_comments.sql
+sql/topology_comments.sql: ../../doc/topology_comments.sql | sql
 	cp $< $@
 
 sql/$(EXTENSION)--unpackaged.sql: Makefile | sql
@@ -84,7 +83,7 @@ sql/$(EXTENSION)--unpackaged.sql: Makefile | sql
 sql/$(EXTENSION)--unpackaged--$(EXTVERSION).sql: ../../topology/topology.sql ../../utils/create_unpackaged.pl sql/topology_upgrade.sql Makefile | sql
 	# Ugprade before packaging
 	cat sql/topology_upgrade.sql > $@
-	cat $< | $(PERL) ../../utils/create_unpackaged.pl postgis_topology >> $@
+	cat $< | $(PERL) @top_srcdir@/utils/create_unpackaged.pl postgis_topology >> $@
 
 #upgrade script should have everything but table, schema, type creation/alter
 #NOTE: we assume all object definitions end in ;
@@ -98,9 +97,9 @@ sql/topology_upgrade.sql:  ../../topology/topology_upgrade.sql | sql
 	sed -e 's/BEGIN;//g' -e 's/COMMIT;//g' -e '/^CREATE SCHEMA/d;'  $< > $@
 
 sql/$(EXTENSION)--ANY--$(EXTVERSION).sql: $(EXTENSION_UPGRADE_SCRIPTS)
-	cat $(EXTENSION_UPGRADE_SCRIPTS) > $@
+	cat $^ > $@
 
-include ../upgrade-paths-rules.mk
+include @srcdir@/../upgrade-paths-rules.mk
 
 distclean: clean
 	rm Makefile
@@ -109,3 +108,5 @@ PG_CONFIG := @PG_CONFIG@
 PGXS := @PGXS@
 include $(PGXS)
 PERL=@PERL@
+
+VPATH = @srcdir@
diff --git a/liblwgeom/Makefile.in b/liblwgeom/Makefile.in
index f0b6c6753..3112ea841 100644
--- a/liblwgeom/Makefile.in
+++ b/liblwgeom/Makefile.in
@@ -18,24 +18,30 @@
 # *
 # **********************************************************************
 # *
+# * Copyright 2022 Sandro Santilli <strk at kbt.io>
 # * Copyright 2008 Mark Cave-Ayland
 # *
 # **********************************************************************/
 
-CC = @CC@
-RYU_INCLUDE = -I../deps/ryu/..
-CPPFLAGS =  $(RYU_INCLUDE) @CPPFLAGS@
-CFLAGS = @CFLAGS@ @PICFLAGS@
-LDFLAGS = @LDFLAGS@ @GEOS_LDFLAGS@ @PROJ_LDFLAGS@ @JSON_LDFLAGS@
+srcdir = @srcdir@
+builddir = @builddir@
 top_builddir = @top_builddir@
 prefix = @prefix@
-exec_prefix = @exec_prefix@
 libdir = @libdir@
 includedir = @includedir@
+exec_prefix = @exec_prefix@
+
+CC = @CC@
+CPPFLAGS =  $(RYU_INCLUDE) @CPPFLAGS@ -I$(builddir) -I$(srcdir)
+CFLAGS = @CFLAGS@ @PICFLAGS@
+LDFLAGS = @LDFLAGS@ @GEOS_LDFLAGS@ @PROJ_LDFLAGS@ @JSON_LDFLAGS@
 SHELL = @SHELL@
 INSTALL = @INSTALL@
 LIBTOOL = @LIBTOOL@
 
+VPATH = $(srcdir):$(builddir)
+RYU_INCLUDE = -I$(srcdir)/../deps/ryu/..
+
 SOVER = @POSTGIS_MAJOR_VERSION at .@POSTGIS_MINOR_VERSION@
 
 IFACE_CURRENT = @LIBLWGEOM_CURRENT@
diff --git a/liblwgeom/cunit/Makefile.in b/liblwgeom/cunit/Makefile.in
index 59201d0b4..a382e2f3a 100644
--- a/liblwgeom/cunit/Makefile.in
+++ b/liblwgeom/cunit/Makefile.in
@@ -2,6 +2,8 @@
 # *
 # * PostGIS - Spatial Types for PostgreSQL
 # * http://postgis.net
+# *
+# * Copyright 2022 Sandro Santilli <strk at kbt.io>
 # * Copyright 2008 Paul Ramsey, Mark Cave-Ayland
 # *
 # * This is free software; you can redistribute and/or modify it under
@@ -9,16 +11,21 @@
 # *
 # **********************************************************************
 
-CC=@CC@
 top_builddir = @top_builddir@
+builddir = @builddir@
+srcdir = @srcdir@
+
+CC=@CC@
 SHELL = @SHELL@
 LIBTOOL = @LIBTOOL@
 
 CUNIT_LDFLAGS=@CUNIT_LDFLAGS@
-CUNIT_CPPFLAGS=-I.. @CUNIT_CPPFLAGS@ @CPPFLAGS@
+CUNIT_CPPFLAGS = -I$(srcdir)/.. -I$(builddir)/.. @CUNIT_CPPFLAGS@ @CPPFLAGS@
 CFLAGS=$(CUNIT_CPPFLAGS) @CFLAGS@
 LDFLAGS = @GEOS_LDFLAGS@ $(CUNIT_LDFLAGS)
 
+VPATH = $(srcdir)
+
 ifeq ($(CUNIT_WITH_VALGRIND), YES)
 	LIBTOOL_VALGRIND := valgrind $(CUNIT_VALGRIND_FLAGS)
 endif
diff --git a/libpgcommon/Makefile.in b/libpgcommon/Makefile.in
index f1722a9ba..fb66c6895 100644
--- a/libpgcommon/Makefile.in
+++ b/libpgcommon/Makefile.in
@@ -9,13 +9,18 @@
 # *
 # **********************************************************************
 
+srcdir = @srcdir@
+top_builddir = @top_builddir@
+
 CC=@CC@
-CFLAGS= -I../liblwgeom @CPPFLAGS@ @CFLAGS@ @PGSQL_BE_CPPFLAGS@ @PROJ_CPPFLAGS@ @PICFLAGS@ @GETTEXT_CFLAGS@
+CFLAGS= -I$(srcdir)/../liblwgeom -I$(top_builddir)/liblwgeom @CPPFLAGS@ @CFLAGS@ @PGSQL_BE_CPPFLAGS@ @PROJ_CPPFLAGS@ @PICFLAGS@ @GETTEXT_CFLAGS@
 LDFLAGS=@GETTEXT_LDFLAGS@ @LIBINTL@
 
 YACC=@YACC@
 LEX=@LEX@
 
+VPATH = $(srcdir)
+
 # Standalone COMMON objects
 SA_OBJS = \
 	gserialized_gist.o \
diff --git a/loader/Makefile.in b/loader/Makefile.in
index 527e1779d..1ba58284c 100644
--- a/loader/Makefile.in
+++ b/loader/Makefile.in
@@ -2,7 +2,9 @@
 # *
 # * PostGIS - Spatial Types for PostgreSQL
 # * http://postgis.net
+# *
 # * Copyright 2008 Mark Cave-Ayland
+# * Copyright (c) 2020 Sandro Santilli <strk at kbt.io>
 # *
 # * This is free software; you can redistribute and/or modify it under
 # * the terms of the GNU General Public Licence. See the COPYING file.
@@ -19,11 +21,16 @@ PG_CONFIG := @PG_CONFIG@
 PGXS := @PGXS@
 include $(PGXS)
 
+top_builddir = @top_builddir@
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+
+VPATH = $(srcdir)
+
 # Set CFLAGS afer PGXS, otherwise it will get overwritten with the PGXS
 # version which is not what we want.
 CC=@CC@
-CFLAGS= -I ../liblwgeom @CPPFLAGS@ @CFLAGS@ @PICFLAGS@ @PROJ_CPPFLAGS@
-top_builddir = @top_builddir@
+CFLAGS= -I$(top_srcdir)/liblwgeom -I$(top_builddir)/liblwgeom @CPPFLAGS@ @CFLAGS@ @PICFLAGS@ @PROJ_CPPFLAGS@
 SHELL = @SHELL@
 INSTALL = @INSTALL@
 LIBTOOL = @LIBTOOL@
@@ -104,7 +111,7 @@ $(PGSQL2SHP-CLI): $(SHPLIB_OBJS) pgsql2shp-core.o pgsql2shp-cli.o $(LIBLWGEOM)
 	  $(CC) $(CFLAGS) $^ $(LDFLAGS) $(ICONV_LDFLAGS) $(PGSQL_FE_LDFLAGS) $(GETTEXT_LDFLAGS) -o $@
 
 $(POSTGIS-CLI): postgis.pl
-	cp postgis.pl postgis; chmod +x postgis
+	cp $< $@; chmod +x $@
 
 $(SHP2PGSQL-CLI): $(SHPLIB_OBJS) shp2pgsql-core.o shp2pgsql-cli.o $(LIBLWGEOM)
 	$(LIBTOOL) --mode=link \
diff --git a/postgis/Makefile.in b/postgis/Makefile.in
index dbf1e4b36..ecc92b7a3 100644
--- a/postgis/Makefile.in
+++ b/postgis/Makefile.in
@@ -36,7 +36,7 @@ endif
 
 # Files to be copied to the contrib/ directory
 SQL_built=postgis.sql uninstall_postgis.sql postgis_upgrade.sql legacy.sql uninstall_legacy.sql legacy_minimal.sql legacy_gist.sql
-DATA=../spatial_ref_sys.sql
+DATA=@top_srcdir@/spatial_ref_sys.sql
 
 # SQL objects (files requiring pre-processing)
 SQL_OBJS = \
@@ -57,15 +57,15 @@ WAGYU_LIBPATH = ../deps/wagyu/@WAGYU_LIB@
 
 ifeq (@HAVE_PROTOBUF@,yes)
 PROTOBUF_OBJ = vector_tile.pb-c.o geobuf.pb-c.o
-UTHASH_INCLUDE = -I../deps/uthash/include
+UTHASH_INCLUDE = -I at top_srcdir@/deps/uthash/include
 
-WAYGU_INCLUDE = -I../deps/wagyu
+WAYGU_INCLUDE = -I at top_srcdir@/deps/wagyu
 WAYGU_LIB = $(WAGYU_LIBPATH) @WAGYU_LDFLAGS@
 WAGYU_DEP = $(WAGYU_LIBPATH)
 endif
 
 FLATGEOBUF_LIBPATH = ../deps/flatgeobuf/@FLATGEOBUF_LIB@
-FLATGEOBUF_INCLUDE = -I../deps/flatgeobuf
+FLATGEOBUF_INCLUDE = -I at top_srcdir@/deps/flatgeobuf
 FLATGEOBUF_LIB = $(FLATGEOBUF_LIBPATH) @FLATGEOBUF_LDFLAGS@
 FLATGEOBUF_DEP = $(FLATGEOBUF_LIBPATH)
 
@@ -143,7 +143,7 @@ OBJS=$(PG_OBJS)
 # to an existing liblwgeom.so in the PostgreSQL $libdir supplied by an
 # older version of PostGIS, rather than with the static liblwgeom.a
 # supplied with newer versions of PostGIS
-PG_CPPFLAGS += -I../liblwgeom @CFLAGS@ -I../libpgcommon $(FLATGEOBUF_INCLUDE) $(WAYGU_INCLUDE) $(UTHASH_INCLUDE) @CPPFLAGS@ @PICFLAGS@
+PG_CPPFLAGS += -I at top_srcdir@/liblwgeom -I at top_builddir@/liblwgeom @CFLAGS@ -I at top_srcdir@/libpgcommon $(FLATGEOBUF_INCLUDE) $(WAYGU_INCLUDE) $(UTHASH_INCLUDE) @CPPFLAGS@ @PICFLAGS@
 SHLIB_LINK_F = $(WAYGU_LIB) $(FLATGEOBUF_LIB) ../libpgcommon/libpgcommon.a ../liblwgeom/.libs/liblwgeom.a @SHLIB_LINK@
 
 # Extra files to remove during 'make clean'
@@ -166,6 +166,8 @@ PGXS := @PGXS@
 NO_TEMP_INSTALL=yes
 include $(PGXS)
 
+VPATH := @srcdir@
+
 # Set PERL _after_ the include of PGXS
 PERL=@PERL@
 
@@ -217,11 +219,11 @@ PROTOCC=@PROTOCC@
 
 # Generate Mapbox Vector Tile encoder/decoder using protobuf-c compiler
 vector_tile.pb-c.c vector_tile.pb-c.h: vector_tile.proto
-	$(PROTOCC) --c_out=. $<
+	$(PROTOCC) -I at srcdir@ --c_out=. $<
 
 # Generate Geobuf encoder/decoder using protobuf-c compiler
 geobuf.pb-c.c geobuf.pb-c.h: geobuf.proto
-	$(PROTOCC) --c_out=. $<
+	$(PROTOCC) -I at srcdir@ --c_out=. $<
 
 ifeq (@HAVE_PROTOBUF@,yes)
 lwgeom_out_mvt.o: vector_tile.pb-c.h
@@ -234,12 +236,12 @@ endif
 # and adding the version number
 # replace @extschema at . with nothing, this is only used as placeholder for extension install
 %.sql: %.sql.in
-	$(SQLPP) -I../libpgcommon $< | grep -v '^#' | \
+	$(SQLPP) -I at top_srcdir@/libpgcommon -I at builddir@ $< | grep -v '^#' | \
 	$(PERL) -lpe "s'MODULE_PATHNAME'\$(MODULEPATH)'g;s'@extschema@\.''g" > $@
 
 #this is redundant but trying to fold in with extension just hangs
 postgis_upgrade.sql.in: postgis.sql ../utils/postgis_proc_upgrade.pl
-	$(PERL) ../utils/postgis_proc_upgrade.pl $< UNUSED > $@
+	$(PERL) @top_srcdir@/utils/postgis_proc_upgrade.pl $< UNUSED > $@
 
 
 postgis_upgrade.sql: postgis_before_upgrade.sql postgis_upgrade.sql.in postgis_after_upgrade.sql
@@ -253,10 +255,10 @@ $(SQL_OBJS): ../postgis_config.h ../postgis_revision.h
 #postgis.sql.in: sqldefines.h long_xact.sql.in.c geography.sql.in.c
 
 uninstall_postgis.sql: postgis.sql ../utils/create_undef.pl
-	$(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
+	$(PERL) @top_srcdir@/utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
 
 uninstall_legacy.sql: legacy.sql ../utils/create_undef.pl
-	$(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
+	$(PERL) @top_srcdir@/utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
 
 distclean: clean
 	rm -f Makefile
diff --git a/raster/loader/Makefile.in b/raster/loader/Makefile.in
index 3df47a96f..55d1dd187 100644
--- a/raster/loader/Makefile.in
+++ b/raster/loader/Makefile.in
@@ -2,7 +2,7 @@
 #
 # Copyright (c) 2011 Regents of the University of California
 #   <bkpark at ucdavis.edu>
-# Copyright (c) 2009 Sandro Santilli <strk at kbt.io>
+# Copyright (c) 2009-2022 Sandro Santilli <strk at kbt.io>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -20,10 +20,13 @@
 #
 #############################################################################
 
-# Set CFLAGS after PGXS, otherwise it will get overwritten with the PGXS
-# version which is not what we want.
-CC=@CC@
 top_builddir = @top_builddir@
+builddir = @builddir@
+srcdir = @srcdir@
+
+VPATH = $(srcdir)
+
+CC=@CC@
 SHELL = @SHELL@
 INSTALL = @INSTALL@
 LIBTOOL = @LIBTOOL@
@@ -34,10 +37,8 @@ RASTER2PGSQL=raster2pgsql at EXESUFFIX@
 # PostgreSQL executable directory
 PGSQL_BINDIR=@PGSQL_BINDIR@
 
-RT_CORE=../rt_core
-
-LIBLWGEOM_LDFLAGS= -static ../../liblwgeom/liblwgeom.la
-LIBLWGEOM_CFLAGS=-I../../liblwgeom
+LIBLWGEOM_LDFLAGS = -static $(top_builddir)/liblwgeom/liblwgeom.la
+LIBLWGEOM_CFLAGS = -I$(top_buidldir)/liblwgeom
 LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@
 LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@
 LIBGDAL_DEPLIBS_LDFLAGS=@LIBGDAL_DEPLIBS_LDFLAGS@
@@ -45,8 +46,8 @@ PROJ_CFLAGS=@PROJ_CPPFLAGS@
 GEOS_CFLAGS=@GEOS_CPPFLAGS@
 GEOS_LDFLAGS=@GEOS_LDFLAGS@
 
-RTCORE_CFLAGS=-I$(RT_CORE)
-RTCORE_LDFLAGS=$(RT_CORE)/librtcore.a
+RTCORE_CFLAGS = -I$(srcdir)/../rt_core
+RTCORE_LDFLAGS = $(builddir)/../rt_core/librtcore.a
 
 # GetText includes and libraries
 GETTEXT_CFLAGS = @GETTEXT_CFLAGS@
@@ -56,6 +57,8 @@ GETTEXT_LDFLAGS = @GETTEXT_LDFLAGS@ @LIBINTL@
 ICONV_LDFLAGS=@ICONV_LDFLAGS@
 ICONV_CFLAGS=@ICONV_CFLAGS@
 
+CPPFLAGS = -I$(builddir)
+
 CFLAGS = \
 	@CFLAGS@ @PICFLAGS@ \
 	$(RTCORE_CFLAGS) \
@@ -80,7 +83,7 @@ all: $(RASTER2PGSQL)
 raster2pgsql.o: raster2pgsql.c
 	$(CC) $(CPPFLAGS) $(CFLAGS) -c $<
 
-$(RASTER2PGSQL): $(RT_CORE)/librtcore.a raster2pgsql.o
+$(RASTER2PGSQL): ../rt_core/librtcore.a raster2pgsql.o
 	$(LIBTOOL) --mode=link $(CC) $(CFLAGS) $^ $(LDFLAGS) -o $@
 
 installdir:
@@ -92,8 +95,8 @@ install: installdir
 uninstall:
 	$(LIBTOOL) --mode=uninstall $(RM) "$(DESTDIR)$(PGSQL_BINDIR)/$(RASTER2PGSQL)"
 
-$(RT_CORE)/librtcore.a:
-	$(MAKE) -C ../rt_core
+../rt_core/librtcore.a:
+	$(MAKE) -C $(buidldir)/../rt_core
 
 clean:
 	rm -rf .libs
diff --git a/raster/rt_core/Makefile.in b/raster/rt_core/Makefile.in
index 0580a6127..711677bc9 100644
--- a/raster/rt_core/Makefile.in
+++ b/raster/rt_core/Makefile.in
@@ -1,6 +1,6 @@
 #############################################################################
 #
-# Copyright (c) 2009 Sandro Santilli <strk at kbt.io>
+# Copyright (c) 2009-2022 Sandro Santilli <strk at kbt.io>
 #
 # This program is free software; you can redistribute it and/or
 # modify it under the terms of the GNU General Public License
@@ -18,11 +18,16 @@
 #
 #############################################################################
 
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+builddir = @builddir@
+top_builddir = @top_builddir@
+
 AR = ar rs
 
 CC = @CC@
-LIBLWGEOM_LDFLAGS = ../../liblwgeom/.libs/liblwgeom.a
-LIBLWGEOM_CFLAGS = -I../../liblwgeom
+LIBLWGEOM_LDFLAGS = $(top_builddir)/liblwgeom/.libs/liblwgeom.a
+LIBLWGEOM_CFLAGS = -I$(top_srcdir)/liblwgeom -I$(top_builddir)/liblwgeom -I$(builddir)
 LIBGDAL_CFLAGS = @LIBGDAL_CFLAGS@
 LIBGDAL_LDFLAGS = @LIBGDAL_LDFLAGS@
 GEOS_LDFLAGS = @GEOS_LDFLAGS@
@@ -53,6 +58,8 @@ RT_HEADERS = \
 	librtcore_internal.h \
 	../raster_config.h
 
+VPATH = $(srcdir)
+
 all: $(RT_LIB)
 
 $(RT_OBJS): $(RT_HEADERS)
diff --git a/raster/rt_pg/Makefile.in b/raster/rt_pg/Makefile.in
index 96a5a3702..c4ba032a6 100644
--- a/raster/rt_pg/Makefile.in
+++ b/raster/rt_pg/Makefile.in
@@ -66,17 +66,17 @@ OBJS = \
 # older version of PostGIS, rather than with the static liblwgeom.a
 # supplied with newer versions of PostGIS
 #
-LIBLWGEOM_LDFLAGS=../../liblwgeom/.libs/liblwgeom.a
-LIBLWGEOM_CFLAGS="-I../../liblwgeom"
-LIBPGCOMMON_CFLAGS="-I../../libpgcommon"
-LIBPGCOMMON_LDFLAGS=../../libpgcommon/libpgcommon.a
+LIBLWGEOM_LDFLAGS = @top_builddir@/liblwgeom/.libs/liblwgeom.a
+LIBLWGEOM_CFLAGS = -I at top_srcdir@/liblwgeom -I at top_builddir@/liblwgeom
+LIBPGCOMMON_CFLAGS = -I at top_srcdir@/libpgcommon
+LIBPGCOMMON_LDFLAGS = @top_builddir@/libpgcommon/libpgcommon.a
 LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@
 LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@
 LIBPROJ_CFLAGS=@PROJ_CPPFLAGS@
 
 CC = @CC@
-PG_CPPFLAGS+= $(LIBLWGEOM_CFLAGS) @CPPFLAGS@ @CFLAGS@ $(LIBGDAL_CFLAGS) $(LIBPGCOMMON_CFLAGS) $(LIBPROJ_CFLAGS) -I../rt_core
-SHLIB_LINK_F = ../rt_core/librtcore.a $(LIBLWGEOM_LDFLAGS) $(LIBPGCOMMON_LDFLAGS) $(LIBGDAL_LDFLAGS) @SHLIB_LINK@
+PG_CPPFLAGS+= $(LIBLWGEOM_CFLAGS) @CPPFLAGS@ @CFLAGS@ $(LIBGDAL_CFLAGS) $(LIBPGCOMMON_CFLAGS) $(LIBPROJ_CFLAGS) -I at srcdir@/../rt_core
+SHLIB_LINK_F = @builddir@/../rt_core/librtcore.a $(LIBLWGEOM_LDFLAGS) $(LIBPGCOMMON_LDFLAGS) $(LIBGDAL_LDFLAGS) @SHLIB_LINK@
 
 # Extra files to remove during 'make clean'
 EXTRA_CLEAN=$(SQL_OBJS) $(DATA_built) rtpostgis_upgrade.sql.in
@@ -89,6 +89,8 @@ PGXS := @PGXS@
 NO_TEMP_INSTALL=yes
 include $(PGXS)
 
+VPATH = @srcdir@
+
 # Utility rule for use from outside
 sql_objs: $(DATA_built)
 
@@ -113,7 +115,7 @@ endif
 # and adding the version number
 # replace @extschema at . with nothing, this is only used as placeholder for extension install
 %.sql: %.sql.in
-	$(SQLPP) -I../../postgis/ -I../../ $< | grep -v '^#' | \
+	$(SQLPP) -I at top_builddir@/postgis/ $< | grep -v '^#' | \
 	$(PERL) -lpe "s'MODULE_PATHNAME'\$(MODULEPATH)'g;s'@extschema@\.''g" > $@
 
 ../../liblwgeom/.libs/liblwgeom.a:
@@ -135,7 +137,7 @@ $(SQL_OBJS): ../../postgis/sqldefines.h ../../postgis_revision.h
 
 #this is redundant but trying to fold in with the  other just hangs
 rtpostgis_upgrade.sql.in: rtpostgis.sql ../../utils/postgis_proc_upgrade.pl
-	$(PERL) ../../utils/postgis_proc_upgrade.pl $< UNUSED > $@
+	$(PERL) @top_srcdir@/utils/postgis_proc_upgrade.pl $< UNUSED > $@
 
 rtpostgis_upgrade.sql: rtpostgis_upgrade_cleanup.sql rtpostgis_upgrade.sql.in rtpostgis_drop.sql
 	echo 'BEGIN;' > $@
@@ -143,7 +145,7 @@ rtpostgis_upgrade.sql: rtpostgis_upgrade_cleanup.sql rtpostgis_upgrade.sql.in rt
 	echo 'COMMIT;' >> $@
 
 uninstall_rtpostgis.sql: rtpostgis.sql ../../utils/create_undef.pl
-	$(PERL) ../../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
+	$(PERL) @top_srcdir@/utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
 
 distclean: clean
 	rm -f Makefile
diff --git a/raster/rt_pg/rtpostgis.sql.in b/raster/rt_pg/rtpostgis.sql.in
index baac9d676..1be585ddb 100644
--- a/raster/rt_pg/rtpostgis.sql.in
+++ b/raster/rt_pg/rtpostgis.sql.in
@@ -34,7 +34,7 @@
 --
 -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
-#include "../../postgis/sqldefines.h"
+#include "sqldefines.h"
 
 -- INSTALL VERSION: POSTGIS_LIB_VERSION
 
diff --git a/raster/test/cunit/Makefile.in b/raster/test/cunit/Makefile.in
index 53427fa7f..8ab246acd 100644
--- a/raster/test/cunit/Makefile.in
+++ b/raster/test/cunit/Makefile.in
@@ -9,15 +9,17 @@
 # *
 # **********************************************************************
 
-CC=@CC@
 top_builddir = @top_builddir@
+top_srcdir = @top_srcdir@
+builddir = @builddir@
+srcdir = @srcdir@
+
+CC=@CC@
 SHELL = @SHELL@
 LIBTOOL = @LIBTOOL@
 
-RT_CORE=../../rt_core
-
 LIBLWGEOM_LDFLAGS=../../../liblwgeom/.libs/liblwgeom.a
-LIBLWGEOM_CFLAGS=-I../../../liblwgeom
+LIBLWGEOM_CFLAGS = -I$(top_srcdir)/liblwgeom -I$(top_builddir)/liblwgeom
 LIBGDAL_CFLAGS=@LIBGDAL_CFLAGS@
 LIBGDAL_LDFLAGS=@LIBGDAL_LDFLAGS@
 PROJ_CFLAGS=@PROJ_CPPFLAGS@
@@ -26,12 +28,15 @@ GEOS_CFLAGS=@GEOS_CPPFLAGS@
 GEOS_LDFLAGS=@GEOS_LDFLAGS@
 CUNIT_LDFLAGS=@CUNIT_LDFLAGS@
 
-RTCORE_CFLAGS=-I$(RT_CORE)
-RTCORE_LDFLAGS=$(RT_CORE)/librtcore.a
+RTCORE_CFLAGS = -I$(top_srcdir)/raster/rt_core
+RTCORE_LDFLAGS = $(top_builddir)/raster/rt_core/librtcore.a
+
+VPATH = $(srcdir)
 
 CC=@CC@
 CFLAGS = \
-	-I.. \
+	-I$(builddir) \
+	-I$(builddir)/.. \
 	$(LIBLWGEOM_CFLAGS) \
 	$(RTCORE_CFLAGS) \
 	$(PROJ_CFLAGS) \
@@ -80,15 +85,15 @@ check: cu_tester
 endif
 
 # Build the main unit test executable
-cu_tester: $(RT_CORE)/librtcore.a $(OBJS)
+cu_tester: $(top_builddir)/raster/rt_core/librtcore.a $(OBJS)
 	$(LIBTOOL) --mode=link $(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS) $(CUNIT_LDFLAGS)
 
 # Command to build each of the .o files
 $(OBJS): %.o: %.c
 	$(CC) $(CFLAGS) -c -o $@ $<
 
-$(RT_CORE)/librtcore.a:
-	$(MAKE) -C ../../rt_core
+$(top_builddir)/raster/rt_core/librtcore.a:
+	$(MAKE) -C $(top_builddir)/raster/rt_core
 
 # Clean target
 clean:
diff --git a/raster/test/regress/Makefile.in b/raster/test/regress/Makefile.in
index 91173802e..a932ab857 100644
--- a/raster/test/regress/Makefile.in
+++ b/raster/test/regress/Makefile.in
@@ -24,6 +24,9 @@
 #
 #############################################################################
 
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
+
 POSTGIS_SRC=../../..
 PERL=@PERL@
 
@@ -180,10 +183,10 @@ rtpostgis.sql: ../../rt_pg/rtpostgis.sql
 	$(PERL) -lpe "s'\\\$$libdir'$(REGRESS_INSTALLDIR)/lib'g" $< > $@
 
 
-topsrcdir = $(realpath ../../../)
-srcdir = $(realpath .)
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
 
-include tests.mk
-include ../../../regress/runtest.mk
+include $(srcdir)/tests.mk
+include $(top_srcdir)/regress/runtest.mk
 
 check: check-regress
diff --git a/regress/Makefile.in b/regress/Makefile.in
index c1449f374..9fe11f4a0 100644
--- a/regress/Makefile.in
+++ b/regress/Makefile.in
@@ -3,13 +3,18 @@
 # * PostGIS - Spatial Types for PostgreSQL
 # * http://postgis.net
 # *
-# * Copyright (C) 2018 Sandro Santilli <strk at kbt.io>
+# * Copyright (C) 2018-2022 Sandro Santilli <strk at kbt.io>
 # *
 # * This is free software; you can redistribute and/or modify it under
 # * the terms of the GNU General Public Licence. See the COPYING file.
 # *
 # **********************************************************************
 
+top_srcdir = @top_srcdir@
+top_builddir = @top_builddir@
+builddir = @builddir@
+srcdir = @srcdir@
+
 PERL=@PERL@
 MINGWBUILD=@MINGWBUILD@
 HAVE_SFCGAL=@HAVE_SFCGAL@
@@ -18,15 +23,7 @@ POSTGIS_MAJOR_VERSION=@POSTGIS_MAJOR_VERSION@
 POSTGIS_MINOR_VERSION=@POSTGIS_MINOR_VERSION@
 POSTGIS_MICRO_VERSION=@POSTGIS_MICRO_VERSION@
 
-topsrcdir = $(realpath ../)
-
-# Where we put our regression installation
-ifeq ($(MINGWBUILD),1)
-	srcdir=$(shell bash -c "pwd -W")
-else
-	srcdir=$(shell pwd)
-endif
-REGRESS_INSTALLDIR=$(srcdir)/00-regress-install
+REGRESS_INSTALLDIR = $(realpath $(builddir) )/00-regress-install
 
 # MingW hack: rather than use PGSQL_BINDIR directly, we change to the directory and
 # then use "pwd" to return the path. This ensures that the returned path is in MSYS
@@ -45,11 +42,14 @@ check: check-regress
 
 check-unit:
 
-include core/tests.mk
-include loader/tests.mk
-include dumper/tests.mk
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
+
+include $(builddir)/core/tests.mk
+include $(srcdir)/loader/tests.mk
+include $(srcdir)/dumper/tests.mk
 
-include runtest.mk
+include $(srcdir)/runtest.mk
 
 clean:
 	rm -rf $(REGRESS_INSTALLDIR)
diff --git a/regress/core/Makefile.in b/regress/core/Makefile.in
index dd1434c81..f7e5b848e 100644
--- a/regress/core/Makefile.in
+++ b/regress/core/Makefile.in
@@ -10,11 +10,16 @@
 # *
 # **********************************************************************
 
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
+builddir = @builddir@
+
 PERL=@PERL@
 
-topsrcdir = $(realpath ../../)
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
 
-include tests.mk
-include ../runtest.mk
+include $(builddir)/tests.mk
+include $(top_srcdir)/regress/runtest.mk
 
-check: check-regress
\ No newline at end of file
+check: check-regress
diff --git a/regress/dumper/Makefile.in b/regress/dumper/Makefile.in
index b6f4013c5..70d77e032 100644
--- a/regress/dumper/Makefile.in
+++ b/regress/dumper/Makefile.in
@@ -3,18 +3,23 @@
 # * PostGIS - Spatial Types for PostgreSQL
 # * http://postgis.net
 # *
-# * Copyright (C) 2020 Sandro Santilli <strk at kbt.io>
+# * Copyright (C) 2020-2022 Sandro Santilli <strk at kbt.io>
 # *
 # * This is free software; you can redistribute and/or modify it under
 # * the terms of the GNU General Public Licence. See the COPYING file.
 # *
 # **********************************************************************
 
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
+builddir = @builddir@
+
 PERL=@PERL@
 
-topsrcdir = $(realpath ../../)
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
 
-include tests.mk
-include ../runtest.mk
+include $(srcdir)/tests.mk
+include $(top_srcdir)/regress/runtest.mk
 
 check: check-regress
diff --git a/regress/loader/Makefile.in b/regress/loader/Makefile.in
index d8e6b3b23..f35be7a27 100644
--- a/regress/loader/Makefile.in
+++ b/regress/loader/Makefile.in
@@ -3,19 +3,24 @@
 # * PostGIS - Spatial Types for PostgreSQL
 # * http://postgis.net
 # *
-# * Copyright (C) 2020 Sandro Santilli <strk at kbt.io>
+# * Copyright (C) 2020-2022 Sandro Santilli <strk at kbt.io>
 # *
 # * This is free software; you can redistribute and/or modify it under
 # * the terms of the GNU General Public Licence. See the COPYING file.
 # *
 # **********************************************************************
 
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
+builddir = @builddir@
+
 PERL=@PERL@
 
-topsrcdir = $(realpath ../../)
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
 
-include tests.mk
+include $(srcdir)/tests.mk
 
-include ../runtest.mk
+include $(top_srcdir)/regress/runtest.mk
 
 check: check-regress
diff --git a/regress/runtest.mk b/regress/runtest.mk
index bfad91b7e..6795bd1b8 100644
--- a/regress/runtest.mk
+++ b/regress/runtest.mk
@@ -1,15 +1,27 @@
-abstopsrcdir := $(realpath $(topsrcdir))
+# **********************************************************************
+# *
+# * PostGIS - Spatial Types for PostgreSQL
+# * http://postgis.net
+# *
+# * Copyright (C) 2020-2022 Sandro Santilli <strk at kbt.io>
+# *
+# * This is free software; you can redistribute and/or modify it under
+# * the terms of the GNU General Public Licence. See the COPYING file.
+# *
+# **********************************************************************
+
+abstopsrcdir := $(realpath $(top_srcdir))
 abssrcdir := $(realpath .)
 
 TESTS := $(patsubst $(topsrcdir)/%,$(abstopsrcdir)/%,$(TESTS))
 TESTS := $(patsubst $(abssrcdir)/%,./%,$(TESTS))
 
+.PHONY: check-regress
 check-regress:
-
 	@echo "RUNTESTFLAGS: $(RUNTESTFLAGS)"
 	@echo "RUNTESTFLAGS_INTERNAL: $(RUNTESTFLAGS_INTERNAL)"
 
-	@$(PERL) $(topsrcdir)/regress/run_test.pl $(RUNTESTFLAGS) $(RUNTESTFLAGS_INTERNAL) $(TESTS)
+	POSTGIS_TOP_BUILD_DIR=$(top_builddir) $(PERL) $(topsrcdir)/regress/run_test.pl $(RUNTESTFLAGS) $(RUNTESTFLAGS_INTERNAL) $(TESTS)
 
 	@if echo "$(RUNTESTFLAGS)" | grep -vq -- --upgrade; then \
 		echo "Running upgrade test as RUNTESTFLAGS did not contain that"; \
diff --git a/sfcgal/Makefile.in b/sfcgal/Makefile.in
index 000588fc8..0c8cec8a4 100644
--- a/sfcgal/Makefile.in
+++ b/sfcgal/Makefile.in
@@ -55,30 +55,8 @@ OBJS = lwgeom_sfcgal.o
 # to an existing liblwgeom.so in the PostgreSQL $libdir supplied by an
 # older version of PostGIS, rather than with the static liblwgeom.a
 # supplied with newer versions of PostGIS
-PG_CPPFLAGS += -I../liblwgeom -I../libpgcommon @CFLAGS@ @CPPFLAGS@ @PICFLAGS@
-SHLIB_LINK_F = ../libpgcommon/libpgcommon.a ../liblwgeom/.libs/liblwgeom.a @SHLIB_LINK@
-
-# Add SFCGAL Flags if defined
-ifeq (@SFCGAL@,sfcgal)
-PG_CPPFLAGS += @SFCGAL_CPPFLAGS@
-SHLIB_LINK_F += @SFCGAL_LDFLAGS@
-endif
-
-# This is to workaround a bug in PGXS 8.4 win32 link line,
-# see http://trac.osgeo.org/postgis/ticket/1158#comment:57
-SHLIB_LINK := $(SHLIB_LINK_F) $(SHLIB_LINK)
-
-# PGXS information
-PG_CONFIG := @PG_CONFIG@
-PGXS := @PGXS@
-
-# Note: we specify liblwgeom.a directly in SHLIB_LINK rather than using
-# -L... -l options to prevent issues with some platforms trying to link
-# to an existing liblwgeom.so in the PostgreSQL $libdir supplied by an
-# older version of PostGIS, rather than with the static liblwgeom.a
-# supplied with newer versions of PostGIS
-PG_CPPFLAGS += -I../liblwgeom -I../libpgcommon @CFLAGS@ @CPPFLAGS@ @PICFLAGS@
-SHLIB_LINK_F = ../libpgcommon/libpgcommon.a ../liblwgeom/.libs/liblwgeom.a @SHLIB_LINK@
+PG_CPPFLAGS += -I at top_builddir@/liblwgeom -I at top_srcdir@/liblwgeom -I at top_srcdir@/libpgcommon @CFLAGS@ @CPPFLAGS@ @PICFLAGS@
+SHLIB_LINK_F = @top_builddir@/libpgcommon/libpgcommon.a @top_builddir@/liblwgeom/.libs/liblwgeom.a @SHLIB_LINK@
 
 # Add SFCGAL Flags if defined
 ifeq (@SFCGAL@,sfcgal)
@@ -102,6 +80,8 @@ PGXS := @PGXS@
 NO_TEMP_INSTALL=yes
 include $(PGXS)
 
+VPATH := @srcdir@
+
 # Set PERL _after_ the include of PGXS
 PERL=@PERL@
 
@@ -142,11 +122,11 @@ $(SQL_OBJS): ../postgis_config.h ../postgis_revision.h
 # and adding the version number
 # replace @extschema at . with nothing, this is only used as placeholder for extension install
 %.sql: %.sql.in
-	$(SQLPP) -I../libpgcommon $< | grep -v '^#' | \
+	$(SQLPP) -I at top_builddir@/postgis $< | grep -v '^#' | \
 	$(PERL) -lpe "s'MODULE_PATHNAME'\$(MODULEPATH)'g;s'@extschema@\.''g" > $@
 
 sfcgal_upgrade.sql.in: sfcgal.sql ../utils/postgis_proc_upgrade.pl
-	$(PERL) ../utils/postgis_proc_upgrade.pl $< UNUSED > $@
+	$(PERL) @top_srcdir@/utils/postgis_proc_upgrade.pl $< UNUSED > $@
 
 sfcgal_upgrade.sql: sfcgal_before_upgrade.sql sfcgal_upgrade.sql.in sfcgal_after_upgrade.sql
 	echo "BEGIN;" > $@
@@ -154,10 +134,10 @@ sfcgal_upgrade.sql: sfcgal_before_upgrade.sql sfcgal_upgrade.sql.in sfcgal_after
 	echo "COMMIT;" >> $@
 
 uninstall_sfcgal_legacy.sql: sfcgal_legacy.sql ../utils/create_undef.pl
-	$(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
+	$(PERL) @top_srcdir@/utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
 
 uninstall_sfcgal.sql: sfcgal.sql ../utils/create_undef.pl
-	$(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
+	$(PERL) @top_srcdir@/utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
 
 distclean: clean
 	rm -f Makefile
diff --git a/sfcgal/regress/Makefile.in b/sfcgal/regress/Makefile.in
index e120ec200..4871ed746 100644
--- a/sfcgal/regress/Makefile.in
+++ b/sfcgal/regress/Makefile.in
@@ -3,20 +3,25 @@
 # * PostGIS - Spatial Types for PostgreSQL
 # * http://postgis.net
 # *
-# * Copyright (C) 2020 Sandro Santilli <strk at kbt.io>
+# * Copyright (C) 2020-2022 Sandro Santilli <strk at kbt.io>
 # *
 # * This is free software; you can redistribute and/or modify it under
 # * the terms of the GNU General Public Licence. See the COPYING file.
 # *
 # **********************************************************************
 
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
+builddir = @builddir@
+
 PERL=@PERL@
 
 override RUNTESTFLAGS := $(RUNTESTFLAGS) --sfcgal
 
-topsrcdir = $(realpath ../../)
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
 
-include tests.mk
-include ../../regress/runtest.mk
+include $(srcdir)/tests.mk
+include $(top_srcdir)/regress/runtest.mk
 
 check: check-regress
diff --git a/topology/Makefile.in b/topology/Makefile.in
index 07c6993dc..25677d253 100644
--- a/topology/Makefile.in
+++ b/topology/Makefile.in
@@ -3,7 +3,7 @@
 # * PostGIS - Spatial Types for PostgreSQL
 # * http://postgis.net
 # *
-# * Copyright (C) 2010-2011 Sandro Santilli <strk at kbt.io>
+# * Copyright (C) 2010-2022 Sandro Santilli <strk at kbt.io>
 # * Copyright (C) 2008 Mark Cave-Ayland
 # * Copyright (C) 2005 Refractions Research Inc.
 # *
@@ -51,8 +51,8 @@ OBJS = postgis_topology.o
 # to an existing liblwgeom.so in the PostgreSQL $libdir supplied by an
 # older version of PostGIS, rather than with the static liblwgeom.a
 # supplied with newer versions of PostGIS
-PG_CPPFLAGS += -I../liblwgeom -I../libpgcommon @CFLAGS@ @CPPFLAGS@ @PICFLAGS@
-SHLIB_LINK_F = ../libpgcommon/libpgcommon.a ../liblwgeom/.libs/liblwgeom.a @SHLIB_LINK@
+PG_CPPFLAGS += -I at top_builddir@/liblwgeom -I at top_srcdir@/liblwgeom -I at top_srcdir@/libpgcommon @CFLAGS@ @CPPFLAGS@ @PICFLAGS@
+SHLIB_LINK_F = @top_builddir@/libpgcommon/libpgcommon.a @top_builddir@/liblwgeom/.libs/liblwgeom.a @SHLIB_LINK@
 
 # Add SFCGAL Flags if defined
 ifeq (@SFCGAL@,sfcgal)
@@ -72,6 +72,8 @@ PGXS := @PGXS@
 NO_TEMP_INSTALL=yes
 include $(PGXS)
 
+VPATH := @srcdir@
+
 # Set PERL _after_ the include of PGXS
 PERL=@PERL@
 
@@ -96,7 +98,7 @@ endif
 
 # Generate any .sql file from .sql.in files by running them through the SQL pre-processor
 %.sql: %.sql.in
-	$(SQLPP) $< | grep -v '^#' | \
+	$(SQLPP) -I at top_builddir@/postgis $< | grep -v '^#' | \
 	$(PERL) -lpe "s'MODULE_PATHNAME'\$(MODULEPATH)'g" > $@
 
 #Generate upgrade script by stripping things that can't be reinstalled
@@ -138,7 +140,7 @@ topology.sql: \
 	../postgis_revision.h
 
 uninstall_topology.sql: topology.sql ../utils/create_undef.pl
-	$(PERL) ../utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
+	$(PERL) @top_srcdir@/utils/create_undef.pl $< $(POSTGIS_PGSQL_VERSION) > $@
 
 check-unit:
 
diff --git a/topology/test/Makefile.in b/topology/test/Makefile.in
index 19d7770b5..b1df1349b 100644
--- a/topology/test/Makefile.in
+++ b/topology/test/Makefile.in
@@ -1,3 +1,19 @@
+# **********************************************************************
+# *
+# * PostGIS - Spatial Types for PostgreSQL
+# * http://postgis.net
+# *
+# * Copyright (C) 2020-2022 Sandro Santilli <strk at kbt.io>
+# *
+# * This is free software; you can redistribute and/or modify it under
+# * the terms of the GNU General Public Licence. See the COPYING file.
+# *
+# **********************************************************************
+
+top_srcdir = @top_srcdir@
+srcdir = @srcdir@
+builddir = @builddir@
+
 DATABASE=postgis_topo_regress
 
 PSQL=psql
@@ -39,8 +55,8 @@ check-regress: check-regress-deps
 
 check-regress-deps: topo_predicates.sql load_topology.sql load_topology-4326.sql
 
-topsrcdir = $(realpath ../../)
-srcdir = $(realpath .)
+# TODO: drop this variable, use top_srcdir directly
+topsrcdir = $(top_srcdir)
 
-include tests.mk
-include ../../regress/runtest.mk
+include $(srcdir)/tests.mk
+include $(top_srcdir)/regress/runtest.mk
diff --git a/topology/topology.sql.in b/topology/topology.sql.in
index 1f62c8a1e..14b7e2ead 100644
--- a/topology/topology.sql.in
+++ b/topology/topology.sql.in
@@ -188,7 +188,7 @@
 -- Let people decide about that
 -- DROP SCHEMA topology CASCADE;
 
-#include "../postgis/sqldefines.h"
+#include "sqldefines.h"
 
 CREATE SCHEMA topology;
 COMMENT ON SCHEMA topology IS 'PostGIS Topology schema';
diff --git a/utils/Makefile.in b/utils/Makefile.in
index 8b22ff19b..a5a54c119 100644
--- a/utils/Makefile.in
+++ b/utils/Makefile.in
@@ -25,6 +25,8 @@ PG_CONFIG := @PG_CONFIG@
 PGXS := @PGXS@
 include $(PGXS)
 
+VPATH := @srcdir@
+
 SHELL = @SHELL@
 INSTALL = $(SHELL) ../build-aux/install-sh
 
@@ -42,7 +44,6 @@ SRID_MAXIMUM = @SRID_MAX@
 SRID_USER_MAXIMUM = @SRID_USR_MAX@
 
 all: postgis_restore.pl
-	chmod +x $(SCRIPTS)
 
 DROP_FILES = \
   ../raster/rt_pg/rtpostgis_upgrade_cleanup.sql.in \
@@ -72,6 +73,7 @@ update-restore:
 
 postgis_restore.pl: postgis_restore.pl.in
 	sed 's, at SRID_MAXIMUM@,$(SRID_MAXIMUM),g;s, at SRID_USER_MAXIMUM@,$(SRID_USER_MAXIMUM),' $< >$@
+	chmod +x $@
 
 distclean: clean
 	rm -f Makefile

commit afff318c410ca8992837f8054c4f85a52980f827
Author: Sandro Santilli <strk at kbt.io>
Date:   Wed Jan 19 17:12:03 2022 +0100

    Allow passing POSTGIS_TOP_BUILD_DIR env variable to run_test.pl

diff --git a/regress/run_test.pl b/regress/run_test.pl
index 9810a81d7..3ef07ea65 100755
--- a/regress/run_test.pl
+++ b/regress/run_test.pl
@@ -50,9 +50,10 @@ BEGIN {
 
 our $DB = $ENV{"POSTGIS_REGRESS_DB"} || "postgis_reg";
 our $REGDIR = abs_path(dirname($0));
-our $SHP2PGSQL = $REGDIR . "/../loader/shp2pgsql";
-our $PGSQL2SHP = $REGDIR . "/../loader/pgsql2shp";
-our $RASTER2PGSQL = $REGDIR . "/../raster/loader/raster2pgsql";
+our $TOP_BUILDDIR = $ENV{"POSTGIS_TOP_BUILD_DIR"} || ${REGDIR} . '/..';
+our $SHP2PGSQL = $TOP_BUILDDIR . "/loader/shp2pgsql";
+our $PGSQL2SHP = $TOP_BUILDDIR . "/loader/pgsql2shp";
+our $RASTER2PGSQL = $TOP_BUILDDIR . "/raster/loader/raster2pgsql";
 our $sysdiff = !system("diff --strip-trailing-cr $0 $0 2> /dev/null");
 
 ##################################################################

-----------------------------------------------------------------------


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list