diff --git a/contrib/contrib-global.mk b/contrib/contrib-global.mk
index 4c9358e5c0bee1e099876491b7b2e2ee22379544..415cc273e777432f2ec45716e11033a6dd1c45d8 100644
--- a/contrib/contrib-global.mk
+++ b/contrib/contrib-global.mk
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/contrib/contrib-global.mk,v 1.1 2001/09/06 10:49:29 petere Exp $
+# $Header: /cvsroot/pgsql/contrib/contrib-global.mk,v 1.2 2001/09/16 16:11:08 petere Exp $
 
 # This file contains generic rules to build many kinds of simple
 # contrib modules.  You only need to set a few variables and include
@@ -78,8 +78,8 @@ ifneq (,$(DATA)$(DATA_built))
 endif # DATA
 ifdef MODULES
 	@for file in $(addsuffix $(DLSUFFIX), $(MODULES)); do \
-	  echo "$(INSTALL_SHLIB) $$file $(DESTDIR)$(libdir)/contrib"; \
-	  $(INSTALL_SHLIB) $$file $(DESTDIR)$(libdir)/contrib; \
+	  echo "$(INSTALL_SHLIB) $$file $(DESTDIR)$(pkglibdir)"; \
+	  $(INSTALL_SHLIB) $$file $(DESTDIR)$(pkglibdir); \
 	done
 endif # MODULES
 ifdef DOCS
@@ -92,12 +92,12 @@ ifdef PROGRAM
 	$(INSTALL_PROGRAM) $(PROGRAM)$(X) $(DESTDIR)$(bindir)
 endif # PROGRAM
 ifdef MODULE_big
-	$(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(libdir)/contrib/$(MODULE_big)$(DLSUFFIX)
+	$(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(pkglibdir)/$(MODULE_big)$(DLSUFFIX)
 endif # MODULE_big
 ifdef SCRIPTS
 	@for file in $(addprefix $(srcdir)/, $(SCRIPTS)); do \
 	  echo "$(INSTALL_SCRIPT) $$file $(DESTDIR)$(bindir)"; \
-	  $(INSTALL_DATA) $$file $(DESTDIR)$(bindir); \
+	  $(INSTALL_SCRIPT) $$file $(DESTDIR)$(bindir); \
 	done
 endif # SCRIPTS
 
@@ -107,7 +107,7 @@ ifneq (,$(DATA)$(DATA_built))
 	$(mkinstalldirs) $(DESTDIR)$(datadir)/contrib
 endif
 ifneq (,$(MODULES)$(MODULE_big))
-	$(mkinstalldirs) $(DESTDIR)$(libdir)/contrib
+	$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
 endif
 ifdef DOCS
 	$(mkinstalldirs) $(DESTDIR)$(docdir)/contrib
@@ -122,7 +122,7 @@ ifneq (,$(DATA)$(DATA_built))
 	rm -f $(addprefix $(DESTDIR)$(datadir)/contrib/, $(DATA) $(DATA_built))
 endif
 ifdef MODULES
-	rm -f $(addprefix $(DESTDIR)$(libdir)/contrib/, $(addsuffix $(DLSUFFIX), $(MODULES)))
+	rm -f $(addprefix $(DESTDIR)$(pkglibdir)/, $(addsuffix $(DLSUFFIX), $(MODULES)))
 endif
 ifdef DOCS
 	rm -f $(addprefix $(DESTDIR)$(docdir)/contrib/, $(DOCS))
@@ -131,7 +131,7 @@ ifdef PROGRAM
 	rm -f $(DESTDIR)$(bindir)/$(PROGRAM)$(X)
 endif
 ifdef MODULE_big
-	rm -f $(DESTDIR)$(libdir)/contrib/$(MODULE_big)$(DLSUFFIX)
+	rm -f $(DESTDIR)$(pkglibdir)/$(MODULE_big)$(DLSUFFIX)
 endif
 ifdef SCRIPTS
 	rm -f $(addprefix $(DESTDIR)$(bindir)/, $(SCRIPTS))
@@ -193,7 +193,7 @@ endif # REGRESS
 
 ifneq (,$(MODULES)$(MODULE_big))
 %.sql: %.sql.in
-	sed 's,MODULE_PATHNAME,$(libdir)/contrib/$*,g' $< >$@
+	sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
 endif
 
 ifdef PROGRAM
diff --git a/contrib/pgcrypto/Makefile b/contrib/pgcrypto/Makefile
index ef9a30eb63f48422e4ba5abc54a5c07cac62ccef..1e3d4bac639d778c405434238a2f60d196b28ad3 100644
--- a/contrib/pgcrypto/Makefile
+++ b/contrib/pgcrypto/Makefile
@@ -1,5 +1,5 @@
 #
-# $Header: /cvsroot/pgsql/contrib/pgcrypto/Makefile,v 1.5 2001/08/21 00:42:41 momjian Exp $
+# $Header: /cvsroot/pgsql/contrib/pgcrypto/Makefile,v 1.6 2001/09/16 16:11:09 petere Exp $
 #
 
 subdir = contrib/pgcrypto
@@ -47,13 +47,14 @@ SO_MINOR_VERSION = 1
 
 override CPPFLAGS	+= $(CRYPTO_CFLAGS) -I$(srcdir) 
 override DLLLIBS := $(BE_DLLLIBS) $(DLLLIBS)
+rpath :=
 
 all: all-lib $(NAME).sql
 
 include $(top_srcdir)/src/Makefile.shlib
 
 $(NAME).sql: $(NAME).sql.in
-	sed 's,@MODULE_FILENAME@,$(libdir)/contrib/pgcrypto$(DLSUFFIX),g' $< >$@
+	sed 's,@MODULE_FILENAME@,$$libdir/$(NAME),g' $< >$@
 
 rijndael.o: rijndael.tbl
 
@@ -62,15 +63,15 @@ rijndael.tbl:
 	./gen-rtab > rijndael.tbl
 
 install: all installdirs
-	$(INSTALL_SHLIB) $(shlib)	$(DESTDIR)$(libdir)/contrib/pgcrypto$(DLSUFFIX)
+	$(INSTALL_SHLIB) $(shlib)	$(DESTDIR)$(pkglibdir)/pgcrypto$(DLSUFFIX)
 	$(INSTALL_DATA) $(NAME).sql	$(DESTDIR)$(datadir)/contrib/$(NAME).sql
 	$(INSTALL_DATA) README.$(NAME)	$(DESTDIR)$(docdir)/contrib/README.$(NAME)
 
 installdirs:
-	$(mkinstalldirs) $(libdir)/contrib $(datadir)/contrib $(docdir)/contrib
+	$(mkinstalldirs) $(pkglibdir) $(datadir)/contrib $(docdir)/contrib
 
 uninstall: uninstall-lib
-	rm -f $(DESTDIR)$(libdir)/contrib/pgcrypto$(DLSUFFIX) $(datadir)/contrib/$(NAME).sql $(docdir)/contrib/README.$(NAME)
+	rm -f $(DESTDIR)$(pkglibdir)/pgcrypto$(DLSUFFIX) $(datadir)/contrib/$(NAME).sql $(docdir)/contrib/README.$(NAME)
 
 clean distclean maintainer-clean: clean-lib
 	rm -f $(OBJS) $(NAME).sql gen-rtab
diff --git a/contrib/rserv/Makefile b/contrib/rserv/Makefile
index 7306759b30c75cdc355e10dc27eb514a1a8d0bc5..272511974665631937de647035a9c0f393056adf 100644
--- a/contrib/rserv/Makefile
+++ b/contrib/rserv/Makefile
@@ -22,15 +22,13 @@ override DLLLIBS := $(BE_DLLLIBS) $(DLLLIBS)
 all: $(SQLS) $(TCLS) $(PERLS) $(SCRIPTS) $(SONAME)
 
 %.sql: %.sql.in
-	sed -e "s:_OBJWD_:$(libdir)/contrib:g" \
-	    -e "s:_DLSUFFIX_:$(DLSUFFIX):g" $< >$@
+	sed 's,@MODULE_FILENAME@,$$libdir/$(NAME),g' $< >$@
 
 $(PERLS) $(TCLS) $(SCRIPTS): %: %.in
-	sed -e "s:_OBJWD_:$(libdir)/contrib:g" \
-	    -e "s:_DLSUFFIX_:$(DLSUFFIX):g" \
-	    -e "s:@SQLDIR@:$(datadir)/contrib:g" \
-	    -e "s:@BINDIR@:$(bindir):g" \
-	    -e "s:@LIBDIR@:$(datadir)/contrib:g" $< >$@
+	sed -e 's,@MODULE_FILENAME@,$$libdir/$(NAME),g' \
+	    -e 's:@SQLDIR@:$(datadir)/contrib:g' \
+	    -e 's:@BINDIR@:$(bindir):g' \
+	    -e 's:@LIBDIR@:$(datadir)/contrib:g' $< >$@
 	chmod a+x $@
 
 
@@ -42,12 +40,12 @@ install: all installdirs
 	  $(INSTALL_SCRIPT) $$file $(DESTDIR)$(bindir) || exit ; \
 	done
 	$(INSTALL_DATA) $(srcdir)/RServ.pm $(DESTDIR)$(datadir)/contrib
-	$(INSTALL_SHLIB) $(SONAME) $(DESTDIR)$(libdir)/contrib
+	$(INSTALL_SHLIB) $(SONAME) $(DESTDIR)$(pkglibdir)
 	$(INSTALL_DATA) $(srcdir)/README.$(NAME) $(DESTDIR)$(docdir)/contrib
 
 installdirs:
 	$(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(datadir)/contrib \
-	  $(DESTDIR)$(libdir)/contrib $(DESTDIR)$(docdir)/contrib
+	  $(DESTDIR)$(pkglibdir) $(DESTDIR)$(docdir)/contrib
 
 
 clean distclean maintainer-clean:
diff --git a/contrib/rserv/MasterInit.in b/contrib/rserv/MasterInit.in
index 9464424fa2d1d65e28d336346844e7a0b93d7eb7..68854c743a77d7ae4222491b07fdc75822589696 100644
--- a/contrib/rserv/MasterInit.in
+++ b/contrib/rserv/MasterInit.in
@@ -90,15 +90,15 @@ $result = $conn->exec("create sequence _rserv_sync_seq_");
 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
 
 $result = $conn->exec("CREATE FUNCTION _rserv_log_() RETURNS opaque" .
-					  " AS '_OBJWD_/rserv_DLSUFFIX_' LANGUAGE 'c'");
+					  " AS '@MODULE_FILENAME@' LANGUAGE 'c'");
 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
 
 $result = $conn->exec("CREATE FUNCTION _rserv_sync_(int4) RETURNS int4" .
-					  " AS '_OBJWD_/rserv_DLSUFFIX_' LANGUAGE 'c'");
+					  " AS '@MODULE_FILENAME@' LANGUAGE 'c'");
 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
 
 $result = $conn->exec("CREATE FUNCTION _rserv_debug_(int4) RETURNS int4" .
-					  " AS '_OBJWD_/rserv_DLSUFFIX_' LANGUAGE 'c'");
+					  " AS '@MODULE_FILENAME@' LANGUAGE 'c'");
 RollbackAndQuit($conn) if ($result->resultStatus ne PGRES_COMMAND_OK);
 
 $result = $conn->exec("COMMIT");
diff --git a/contrib/rserv/master.sql.in b/contrib/rserv/master.sql.in
index e52fc5760770b9a7d203e09bcabae45e3fa10cfd..f8d37148b99de9efc95ed8cc922417ab8c119bb3 100644
--- a/contrib/rserv/master.sql.in
+++ b/contrib/rserv/master.sql.in
@@ -80,7 +80,7 @@ drop function _rserv_log_();
 
 CREATE FUNCTION _rserv_log_()
 	RETURNS opaque
-	AS '_OBJWD_/rserv_DLSUFFIX_'
+	AS '@MODULE_FILENAME@'
 	LANGUAGE 'c'
 ;
 
@@ -88,7 +88,7 @@ drop function _rserv_sync_(int4);
 
 CREATE FUNCTION _rserv_sync_(int4)
 	RETURNS int4
-	AS '_OBJWD_/rserv_DLSUFFIX_'
+	AS '@MODULE_FILENAME@'
 	LANGUAGE 'c'
 ;
 
@@ -96,6 +96,6 @@ drop function _rserv_debug_(int4);
 
 CREATE FUNCTION _rserv_debug_(int4)
 	RETURNS int4
-	AS '_OBJWD_/rserv_DLSUFFIX_'
+	AS '@MODULE_FILENAME@'
 	LANGUAGE 'c'
 ;
diff --git a/doc/src/sgml/installation.sgml b/doc/src/sgml/installation.sgml
index 9e98acb407d205f801beb816a87f7b5894f6109f..3aee49adf7c639987b4b1cacd67a5e005f6e1d1e 100644
--- a/doc/src/sgml/installation.sgml
+++ b/doc/src/sgml/installation.sgml
@@ -1,4 +1,4 @@
-<!-- $Header: /cvsroot/pgsql/doc/src/sgml/installation.sgml,v 1.55 2001/09/12 20:57:28 petere Exp $ -->
+<!-- $Header: /cvsroot/pgsql/doc/src/sgml/installation.sgml,v 1.56 2001/09/16 16:11:09 petere Exp $ -->
 
 <chapter id="installation">
  <title><![%flattext-install-include[<productname>PostgreSQL</>]]>
@@ -471,9 +471,11 @@ su - postgres
        <varname>includedir</varname> and are namespace-clean.  The
        internal header files and the server header files are installed
        into private directories under
-       <filename><replaceable>includedir</replaceable>/postgresql</filename>.
+       <varname>includedir</varname>.
        See the <citetitle>Programmer's Guide</citetitle> for
        information how to get at the header files for each interface.
+       Finally, a private subdirectory will also be created, if appropriate,
+       under <varname>libdir</varname> for dynamically loadable modules.       
       </para>
      </note>
     </para>
diff --git a/doc/src/sgml/ref/pg_config-ref.sgml b/doc/src/sgml/ref/pg_config-ref.sgml
index a61539d162680367a2a88a392988b1542992da3a..56796b094d73cf0469f0a65cfed4bfa2750bcb17 100644
--- a/doc/src/sgml/ref/pg_config-ref.sgml
+++ b/doc/src/sgml/ref/pg_config-ref.sgml
@@ -1,4 +1,4 @@
-<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_config-ref.sgml,v 1.7 2001/09/03 12:57:50 petere Exp $ -->
+<!-- $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_config-ref.sgml,v 1.8 2001/09/16 16:11:09 petere Exp $ -->
 
 <refentry id="app-pgconfig">
  <docinfo>
@@ -24,6 +24,7 @@
     <arg>--includedir</arg>
     <arg>--includedir-server</arg>
     <arg>--libdir</arg>
+    <arg>--pkglibdir</arg>
     <arg>--configure</arg>
     <arg>--version</arg>
    </group>
@@ -87,6 +88,18 @@
      </listitem>
     </varlistentry>
 
+    <varlistentry>
+     <term>--pkglibdir</>
+     <listitem>
+      <para>
+       Print the location of dynamically loadable modules, or where
+       the server would search for them.  (Other
+       architecture-dependent data files may also be installed in this
+       directory.)
+      </para>
+     </listitem>
+    </varlistentry>
+
     <varlistentry>
      <term>--configure</>
      <listitem>
diff --git a/doc/src/sgml/runtime.sgml b/doc/src/sgml/runtime.sgml
index aae6bf14deb712499c1f5f102fa4a0319e575485..2f27788334624dc1469ec3b2b7d7ba60f9575215 100644
--- a/doc/src/sgml/runtime.sgml
+++ b/doc/src/sgml/runtime.sgml
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.79 2001/09/13 15:55:23 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/runtime.sgml,v 1.80 2001/09/16 16:11:09 petere Exp $
 -->
 
 <Chapter Id="runtime">
@@ -1047,12 +1047,13 @@ env PGOPTIONS='-c geqo=off' psql
         The value for dynamic_library_path has to be a colon-separated
         list of absolute directory names.  If a directory name starts
         with the special value <literal>$libdir</literal>, the
-        compiled-in PostgreSQL library directory, which is where the
+        compiled-in PostgreSQL package library directory, which is where the
         modules provided by the PostgreSQL distribution are installed,
-        is substituted.  An example value:
+        is substituted.  (Use <literal>pg_config --pkglibdir</literal>
+        to print the name of this directory.)  An example value:
         <informalexample>
 <programlisting>
-dynamic_library_path = '/usr/local/lib:/home/my_project/lib:$libdir:$libdir/contrib'
+dynamic_library_path = '/usr/local/lib/postgresql:/home/my_project/lib:$libdir'
 </programlisting>
         </informalexample>
        </para>
diff --git a/doc/src/sgml/xfunc.sgml b/doc/src/sgml/xfunc.sgml
index ac14c2d6907fce7af731fab709b3feb6f1261509..d2cf448adc10cbebaed2d999dc53184d5115aeba 100644
--- a/doc/src/sgml/xfunc.sgml
+++ b/doc/src/sgml/xfunc.sgml
@@ -1,5 +1,5 @@
 <!--
-$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.37 2001/09/15 19:56:59 petere Exp $
+$Header: /cvsroot/pgsql/doc/src/sgml/xfunc.sgml,v 1.38 2001/09/16 16:11:09 petere Exp $
 -->
 
  <chapter id="xfunc">
@@ -466,7 +466,7 @@ CREATE FUNCTION square_root(double precision) RETURNS double precision
      <listitem>
       <para>
        If the name starts with the string <literal>$libdir</literal>,
-       that part is replaced by the PostgreSQL library directory,
+       that part is replaced by the PostgreSQL package library directory,
        which is determined at build time.
       </para>
      </listitem>
@@ -516,7 +516,9 @@ CREATE FUNCTION square_root(double precision) RETURNS double precision
     It is recommended to locate shared libraries either relative to
     <literal>$libdir</literal> or through the dynamic library path.
     This simplifies version upgrades if the new installation is at a
-    different location.
+    different location.  The actual directory that
+    <literal>$libdir</literal> stands for can be found out with the
+    command <literal>pg_config --pkglibdir</literal>.
    </para>
 
    <note>
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 9a1aa8c5386f957265f2096cf94ffd4ebf71a6fc..9c3b697889b3e8ef075bc39a7e996fce3e04c206 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -1,5 +1,5 @@
 # -*-makefile-*-
-# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.136 2001/08/29 19:14:39 petere Exp $
+# $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.137 2001/09/16 16:11:09 petere Exp $
 
 #------------------------------------------------------------------------------
 # All PostgreSQL makefiles include this file and use the variables it sets,
@@ -80,10 +80,20 @@ endif
 endif
 
 libdir := @libdir@
-pkglibdir = $(libdir)/postgresql
+pkglibdir = $(libdir)
+ifeq "$(findstring pgsql, $(pkglibdir))" ""
+ifeq "$(findstring postgres, $(pkglibdir))" ""
+override pkglibdir := $(pkglibdir)/postgresql
+endif
+endif
 
 includedir := @includedir@
-pkgincludedir = $(includedir)/postgresql
+pkgincludedir = $(includedir)
+ifeq "$(findstring pgsql, $(pkgincludedir))" ""
+ifeq "$(findstring postgres, $(pkgincludedir))" ""
+override pkgincludedir := $(pkgincludedir)/postgresql
+endif
+endif
 includedir_server = $(pkgincludedir)/server
 includedir_internal = $(pkgincludedir)/internal
 
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 48773c4994e597e9da3ab4451e26c9f8201302d6..40a848005a4efadaa06256a6cdd2d8dc06e64b1f 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -4,7 +4,7 @@
 #
 # Copyright (c) 1994, Regents of the University of California
 #
-# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.73 2001/06/02 18:25:17 petere Exp $
+# $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.74 2001/09/16 16:11:10 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -136,28 +136,36 @@ ifeq ($(enable_nls), yes)
 	$(MAKE) -C po $@
 endif
 
-installdirs:
-	$(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(DESTDIR)$(datadir)
-ifeq ($(enable_nls), yes)
-	$(MAKE) -C po $@
-endif
-
 install-bin: postgres $(POSTGRES_IMP) installdirs
 	$(INSTALL_PROGRAM) postgres$(X) $(DESTDIR)$(bindir)/postgres$(X)
 	@rm -f $(DESTDIR)$(bindir)/postmaster
 	ln -s postgres$(X) $(DESTDIR)$(bindir)/postmaster
 ifeq ($(MAKE_EXPORTS), true)
-	$(INSTALL_DATA) $(POSTGRES_IMP) $(DESTDIR)$(libdir)/$(POSTGRES_IMP)
+	$(INSTALL_DATA) $(POSTGRES_IMP) $(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)
 endif
 
 .PHONY: install-bin
 
+installdirs:
+	$(mkinstalldirs) $(DESTDIR)$(bindir) $(DESTDIR)$(datadir)
+ifeq ($(PORTNAME), win)
+ifeq ($(MAKE_DLL), true)
+	$(mkinstalldirs) $(DESTDIR)$(libdir)
+endif
+endif
+ifeq ($(MAKE_EXPORTS), true)
+	$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
+endif
+ifeq ($(enable_nls), yes)
+	$(MAKE) -C po $@
+endif
+
 ##########################################################################
 
 uninstall:
 	rm -f $(DESTDIR)$(bindir)/postgres$(X) $(DESTDIR)$(bindir)/postmaster
 ifeq ($(MAKE_EXPORTS), true)
-	rm -f $(DESTDIR)$(libdir)/$(POSTGRES_IMP)
+	rm -f $(DESTDIR)$(pkglibdir)/$(POSTGRES_IMP)
 endif
 ifeq ($(PORTNAME), win)
 ifeq ($(MAKE_DLL), true)
diff --git a/src/backend/utils/fmgr/Makefile b/src/backend/utils/fmgr/Makefile
index a449b80942b2694ca5aa382a6183ae53f960f9bb..ad96b1717db0b988e6e6fefa6369ba7ca473ac73 100644
--- a/src/backend/utils/fmgr/Makefile
+++ b/src/backend/utils/fmgr/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for utils/fmgr
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/utils/fmgr/Makefile,v 1.11 2001/05/17 17:44:18 petere Exp $
+#    $Header: /cvsroot/pgsql/src/backend/utils/fmgr/Makefile,v 1.12 2001/09/16 16:11:11 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -14,7 +14,7 @@ include $(top_builddir)/src/Makefile.global
 
 OBJS = dfmgr.o fmgr.o
 
-override CPPFLAGS += -DLIBDIR=\"$(libdir)\" -DDLSUFFIX=\"$(DLSUFFIX)\"
+override CPPFLAGS += -DPKGLIBDIR=\"$(pkglibdir)\" -DDLSUFFIX=\"$(DLSUFFIX)\"
 
 
 all: SUBSYS.o
@@ -22,12 +22,5 @@ all: SUBSYS.o
 SUBSYS.o: $(OBJS)
 	$(LD) $(LDREL) $(LDOUT) SUBSYS.o $(OBJS)
 
-depend dep:
-	$(CC) -MM $(CFLAGS) *.c >depend
-
 clean: 
 	rm -f SUBSYS.o $(OBJS)
-
-ifeq (depend,$(wildcard depend))
-include depend
-endif
diff --git a/src/backend/utils/fmgr/dfmgr.c b/src/backend/utils/fmgr/dfmgr.c
index 0448632aadb7f9c93e450f69afe78394a643b114..2e3cb9ed2dc21e271e04a44ece6d18f8be44d29e 100644
--- a/src/backend/utils/fmgr/dfmgr.c
+++ b/src/backend/utils/fmgr/dfmgr.c
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *	  $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.50 2001/05/19 09:01:10 petere Exp $
+ *	  $Header: /cvsroot/pgsql/src/backend/utils/fmgr/dfmgr.c,v 1.51 2001/09/16 16:11:11 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -224,8 +224,8 @@ file_exists(const char *name)
 #endif
 
 /* Example format: "/usr/local/pgsql/lib" */
-#ifndef LIBDIR
-#error "LIBDIR needs to be defined to compile this file."
+#ifndef PKGLIBDIR
+#error "PKGLIBDIR needs to be defined to compile this file."
 #endif
 
 
@@ -297,7 +297,7 @@ substitute_libpath_macro(const char * name)
 	macroname_len = strcspn(name + 1, "/") + 1;
 
 	if (strncmp(name, "$libdir", macroname_len)==0)
-		replacement = LIBDIR;
+		replacement = PKGLIBDIR;
 	else
 		elog(ERROR, "invalid macro name in dynamic library path");
 
diff --git a/src/bin/pg_config/Makefile b/src/bin/pg_config/Makefile
index 0efaff5e3521941603edca43a3fda70c9539dff6..d2350e83e06270a2950ee215b7ec30688c8310f3 100644
--- a/src/bin/pg_config/Makefile
+++ b/src/bin/pg_config/Makefile
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/src/bin/pg_config/Makefile,v 1.2 2001/08/28 14:20:28 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/pg_config/Makefile,v 1.3 2001/09/16 16:11:11 petere Exp $
 
 subdir = src/bin/pg_config
 top_builddir = ../../..
@@ -12,6 +12,7 @@ pg_config: pg_config.sh $(top_builddir)/config.status $(top_builddir)/src/Makefi
 	    -e 's,@includedir@,$(includedir),g' \
 	    -e 's,@includedir_server@,$(includedir_server),g' \
 	    -e 's,@libdir@,$(libdir),g' \
+	    -e 's,@pkglibdir@,$(pkglibdir),g' \
 	    -e "s,@configure@,$$configure,g" \
 	    -e 's,@version@,$(VERSION),g' \
 	  $< >$@
diff --git a/src/bin/pg_config/pg_config.sh b/src/bin/pg_config/pg_config.sh
index df05b92fee70688321a10004b5f87546b9aa2ba0..e27827cc280f4dfaf87452fb596ebe23cd24c56d 100644
--- a/src/bin/pg_config/pg_config.sh
+++ b/src/bin/pg_config/pg_config.sh
@@ -7,7 +7,7 @@
 # Author:  Peter Eisentraut <peter_e@gmx.net> 
 # Public domain
 
-# $Header: /cvsroot/pgsql/src/bin/pg_config/Attic/pg_config.sh,v 1.4 2001/08/28 14:20:28 petere Exp $
+# $Header: /cvsroot/pgsql/src/bin/pg_config/Attic/pg_config.sh,v 1.5 2001/09/16 16:11:11 petere Exp $
 
 me=`basename $0`
 
@@ -16,13 +16,14 @@ val_bindir='@bindir@'
 val_includedir='@includedir@'
 val_includedir_server='@includedir_server@'
 val_libdir='@libdir@'
+val_pkglibdir='@pkglibdir@'
 val_configure="@configure@"
 val_version='@version@'
 
 help="\
 $me provides information about the installed version of PostgreSQL.
 
-Usage: $me --bindir | --includedir | --includedir-server | --libdir | --configure | --version
+Usage: $me --bindir | --includedir | --includedir-server | --libdir | --pkglibdir | --configure | --version
 
 Operation modes:
   --bindir              show location of user executables
@@ -30,6 +31,7 @@ Operation modes:
                         interfaces
   --includedir-server   show location of C header files for the server
   --libdir              show location of object code libraries
+  --pkglibdir           show location of dynamically loadable modules
   --configure           show options given to 'configure' script when
                         PostgreSQL was built
   --version             show the PostgreSQL version and exit
@@ -55,6 +57,7 @@ do
         --includedir-server)
                         show="$show \$val_includedir_server";;
         --libdir)       show="$show \$val_libdir";;
+        --pkglibdir)    show="$show \$val_pkglibdir";;
         --configure)    show="$show \$val_configure";;
 
 	--version)      echo "PostgreSQL $val_version"
diff --git a/src/pl/plperl/GNUmakefile b/src/pl/plperl/GNUmakefile
index 4ad205acb46c7fdc54340b255746f14572db4ecf..f17c65799ae30e71b5f44f69f981f9d058a6a88c 100644
--- a/src/pl/plperl/GNUmakefile
+++ b/src/pl/plperl/GNUmakefile
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/src/pl/plperl/GNUmakefile,v 1.7 2001/08/26 23:54:41 petere Exp $
+# $Header: /cvsroot/pgsql/src/pl/plperl/GNUmakefile,v 1.8 2001/09/16 16:11:11 petere Exp $
 
 subdir = src/pl/plperl
 top_builddir = ../../..
@@ -13,17 +13,17 @@ all: Makefile
 	$(MAKE) -f $< all VPATH=$(VPATH)
 
 Makefile: Makefile.PL
-	plperl_installdir='$$(DESTDIR)$(libdir)' \
+	plperl_installdir='$$(DESTDIR)$(pkglibdir)' \
 	$(PERL) $< $(makefile_pl_flags) INC='-I$(srcdir) $(filter -I%, $(CPPFLAGS))'
 
 install: all installdirs
 	$(MAKE) -f Makefile install DESTDIR='$(DESTDIR)'
 
 installdirs:
-	$(mkinstalldirs) $(DESTDIR)$(libdir)
+	$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
 
 uninstall:
-	rm -f $(DESTDIR)$(libdir)/plperl$(DLSUFFIX)
+	rm -f $(DESTDIR)$(pkglibdir)/plperl$(DLSUFFIX)
 
 clean distclean maintainer-clean:
 	-[ -f Makefile ] && $(MAKE) -f Makefile clean
diff --git a/src/pl/plpgsql/src/Makefile b/src/pl/plpgsql/src/Makefile
index 55cbf3e3464f3dd2aacf6d4c5b75b7e90eac6550..bc62d95a011f849525844faaa34934786838e0a4 100644
--- a/src/pl/plpgsql/src/Makefile
+++ b/src/pl/plpgsql/src/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for the plpgsql shared object
 #
-# $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Makefile,v 1.17 2001/08/21 16:25:21 petere Exp $
+# $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Makefile,v 1.18 2001/09/16 16:11:11 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -20,8 +20,8 @@ SO_MAJOR_VERSION= 1
 SO_MINOR_VERSION= 0
 
 override CPPFLAGS := -I$(srcdir) $(CPPFLAGS)
-
 override DLLLIBS := $(BE_DLLLIBS) $(DLLLIBS)
+rpath :=
 
 OBJS = pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o
 
@@ -46,7 +46,7 @@ include $(top_srcdir)/src/Makefile.shlib
 
 install: installdirs all
 ifeq ($(enable_shared), yes)
-	$(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(libdir)/plpgsql$(DLSUFFIX)
+	$(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(pkglibdir)/plpgsql$(DLSUFFIX)
 else
 	@echo "*****"; \
 	 echo "* PL/pgSQL was not installed due to lack of shared library support."; \
@@ -54,10 +54,10 @@ else
 endif
 
 installdirs:
-	$(mkinstalldirs) $(DESTDIR)$(libdir)
+	$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
 
 uninstall:
-	rm -f $(DESTDIR)$(libdir)/plpgsql$(DLSUFFIX)
+	rm -f $(DESTDIR)$(pkglibdir)/plpgsql$(DLSUFFIX)
 
 pl_handler.o pl_comp.o pl_exec.o pl_funcs.o: plpgsql.h $(srcdir)/pl.tab.h
 
diff --git a/src/pl/plpython/Makefile b/src/pl/plpython/Makefile
index 782d07ee3f5e7704f80914866e6d4d4f16186f6b..dd92986304e1651c4e43794b605338e45c1cdf03 100644
--- a/src/pl/plpython/Makefile
+++ b/src/pl/plpython/Makefile
@@ -1,4 +1,4 @@
-# $Header: /cvsroot/pgsql/src/pl/plpython/Makefile,v 1.9 2001/08/27 00:29:49 petere Exp $
+# $Header: /cvsroot/pgsql/src/pl/plpython/Makefile,v 1.10 2001/09/16 16:11:11 petere Exp $
 
 subdir = src/pl/plpython
 top_builddir = ../../..
@@ -17,8 +17,8 @@ endif
 ifneq (,$(findstring yes, $(shared_libpython)$(allow_nonpic_in_shlib)))
 
 override CPPFLAGS := -I$(srcdir) $(python_includespec) $(CPPFLAGS)
-
 override DLLLIBS := $(BE_DLLLIBS) $(DLLLIBS)
+rpath :=
 
 NAME = plpython
 SO_MAJOR_VERSION = 0
@@ -33,13 +33,13 @@ include $(top_srcdir)/src/Makefile.shlib
 all: all-lib
 
 install: all installdirs
-	$(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(libdir)/plpython$(DLSUFFIX)
+	$(INSTALL_SHLIB) $(shlib) $(DESTDIR)$(pkglibdir)/plpython$(DLSUFFIX)
 
 installdirs:
-	$(mkinstalldirs) $(DESTDIR)$(libdir)
+	$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
 
 uninstall:
-	rm -f $(DESTDIR)$(libdir)/plpython$(DLSUFFIX)
+	rm -f $(DESTDIR)$(pkglibdir)/plpython$(DLSUFFIX)
 
 clean distclean maintainer-clean: clean-lib
 	rm -f $(OBJS)
diff --git a/src/pl/tcl/Makefile b/src/pl/tcl/Makefile
index a78687299ed9a216635e04391b69ed590c46c8c4..c52ed2693fe9acd156aa2ff30e08d05cdc601b38 100644
--- a/src/pl/tcl/Makefile
+++ b/src/pl/tcl/Makefile
@@ -2,7 +2,7 @@
 #
 # Makefile for the pltcl shared object
 #
-# $Header: /cvsroot/pgsql/src/pl/tcl/Makefile,v 1.33 2001/05/11 23:38:06 petere Exp $
+# $Header: /cvsroot/pgsql/src/pl/tcl/Makefile,v 1.34 2001/09/16 16:11:11 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -93,19 +93,19 @@ endif
 pltcl$(DLSUFFIX): pltcl.o
 
 install: all installdirs
-	$(INSTALL_SHLIB) $(DLOBJS) $(DESTDIR)$(libdir)/$(DLOBJS)
+	$(INSTALL_SHLIB) $(DLOBJS) $(DESTDIR)$(pkglibdir)/$(DLOBJS)
 ifeq ($(enable_pltcl_unknown), yes)
 	$(MAKE) -C modules $@
 endif
 
 installdirs:
-	$(mkinstalldirs) $(DESTDIR)$(libdir)
+	$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
 ifeq ($(enable_pltcl_unknown), yes)
 	$(MAKE) -C modules $@
 endif
 
 uninstall:
-	rm -f $(DESTDIR)$(libdir)/$(DLOBJS)
+	rm -f $(DESTDIR)$(pkglibdir)/$(DLOBJS)
 ifeq ($(enable_pltcl_unknown), yes)
 	$(MAKE) -C modules $@
 endif
diff --git a/src/test/regress/GNUmakefile b/src/test/regress/GNUmakefile
index 595c74f5e2aca996db6099c3990952b52cbae753..84d2959e4f546424a2c0de7df09147b6ce2466a9 100644
--- a/src/test/regress/GNUmakefile
+++ b/src/test/regress/GNUmakefile
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/test/regress/GNUmakefile,v 1.34 2001/04/04 21:15:56 tgl Exp $
+#    $Header: /cvsroot/pgsql/src/test/regress/GNUmakefile,v 1.35 2001/09/16 16:11:11 petere Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -34,6 +34,7 @@ all: pg_regress
 pg_regress: pg_regress.sh GNUmakefile
 	sed -e 's,@bindir@,$(bindir),g' \
 	    -e 's,@libdir@,$(libdir),g' \
+	    -e 's,@pkglibdir@,$(pkglibdir),g' \
 	    -e 's,@datadir@,$(datadir),g' \
 	    -e 's/@VERSION@/$(VERSION)/g' \
 	    -e 's/@host_tuple@/$(host_tuple)/g' \
diff --git a/src/test/regress/pg_regress.sh b/src/test/regress/pg_regress.sh
index 552724a10f142b0682fbfa0253409b7327f50825..c3250358991640a4a9ce313325d457428c48458d 100644
--- a/src/test/regress/pg_regress.sh
+++ b/src/test/regress/pg_regress.sh
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.21 2001/05/27 09:59:30 petere Exp $
+# $Header: /cvsroot/pgsql/src/test/regress/Attic/pg_regress.sh,v 1.22 2001/09/16 16:11:11 petere Exp $
 
 me=`basename $0`
 : ${TMPDIR=/tmp}
@@ -70,6 +70,7 @@ fi
 : ${outputdir=.}
 
 libdir='@libdir@'
+pkglibdir='@pkglibdir@'
 bindir='@bindir@'
 datadir='@datadir@'
 host_platform='@host_tuple@'
@@ -271,6 +272,7 @@ then
 
     bindir=$temp_install/install/$bindir
     libdir=$temp_install/install/$libdir
+    pkglibdir=$temp_install/install/$pkglibdir
     datadir=$temp_install/install/$datadir
     PGDATA=$temp_install/data
 
@@ -450,7 +452,7 @@ fi
 
 if [ "$enable_shared" = yes ]; then
         message "installing PL/pgSQL"
-        "$bindir/createlang" -L "$libdir" $psql_options plpgsql $dbname
+        "$bindir/createlang" -L "$pkglibdir" $psql_options plpgsql $dbname
         if [ $? -ne 0 ] && [ $? -ne 2 ]; then
             echo "$me: createlang failed"
             (exit 2); exit