diff --git a/doc/src/sgml/ref/pg_config-ref.sgml b/doc/src/sgml/ref/pg_config-ref.sgml
index daf0496290c34597e293f438005f5c9260cec3d1..4eef80a3ce0c41c4d601605e4aed364fc768d029 100644
--- a/doc/src/sgml/ref/pg_config-ref.sgml
+++ b/doc/src/sgml/ref/pg_config-ref.sgml
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_config-ref.sgml,v 1.21 2005/08/09 22:47:03 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_config-ref.sgml,v 1.22 2005/09/27 17:39:32 tgl Exp $ -->
 
 <refentry id="app-pgconfig">
  <refmeta>
@@ -53,6 +53,17 @@
      </listitem>
     </varlistentry>
 
+    <varlistentry>
+     <term><option>--docdir</option></>
+     <listitem>
+      <para>
+       Print the location of documentation files.  (This will be an empty
+       string if <literal>--without-docdir</> was specified when
+       <productname>PostgreSQL</> was built.)
+      </para>
+     </listitem>
+    </varlistentry>
+
     <varlistentry>
      <term><option>--includedir</option></>
      <listitem>
@@ -62,12 +73,20 @@
      </listitem>
     </varlistentry>
 
+    <varlistentry>
+     <term><option>--pkgincludedir</option></>
+     <listitem>
+      <para>
+       Print the location of other C header files.
+      </para>
+     </listitem>
+    </varlistentry>
+
     <varlistentry>
      <term><option>--includedir-server</option></>
      <listitem>
       <para>
-       Print the location of C header files for server
-       programming.
+       Print the location of C header files for server programming.
       </para>
      </listitem>
     </varlistentry>
@@ -93,6 +112,44 @@
      </listitem>
     </varlistentry>
 
+    <varlistentry>
+     <term><option>--localedir</option></>
+     <listitem>
+      <para>
+       Print the location of locale support files.  (This will be an empty
+       string if locale support was not configured when
+       <productname>PostgreSQL</> was built.)
+      </para>
+     </listitem>
+    </varlistentry>
+
+    <varlistentry>
+     <term><option>--mandir</option></>
+     <listitem>
+      <para>
+       Print the location of manual pages.
+      </para>
+     </listitem>
+    </varlistentry>
+
+    <varlistentry>
+     <term><option>--sharedir</option></>
+     <listitem>
+      <para>
+       Print the location of architecture-independent support files.
+      </para>
+     </listitem>
+    </varlistentry>
+
+    <varlistentry>
+     <term><option>--sysconfdir</option></>
+     <listitem>
+      <para>
+       Print the location of system-wide configuration files.
+      </para>
+     </listitem>
+    </varlistentry>
+
     <varlistentry>
      <term><option>--pgxs</option></>
      <listitem>
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index e59ef2bfb9806226271932442698d02eab33532d..20d7a1d255420e0e2a1e0235054061526db23e4d 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1,5 +1,5 @@
 # -*-makefile-*-
-# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.219 2005/08/02 19:02:31 tgl Exp $
+# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.220 2005/09/27 17:39:32 tgl Exp $
 
 #------------------------------------------------------------------------------
 # All PostgreSQL makefiles include this file and use the variables it sets,
@@ -55,19 +55,20 @@ configure_args = @configure_args@
 # These are set by the equivalent --xxxdir configure options.  We
 # append "postgresql" to some of them, if the string does not already
 # contain "pgsql" or "postgres", in order to avoid directory clutter.
+#
+# In a PGXS build, we cannot use the values inserted into Makefile.global
+# by configure, since the installation tree may have been relocated.
+# Instead get the path values from pg_config.
+
+ifndef PGXS
+
+# Note that prefix and exec_prefix aren't defined in a PGXS build;
+# makefiles may only use the derived variables such as bindir.
 
 prefix := @prefix@
 exec_prefix := @exec_prefix@
 
 bindir := @bindir@
-sbindir := @sbindir@
-
-libexecdir := @libexecdir@
-ifeq "$(findstring pgsql, $(libexecdir))" ""
-ifeq "$(findstring postgres, $(libexecdir))" ""
-override libexecdir := $(libexecdir)/postgresql
-endif
-endif
 
 datadir := @datadir@
 ifeq "$(findstring pgsql, $(datadir))" ""
@@ -84,6 +85,7 @@ endif
 endif
 
 libdir := @libdir@
+
 pkglibdir = $(libdir)
 ifeq "$(findstring pgsql, $(pkglibdir))" ""
 ifeq "$(findstring postgres, $(pkglibdir))" ""
@@ -92,17 +94,15 @@ endif
 endif
 
 includedir := @includedir@
+
 pkgincludedir = $(includedir)
 ifeq "$(findstring pgsql, $(pkgincludedir))" ""
 ifeq "$(findstring postgres, $(pkgincludedir))" ""
 override pkgincludedir := $(pkgincludedir)/postgresql
 endif
 endif
-includedir_server = $(pkgincludedir)/server
-includedir_internal = $(pkgincludedir)/internal
 
 mandir := @mandir@
-sqlmansect_dummy = l
 
 docdir := @docdir@
 # docdir can be an empty string to signify --without-docdir
@@ -116,8 +116,29 @@ endif
 
 localedir := @localedir@
 
+else # PGXS case
+
+bindir := $(shell pg_config --bindir)
+datadir := $(shell pg_config --sharedir)
+sysconfdir := $(shell pg_config --sysconfdir)
+libdir := $(shell pg_config --libdir)
+pkglibdir := $(shell pg_config --pkglibdir)
+includedir := $(shell pg_config --includedir)
+pkgincludedir := $(shell pg_config --pkgincludedir)
+mandir := $(shell pg_config --mandir)
+docdir := $(shell pg_config --docdir)
+localedir := $(shell pg_config --localedir)
+
+endif # PGXS
+
+# These derived path variables aren't separately configurable.
+
+includedir_server = $(pkgincludedir)/server
+includedir_internal = $(pkgincludedir)/internal
 pgxsdir = $(pkglibdir)/pgxs
 
+sqlmansect_dummy = l
+
 
 ##########################################################################
 #
diff --git a/src/bin/pg_config/pg_config.c b/src/bin/pg_config/pg_config.c
index ae1fce770df8c1a17a180fe182b08d0c6e03082f..3902f585123d938611802e58818151f57e325981 100644
--- a/src/bin/pg_config/pg_config.c
+++ b/src/bin/pg_config/pg_config.c
@@ -17,7 +17,7 @@
  *
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.12 2005/08/09 22:47:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_config/pg_config.c,v 1.13 2005/09/27 17:39:33 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -52,6 +52,17 @@ show_bindir(bool all)
 	printf("%s\n", path);
 }
 
+static void
+show_docdir(bool all)
+{
+	char		path[MAXPGPATH];
+
+	if (all)
+		printf("DOCDIR = ");
+	get_doc_path(mypath, path);
+	printf("%s\n", path);
+}
+
 static void
 show_includedir(bool all)
 {
@@ -63,6 +74,17 @@ show_includedir(bool all)
 	printf("%s\n", path);
 }
 
+static void
+show_pkgincludedir(bool all)
+{
+	char		path[MAXPGPATH];
+
+	if (all)
+		printf("PKGINCLUDEDIR = ");
+	get_pkginclude_path(mypath, path);
+	printf("%s\n", path);
+}
+
 static void
 show_includedir_server(bool all)
 {
@@ -96,6 +118,50 @@ show_pkglibdir(bool all)
 	printf("%s\n", path);
 }
 
+static void
+show_localedir(bool all)
+{
+	char		path[MAXPGPATH];
+
+	if (all)
+		printf("LOCALEDIR = ");
+	get_locale_path(mypath, path);
+	printf("%s\n", path);
+}
+
+static void
+show_mandir(bool all)
+{
+	char		path[MAXPGPATH];
+
+	if (all)
+		printf("MANDIR = ");
+	get_man_path(mypath, path);
+	printf("%s\n", path);
+}
+
+static void
+show_sharedir(bool all)
+{
+	char		path[MAXPGPATH];
+
+	if (all)
+		printf("SHAREDIR = ");
+	get_share_path(mypath, path);
+	printf("%s\n", path);
+}
+
+static void
+show_sysconfdir(bool all)
+{
+	char		path[MAXPGPATH];
+
+	if (all)
+		printf("SYSCONFDIR = ");
+	get_etc_path(mypath, path);
+	printf("%s\n", path);
+}
+
 static void
 show_pgxs(bool all)
 {
@@ -234,10 +300,16 @@ typedef struct
 
 static const InfoItem info_items[] = {
 	{ "--bindir", show_bindir },
+	{ "--docdir", show_docdir },
 	{ "--includedir", show_includedir },
+	{ "--pkgincludedir", show_pkgincludedir },
 	{ "--includedir-server", show_includedir_server },
 	{ "--libdir", show_libdir },
 	{ "--pkglibdir", show_pkglibdir },
+	{ "--localedir", show_localedir },
+	{ "--mandir", show_mandir },
+	{ "--sharedir", show_sharedir },
+	{ "--sysconfdir", show_sysconfdir },
 	{ "--pgxs", show_pgxs },
 	{ "--configure", show_configure },
 	{ "--cc", show_cc },
@@ -260,11 +332,17 @@ help(void)
 	printf(_("  %s [ OPTION ... ]\n\n"), progname);
 	printf(_("Options:\n"));
 	printf(_("  --bindir              show location of user executables\n"));
+	printf(_("  --docdir              show location of documentation files\n"));
 	printf(_("  --includedir          show location of C header files of the client\n"
 			 "                        interfaces\n"));
+	printf(_("  --pkgincludedir       show location of other C header files\n"));
 	printf(_("  --includedir-server   show location of C header files for the server\n"));
 	printf(_("  --libdir              show location of object code libraries\n"));
 	printf(_("  --pkglibdir           show location of dynamically loadable modules\n"));
+	printf(_("  --localedir           show location of locale support files\n"));
+	printf(_("  --mandir              show location of manual pages\n"));
+	printf(_("  --sharedir            show location of architecture-independent support files\n"));
+	printf(_("  --sysconfdir          show location of system-wide configuration files\n"));
 	printf(_("  --pgxs                show location of extension makefile\n"));
 	printf(_("  --configure           show options given to \"configure\" script when\n"
 			 "                        PostgreSQL was built\n"));
diff --git a/src/bin/pg_config/win32.mak b/src/bin/pg_config/win32.mak
index 0017e57851e02e0af2dae9fb9d2242d3325a8f5e..f00f3012550b6ed6c090a12ec0d6b5d8c31eece8 100644
--- a/src/bin/pg_config/win32.mak
+++ b/src/bin/pg_config/win32.mak
@@ -39,6 +39,8 @@ CLEAN :
 	echo #define LIBDIR "" >>$@
 	echo #define PKGLIBDIR "" >>$@
 	echo #define LOCALEDIR "" >>$@
+	echo #define DOCDIR "" >>$@
+	echo #define MANDIR "" >>$@
 
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
diff --git a/src/bin/psql/bcc32.mak b/src/bin/psql/bcc32.mak
index fd2a1cd26791ae6c4ae699c4e4e9deba862d46cb..5a6caeef6e6b82cf58dcf4916cdff146136e6e23 100644
--- a/src/bin/psql/bcc32.mak
+++ b/src/bin/psql/bcc32.mak
@@ -159,6 +159,8 @@ LINK32_OBJS	= $(LINK32_OBJS) "..\..\interfaces\libpq\Release\blibpqdll.lib"
 	echo \#define LIBDIR "" >>$@
 	echo \#define PKGLIBDIR "" >>$@
 	echo \#define LOCALEDIR "" >>$@
+	echo \#define DOCDIR "" >>$@
+	echo \#define MANDIR "" >>$@
 
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
diff --git a/src/bin/psql/win32.mak b/src/bin/psql/win32.mak
index 8c4a0738ec986bf45ab6d6f8a79560ecbe206ff2..62154c026f388ed2d723ee9dc89b5da0e81b96c6 100644
--- a/src/bin/psql/win32.mak
+++ b/src/bin/psql/win32.mak
@@ -108,6 +108,8 @@ LINK32_OBJS	= $(LINK32_OBJS) "..\..\interfaces\libpq\Release\libpqdll.lib"
 	echo #define LIBDIR "" >>$@
 	echo #define PKGLIBDIR "" >>$@
 	echo #define LOCALEDIR "" >>$@
+	echo #define DOCDIR "" >>$@
+	echo #define MANDIR "" >>$@
 
 "$(OUTDIR)" :
     if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
diff --git a/src/include/port.h b/src/include/port.h
index 7172ce5fb53f88054fb7fcdd4cc4660baa76ce38..a95ac4a85e792e447c92b8852969ddb6e7fee14a 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $PostgreSQL: pgsql/src/include/port.h,v 1.82 2005/08/29 19:39:39 tgl Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.83 2005/09/27 17:39:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -43,6 +43,8 @@ extern void get_includeserver_path(const char *my_exec_path, char *ret_path);
 extern void get_lib_path(const char *my_exec_path, char *ret_path);
 extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
 extern void get_locale_path(const char *my_exec_path, char *ret_path);
+extern void get_doc_path(const char *my_exec_path, char *ret_path);
+extern void get_man_path(const char *my_exec_path, char *ret_path);
 extern void set_pglocale_pgservice(const char *argv0, const char *app);
 extern bool get_home_path(char *ret_path);
 extern void get_parent_directory(char *path);
diff --git a/src/port/Makefile b/src/port/Makefile
index 2b5b50a914cbd568c7202fe59161097659c5aca6..e17f324c0d42010742b01e107cdabe8fe3337040 100644
--- a/src/port/Makefile
+++ b/src/port/Makefile
@@ -15,7 +15,7 @@
 #		for use only by the backend binaries
 #
 # IDENTIFICATION
-#    $PostgreSQL: pgsql/src/port/Makefile,v 1.28 2005/08/12 19:45:14 momjian Exp $
+#    $PostgreSQL: pgsql/src/port/Makefile,v 1.29 2005/09/27 17:39:35 tgl Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -81,6 +81,8 @@ pg_config_paths.h: $(top_builddir)/src/Makefile.global
 	echo "#define LIBDIR \"$(libdir)\"" >>$@
 	echo "#define PKGLIBDIR \"$(pkglibdir)\"" >>$@
 	echo "#define LOCALEDIR \"$(localedir)\"" >>$@
+	echo "#define DOCDIR \"$(docdir)\"" >>$@
+	echo "#define MANDIR \"$(mandir)\"" >>$@
 
 clean distclean maintainer-clean:
 	rm -f libpgport.a libpgport_srv.a $(LIBOBJS) $(LIBOBJS_SRV) pg_config_paths.h
diff --git a/src/port/path.c b/src/port/path.c
index 41a505759e9a56b2aaab7246a27bdbe8e2225064..bdb6e29adf157ad189c12674f0977fac8b989e58 100644
--- a/src/port/path.c
+++ b/src/port/path.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $PostgreSQL: pgsql/src/port/path.c,v 1.58 2005/08/29 19:39:39 tgl Exp $
+ *	  $PostgreSQL: pgsql/src/port/path.c,v 1.59 2005/09/27 17:39:35 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -538,6 +538,24 @@ get_locale_path(const char *my_exec_path, char *ret_path)
 	make_relative_path(ret_path, LOCALEDIR, PGBINDIR, my_exec_path);
 }
 
+/*
+ *	get_doc_path
+ */
+void
+get_doc_path(const char *my_exec_path, char *ret_path)
+{
+	make_relative_path(ret_path, DOCDIR, PGBINDIR, my_exec_path);
+}
+
+/*
+ *	get_man_path
+ */
+void
+get_man_path(const char *my_exec_path, char *ret_path)
+{
+	make_relative_path(ret_path, MANDIR, PGBINDIR, my_exec_path);
+}
+
 
 /*
  *	get_home_path