Index: postgis/Makefile.in
===================================================================
--- postgis/Makefile.in	(revision 5102)
+++ postgis/Makefile.in	(working copy)
@@ -11,6 +11,7 @@
 # **********************************************************************
 
 MODULE_big=postgis-@POSTGIS_MAJOR_VERSION@.@POSTGIS_MINOR_VERSION@
+MODULEDIR=contrib/$(MODULE_big)
 
 # Files to be copied to the contrib/ directory
 DATA_built=postgis.sql uninstall_postgis.sql postgis_upgrade_15_minor.sql postgis_upgrade_14_to_15.sql postgis_upgrade_13_to_15.sql
@@ -78,6 +79,18 @@
 PGXS := @PGXS@
 include $(PGXS)
 
+# PGXS override feature. The ability to allow PostGIS to install itself
+# in a versioned directory is only available in PostgreSQL >= 8.5. To
+# do this by default on older PostgreSQL versions, we need to override
+# the existing PGXS targets.
+#
+# Once PostgreSQL 8.5 becomes the minimum supported version, this entire
+# section and its associated Makefile.pgxs should be removed.
+PGXSOVERRIDE = @PGXSOVERRIDE@
+ifeq ($(PGXSOVERRIDE),1)
+	include Makefile.pgxs
+endif
+
 # If REGRESS=1 passed as a parameter, change the default install paths
 # so that no prefix is included. This allows us to relocate to a temporary
 # directory for regression testing.
Index: postgis/Makefile.pgxs
===================================================================
--- postgis/Makefile.pgxs	(revision 0)
+++ postgis/Makefile.pgxs	(revision 0)
@@ -0,0 +1,99 @@
+#
+# PostGIS PGXS override file for PostgreSQL <= 8.5
+# (updates relevant targets for MODULEDIR as per the
+# PostgreSQL 8.5 PGXS Makefile)
+#
+
+ifdef MODULEDIR
+datamoduledir = $(MODULEDIR)
+docmoduledir = $(MODULEDIR)
+else
+datamoduledir = contrib
+docmoduledir = contrib
+endif
+
+install: all installdirs
+ifneq (,$(DATA)$(DATA_built))
+	@for file in $(addprefix $(srcdir)/, $(DATA)) $(DATA_built); do \
+	  echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/$(datamoduledir)'"; \
+	  $(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/$(datamoduledir)'; \
+	done
+endif # DATA
+ifneq (,$(DATA_TSEARCH))
+	@for file in $(addprefix $(srcdir)/, $(DATA_TSEARCH)); do \
+	  echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/tsearch_data'"; \
+	  $(INSTALL_DATA) $$file '$(DESTDIR)$(datadir)/tsearch_data'; \
+	done
+endif # DATA_TSEARCH
+ifdef MODULES
+	@for file in $(addsuffix $(DLSUFFIX), $(MODULES)); do \
+	  echo "$(INSTALL_SHLIB) $$file '$(DESTDIR)$(pkglibdir)'"; \
+	  $(INSTALL_SHLIB) $$file '$(DESTDIR)$(pkglibdir)'; \
+	done
+endif # MODULES
+ifdef DOCS
+ifdef docdir
+	@for file in $(addprefix $(srcdir)/, $(DOCS)); do \
+	  echo "$(INSTALL_DATA) $$file '$(DESTDIR)$(docdir)/$(docmoduledir)'"; \
+	  $(INSTALL_DATA) $$file '$(DESTDIR)$(docdir)/$(docmoduledir)'; \
+	done
+endif # docdir
+endif # DOCS
+ifdef PROGRAM
+	$(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
+endif # PROGRAM
+ifdef SCRIPTS
+	@for file in $(addprefix $(srcdir)/, $(SCRIPTS)); do \
+	  echo "$(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'"; \
+	  $(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'; \
+	done
+endif # SCRIPTS
+ifdef SCRIPTS_built
+	@for file in $(SCRIPTS_built); do \
+	  echo "$(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'"; \
+	  $(INSTALL_SCRIPT) $$file '$(DESTDIR)$(bindir)'; \
+	done
+endif # SCRIPTS_built
+
+installdirs:
+ifneq (,$(DATA)$(DATA_built))
+	$(mkinstalldirs) '$(DESTDIR)$(datadir)/$(datamoduledir)'
+endif
+ifneq (,$(DATA_TSEARCH))
+	$(mkinstalldirs) '$(DESTDIR)$(datadir)/tsearch_data'
+endif
+ifneq (,$(MODULES))
+	$(mkinstalldirs) '$(DESTDIR)$(pkglibdir)'
+endif
+ifdef DOCS
+ifdef docdir
+	$(mkinstalldirs) '$(DESTDIR)$(docdir)/$(docmoduledir)'
+endif # docdir
+endif # DOCS
+ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
+	$(mkinstalldirs) '$(DESTDIR)$(bindir)'
+endif
+
+uninstall:
+ifneq (,$(DATA)$(DATA_built))
+	rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
+endif
+ifneq (,$(DATA_TSEARCH))
+	rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
+endif
+ifdef MODULES
+	rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
+endif
+ifdef DOCS
+	rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
+endif
+ifdef PROGRAM
+	rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
+endif
+ifdef SCRIPTS
+	rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
+endif
+ifdef SCRIPTS_built
+	rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
+endif
+
Index: configure.ac
===================================================================
--- configure.ac	(revision 5102)
+++ configure.ac	(working copy)
@@ -306,6 +306,15 @@
 	fi
 fi	
 
+dnl Temporary hack until minimum PostgreSQL version is 8.5:
+dnl If PostgreSQL < 8.5 is detected, trigger the inclusion of the new versioned PGXS targets
+PGXSOVERRIDE=0
+if test ! "$PGSQL_MINOR_VERSION" -ge 5; then
+	PGXSOVERRIDE=1
+fi
+
+AC_SUBST([PGXSOVERRIDE])
+
 dnl Note: We don't need the server-side LDFLAGS or CPPFLAGS because we get these from PGXS 
 
 dnl Extract the linker and include flags for the frontend (for programs that use libpq)

