diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 5027503bc60448d9ce7c9a4b7b9cf727a47cf1d2..658a2b1d8915f4f2b021ed16c7328827de8b360b 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.66 2000/02/10 19:11:17 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/Makefile.global.in,v 1.67 2000/03/08 01:58:15 momjian Exp $
 #
 # NOTES
 #    Essentially all Postgres make files include this file and use the
@@ -54,6 +54,10 @@ BSD_SHLIB= true
 ELF_SYSTEM= @ELF_SYS@
 
 LIBPQDIR:= $(SRCDIR)/interfaces/libpq
+LIBPGTCLDIR:= $(SRCDIR)/interfaces/libpgtcl
+
+LIBPQ:= -L$(LIBPQDIR) -lpq
+LIBPGTCL:= -L$(LIBPGTCLDIR) -lpgtcl
 
 # For convenience, POSTGRESDIR is where BINDIR, and LIBDIR
 # and other target destinations are rooted.  Of course, each of these is
@@ -70,6 +74,10 @@ BINDIR= $(POSTGRESDIR)/bin
 # command line.
 LIBDIR= $(POSTGRESDIR)/lib
 
+# Where the database templates are stored
+#
+TEMPLATEDIR= $(POSTGRESDIR)/lib
+
 # This is the directory where IPC utilities ipcs and ipcrm are located
 #
 IPCS=@ipcs@
diff --git a/src/Makefile.shlib b/src/Makefile.shlib
index 169e59311dc222299988a966475f1ff7385c77fb..441feec22a5e63b101d118edd4c33ed7fe973be2 100644
--- a/src/Makefile.shlib
+++ b/src/Makefile.shlib
@@ -6,7 +6,7 @@
 # Copyright (c) 1998, Regents of the University of California
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.17 1999/12/09 19:14:22 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/Makefile.shlib,v 1.18 2000/03/08 01:58:15 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -109,6 +109,24 @@ ifeq ($(PORTNAME), freebsd)
   endif
 endif
 
+ifeq ($(PORTNAME), netbsd)
+  ifdef BSD_SHLIB
+    install-shlib-dep	:= install-shlib
+    soname		:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)
+    shlib		:= lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION).$(SO_MINOR_VERSION)
+    ifdef ELF_SYSTEM
+      LD		:= $(CC)
+      LDFLAGS_SL	:= -shared -Wl,-soname -Wl,$(soname)
+      ifneq ($(SHLIB_LINK),)
+        LDFLAGS_SL	+= -Wl,-R$(LIBDIR)
+      endif
+    else
+      LDFLAGS_SL	:= -x -Bshareable -Bforcearchive
+    endif
+    CFLAGS		+= $(CFLAGS_SL)
+  endif
+endif
+
 ifeq ($(PORTNAME), hpux)
   install-shlib-dep	:= install-shlib
 # HPUX doesn't believe in version numbers for shlibs
diff --git a/src/backend/Makefile b/src/backend/Makefile
index fe77dde8e236e54cdcfc8d1721d30059c30db569..1033de1c8abb6155b23f82212710835e84fefc57 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -34,7 +34,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.43 2000/02/27 01:26:12 tgl Exp $
+#    $Header: /cvsroot/pgsql/src/backend/Makefile,v 1.44 2000/03/08 01:58:16 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -165,10 +165,11 @@ endif
 # and (2) the parameters of a database system should be set at initdb time,
 # not at postgres build time.
 
-.PHONY: install install-bin install-lib install-headers
+.PHONY: install install-bin install-templates install-headers
 
-install: $(LIBDIR) $(BINDIR) $(HEADERDIR) postgres $(POSTGRES_IMP) \
-         install-bin install-lib install-headers
+install: $(LIBDIR) $(BINDIR) $(HEADERDIR) $(TEMPLATEDIR) \
+         postgres $(POSTGRES_IMP) \
+         install-bin install-templates install-headers
 
 install-bin: $(BINDIR) postgres$(X) $(POSTGRES_IMP)
 	$(INSTALL) $(INSTL_EXE_OPTS) postgres$(X) $(BINDIR)/postgres$(X)
@@ -184,22 +185,22 @@ ifeq ($(MAKE_DLL), true)
 endif
 endif
 
-install-lib: $(LIBDIR) \
+install-templates: $(TEMPLATEDIR) \
          global1.bki.source local1_template1.bki.source \
          global1.description local1_template1.description \
          libpq/pg_hba.conf.sample optimizer/geqo/pg_geqo.sample
 	$(INSTALL) $(INSTLOPTS) global1.bki.source \
-	  $(LIBDIR)/global1.bki.source
+	  $(TEMPLATEDIR)/global1.bki.source
 	$(INSTALL) $(INSTLOPTS) global1.description \
-	  $(LIBDIR)/global1.description
+	  $(TEMPLATEDIR)/global1.description
 	$(INSTALL) $(INSTLOPTS) local1_template1.bki.source \
-	  $(LIBDIR)/local1_template1.bki.source
+	  $(TEMPLATEDIR)/local1_template1.bki.source
 	$(INSTALL) $(INSTLOPTS) local1_template1.description \
-	  $(LIBDIR)/local1_template1.description
+	  $(TEMPLATEDIR)/local1_template1.description
 	$(INSTALL) $(INSTLOPTS) libpq/pg_hba.conf.sample \
-	  $(LIBDIR)/pg_hba.conf.sample
+	  $(TEMPLATEDIR)/pg_hba.conf.sample
 	$(INSTALL) $(INSTLOPTS) optimizer/geqo/pg_geqo.sample \
-	  $(LIBDIR)/pg_geqo.sample
+	  $(TEMPLATEDIR)/pg_geqo.sample
 
 install-headers: fmgr.h $(SRCDIR)/include/config.h
 	-@if [ ! -d $(HEADERDIR) ]; then mkdir $(HEADERDIR); fi
@@ -263,6 +264,8 @@ $(LIBDIR):
 	mkdir $@
 $(HEADERDIR):
 	mkdir $@
+$(TEMPLATEDIR):
+	mkdir $@
 
 #############################################################################
 #
diff --git a/src/backend/port/dynloader/netbsd.c b/src/backend/port/dynloader/netbsd.c
new file mode 100644
index 0000000000000000000000000000000000000000..b77dea182f7a7439fee190a2512d971b3f41e704
--- /dev/null
+++ b/src/backend/port/dynloader/netbsd.c
@@ -0,0 +1,107 @@
+/*-
+ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *	  notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *	  notice, this list of conditions and the following disclaimer in the
+ *	  documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *	  must display the following acknowledgement:
+ *		This product includes software developed by the University of
+ *		California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *	  may be used to endorse or promote products derived from this software
+ *	  without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.	IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "@(#)dl.c	5.4 (Berkeley) 2/23/91";
+
+#endif	 /* LIBC_SCCS and not lint */
+
+#include <sys/types.h>
+#include <nlist.h>
+#include "link.h"
+#include <dlfcn.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "dynloader.h"
+
+static char error_message[BUFSIZ];
+
+char *
+BSD44_derived_dlerror(void)
+{
+	static char ret[BUFSIZ];
+
+	strcpy(ret, error_message);
+	error_message[0] = 0;
+	return (ret[0] == 0) ? (char *) NULL : ret;
+}
+
+void *
+BSD44_derived_dlopen(const char *file, int num)
+{
+#if defined(__mips__) || (defined(__NetBSD__) && defined(__vax__))
+	sprintf(error_message, "dlopen (%s) not supported", file);
+	return NULL;
+#else
+	void	   *vp;
+
+	if ((vp = dlopen((char *) file, num)) == (void *) NULL)
+		sprintf(error_message, "dlopen (%s) failed", file);
+	return vp;
+#endif
+}
+
+void *
+BSD44_derived_dlsym(void *handle, const char *name)
+{
+#if defined(__mips__) || (defined(__NetBSD__) && defined(__vax__))
+	sprintf(error_message, "dlsym (%s) failed", name);
+	return NULL;
+#elif defined(__ELF__)
+	return dlsym(handle, name);
+#else
+	void	   *vp;
+	char		buf[BUFSIZ];
+
+	if (*name != '_')
+	{
+		sprintf(buf, "_%s", name);
+		name = buf;
+	}
+	if ((vp = dlsym(handle, (char *) name)) == (void *) NULL)
+		sprintf(error_message, "dlsym (%s) failed", name);
+	return vp;
+#endif
+}
+
+void
+BSD44_derived_dlclose(void *handle)
+{
+#if defined(__mips__) || (defined(__NetBSD__) && defined(__vax__))
+#else
+	dlclose(handle);
+#endif
+}
diff --git a/src/backend/port/dynloader/netbsd.h b/src/backend/port/dynloader/netbsd.h
new file mode 100644
index 0000000000000000000000000000000000000000..ad5832428359493bd1ee9cbfdd24dd869bbe8c78
--- /dev/null
+++ b/src/backend/port/dynloader/netbsd.h
@@ -0,0 +1,49 @@
+/*-------------------------------------------------------------------------
+ *
+ * port_protos.h
+ *	  port-specific prototypes for NetBSD 1.0
+ *
+ *
+ * Portions Copyright (c) 1996-2000, PostgreSQL, Inc
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $Id: netbsd.h,v 1.1 2000/03/08 01:58:17 momjian Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PORT_PROTOS_H
+#define PORT_PROTOS_H
+
+#include <sys/types.h>
+#include <nlist.h>
+#include "link.h"
+
+#include "postgres.h"
+
+#include "fmgr.h"
+#include "utils/dynamic_loader.h"
+
+/* dynloader.c */
+/*
+ * Dynamic Loader on NetBSD 1.0.
+ *
+ * this dynamic loader uses the system dynamic loading interface for shared
+ * libraries (ie. dlopen/dlsym/dlclose). The user must specify a shared
+ * library as the file to be dynamically loaded.
+ *
+ * agc - I know this is all a bit crufty, but it does work, is fairly
+ * portable, and works (the stipulation that the d.l. function must
+ * begin with an underscore is fairly tricky, and some versions of
+ * NetBSD (like 1.0, and 1.0A pre June 1995) have no dlerror.)
+ */
+#define		   pg_dlopen(f)    BSD44_derived_dlopen(f, 1)
+#define		   pg_dlsym		   BSD44_derived_dlsym
+#define		   pg_dlclose	   BSD44_derived_dlclose
+#define		   pg_dlerror	   BSD44_derived_dlerror
+
+char	   *BSD44_derived_dlerror(void);
+void	   *BSD44_derived_dlopen(const char *filename, int num);
+void	   *BSD44_derived_dlsym(void *handle, const char *name);
+void		BSD44_derived_dlclose(void *handle);
+
+#endif	 /* PORT_PROTOS_H */
diff --git a/src/bin/pg_ctl/Makefile b/src/bin/pg_ctl/Makefile
index 6f57b868de43fabbcba20fdab9c8cdd3e0ce07fe..c9315a16145ed9579c32911633556403bc99aad8 100644
--- a/src/bin/pg_ctl/Makefile
+++ b/src/bin/pg_ctl/Makefile
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.3 1999/12/22 04:12:55 ishii Exp $
+#    $Header: /cvsroot/pgsql/src/bin/pg_ctl/Makefile,v 1.4 2000/03/08 01:58:18 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -21,7 +21,7 @@ pg_ctl: pg_ctl.sh
 
 install: pg_ctl
 	$(INSTALL) $(INSTL_EXE_OPTS) $+ $(BINDIR)
-	$(INSTALL) $(INSTLOPTS) postmaster.opts.default.sample $(LIBDIR)
+	$(INSTALL) $(INSTLOPTS) postmaster.opts.default.sample $(TEMPLATEDIR)
 
 clean:
 	rm -f pg_ctl
diff --git a/src/bin/pg_dump/Makefile.in b/src/bin/pg_dump/Makefile.in
index f387b729e0b7fb8d0b6a74de90d45697c992c595..752b4af1a6f2b28c718014d19b3e1cc5a63cf09c 100644
--- a/src/bin/pg_dump/Makefile.in
+++ b/src/bin/pg_dump/Makefile.in
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/Makefile.in,v 1.11 1999/01/17 06:19:05 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/bin/pg_dump/Attic/Makefile.in,v 1.12 2000/03/08 01:58:19 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -29,7 +29,7 @@ endif
 all: submake pg_dump
 
 pg_dump: $(OBJS) $(LIBPQDIR)/libpq.a
-	$(CC) -o pg_dump -L$(LIBPQDIR) $(OBJS) -lpq $(LDFLAGS)
+	$(CC) -o pg_dump $(OBJS) $(LIBPQ) $(LDFLAGS)
 
 ../../utils/strdup.o:
 	$(MAKE) -C ../../utils strdup.o
diff --git a/src/bin/pg_encoding/Makefile b/src/bin/pg_encoding/Makefile
index ddad3ecb2811babdcd97e0de6868306fccddc074..df4e9d7f3f8e17bf8178813cacf34e933e33d517 100644
--- a/src/bin/pg_encoding/Makefile
+++ b/src/bin/pg_encoding/Makefile
@@ -6,7 +6,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/Makefile,v 1.4 2000/01/15 18:30:32 petere Exp $
+#    $Header: /cvsroot/pgsql/src/bin/pg_encoding/Attic/Makefile,v 1.5 2000/03/08 01:58:20 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -22,7 +22,7 @@ CFLAGS:= -I$(SRCDIR)/include $(CFLAGS)
 all: submake pg_encoding
 
 pg_encoding: $(OBJS)
-	$(CC) -o pg_encoding $(OBJS) -L$(LIBPQDIR) -lpq $(LDFLAGS) $(CFLAGS)
+	$(CC) -o pg_encoding $(OBJS) $(LIBPQ) $(LDFLAGS) $(CFLAGS)
 
 .PHONY: submake
 
diff --git a/src/bin/pgtclsh/Makefile b/src/bin/pgtclsh/Makefile
index 459ed4660b11d704770222e90fa98060f0d3b9d3..3589476338713536d595ace6f89c6bd0ebf71591 100644
--- a/src/bin/pgtclsh/Makefile
+++ b/src/bin/pgtclsh/Makefile
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/pgtclsh/Attic/Makefile,v 1.24 1998/10/27 21:51:54 tgl Exp $
+#    $Header: /cvsroot/pgsql/src/bin/pgtclsh/Attic/Makefile,v 1.25 2000/03/08 01:58:21 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -22,16 +22,13 @@ ifeq ($(USE_TK), true)
 include Makefile.tkdefs
 endif
 
-CFLAGS+= $(X_CFLAGS) -I$(SRCDIR)/interfaces/libpgtcl 
+CFLAGS+= $(X_CFLAGS) -I$(LIBPGTCLDIR)
 
 ifdef KRBVERS
 LDFLAGS+= $(KRBLIBS)
 CFLAGS+= $(KRBFLAGS)
 endif
 
-LIBPGTCL= -L$(SRCDIR)/interfaces/libpgtcl -lpgtcl
-LIBPQ= -L$(LIBPQDIR) -lpq
-
 # If we are here then TCL is available
 PGMS = pgtclsh
 INSTPGMS = install_tcl
diff --git a/src/bin/psql/Makefile.in b/src/bin/psql/Makefile.in
index 976f07c8f30acbaa83a3de1e1e1c0cfaf2b30ed4..6221d4cb89c686d1accc46c7246bd8356a196fab 100644
--- a/src/bin/psql/Makefile.in
+++ b/src/bin/psql/Makefile.in
@@ -7,7 +7,7 @@
 #
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/bin/psql/Attic/Makefile.in,v 1.20 2000/01/19 02:59:00 petere Exp $
+#    $Header: /cvsroot/pgsql/src/bin/psql/Attic/Makefile.in,v 1.21 2000/03/08 01:58:22 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -56,7 +56,7 @@ endif
 # End of hacks for picking up backend 'port' modules
 
 psql: $(OBJS) $(LIBPQDIR)/libpq.a
-	$(CC) -o psql -L$(LIBPQDIR) $(OBJS) -lpq $(LDFLAGS)
+	$(CC) -o psql $(OBJS) $(LIBPQ) $(LDFLAGS)
 
 help.o: sql_help.h
 
diff --git a/src/bin/psql/input.h b/src/bin/psql/input.h
index e539ba291459a11901069c1bd5554712f2b78498..c141d1658cd09c80e542d1230a60259a1a73b125 100644
--- a/src/bin/psql/input.h
+++ b/src/bin/psql/input.h
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.8 2000/02/16 13:15:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.9 2000/03/08 01:58:22 momjian Exp $
  */
 #ifndef INPUT_H
 #define INPUT_H
@@ -15,22 +15,22 @@
  * USE_READLINE and USE_HISTORY are the definite pointers regarding existence or not.
  */
 #ifdef HAVE_LIBREADLINE
-# ifdef HAVE_READLINE_H
-#  include <readline.h>
-#  define USE_READLINE 1
-# elif defined(HAVE_READLINE_READLINE_H)
+# if defined(HAVE_READLINE_READLINE_H)
 #  include <readline/readline.h>
 #  define USE_READLINE 1
+# elif defined(HAVE_READLINE_H)
+#  include <readline.h>
+#  define USE_READLINE 1
 # endif
 #endif
 
 #if defined(HAVE_LIBHISTORY) || (defined(HAVE_LIBREADLINE) && defined(HAVE_HISTORY_IN_READLINE))
-# ifdef HAVE_HISTORY_H
-#  include <history.h>
-#  define USE_HISTORY 1
-# elif defined(HAVE_READLINE_HISTORY_H)
+# if defined(HAVE_READLINE_HISTORY_H)
 #  include <readline/history.h>
 #  define USE_HISTORY 1
+# elif defined(HAVE_HISTORY_H)
+#  include <history.h>
+#  define USE_HISTORY 1
 # endif
 #endif
 
diff --git a/src/configure.in b/src/configure.in
index dd79e1a9774398ca3e5fd94fd9d0f20fe0e6625f..45ecc9117bb82dc65037597656869d99a7112211 100644
--- a/src/configure.in
+++ b/src/configure.in
@@ -23,11 +23,7 @@ case "$host_os" in
     bsdi*) os=bsdi need_tas=no ;;
  freebsd1*|freebsd2*) os=freebsd need_tas=no ;;
  freebsd*) os=freebsd need_tas=no elf=yes ;;
-  netbsd*)
-	os=bsd need_tas=no
-	case "$host_cpu" in
-	  powerpc) elf=yes ;;
-	esac ;;
+  netbsd*) os=netbsd need_tas=no ;;
   openbsd*) os=bsd need_tas=no ;;
     dgux*) os=dgux need_tas=no ;;
      aix*) os=aix need_tas=no ;;
diff --git a/src/include/port/netbsd.h b/src/include/port/netbsd.h
new file mode 100644
index 0000000000000000000000000000000000000000..8406844d079e7683b8466d0a970846291d62f94e
--- /dev/null
+++ b/src/include/port/netbsd.h
@@ -0,0 +1,43 @@
+#define USE_POSIX_TIME
+
+#if defined(__i386__)
+#define NEED_I386_TAS_ASM
+#define HAS_TEST_AND_SET
+#endif
+
+#if defined(__sparc__)
+#define NEED_SPARC_TAS_ASM
+#define HAS_TEST_AND_SET
+#endif
+
+#if defined(__vax__)
+#define NEED_VAX_TAS_ASM
+#define HAS_TEST_AND_SET
+#endif
+
+#if defined(__ns32k__)
+#define NEED_NS32K_TAS_ASM
+#define HAS_TEST_AND_SET
+#endif
+
+#if defined(__m68k__)
+#define HAS_TEST_AND_SET
+#endif
+
+#if defined(__arm__)
+#define HAS_TEST_AND_SET
+#endif
+
+#if defined(__mips__)
+/* #	undef HAS_TEST_AND_SET */
+#endif
+
+#if defined(__powerpc__)
+#define HAS_TEST_AND_SET
+#endif
+
+#if defined(__powerpc__)
+typedef unsigned int slock_t;
+#else
+typedef unsigned char slock_t;
+#endif
diff --git a/src/interfaces/ecpg/lib/Makefile.in b/src/interfaces/ecpg/lib/Makefile.in
index a462030ff5bb0338c30f097d13dd4cd9a1137a75..de846dd7f9c020728f7d2fb6dd3fbfcedf51a57f 100644
--- a/src/interfaces/ecpg/lib/Makefile.in
+++ b/src/interfaces/ecpg/lib/Makefile.in
@@ -6,18 +6,18 @@
 # Copyright (c) 1994, Regents of the University of California
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.62 2000/03/07 15:10:52 meskes Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/ecpg/lib/Attic/Makefile.in,v 1.63 2000/03/08 01:58:24 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
 NAME= ecpg
 SO_MAJOR_VERSION= 3
-SO_MINOR_VERSION= 1.0
+SO_MINOR_VERSION= 1
 
 SRCDIR= @top_srcdir@
 include $(SRCDIR)/Makefile.global
 
-CFLAGS+= -I../include -I$(SRCDIR)/interfaces/libpq
+CFLAGS+= -I../include -I$(LIBPQDIR)
 
 ifdef KRBVERS
 CFLAGS+= $(KRBFLAGS)
@@ -26,7 +26,7 @@ endif
 OBJS= execute.o typename.o descriptor.o data.o error.o prepare.o memory.o \
 	connect.o misc.o
 
-SHLIB_LINK= -L../../libpq -lpq
+SHLIB_LINK= $(LIBPQ)
 
 # Shared library stuff, also default 'all' target
 include $(SRCDIR)/Makefile.shlib
diff --git a/src/interfaces/jdbc/Makefile b/src/interfaces/jdbc/Makefile
index faf22386a231fa3732526d08ebce50b63ce2dbe1..95789f765f3fe01f9594eaf6260e6dca553b1ec4 100644
--- a/src/interfaces/jdbc/Makefile
+++ b/src/interfaces/jdbc/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for Java JDBC interface
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.16 1999/09/15 21:56:16 peter Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/Makefile,v 1.17 2000/03/08 01:58:25 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -34,11 +34,11 @@ all:
 	@echo
 	@echo If you are using JDK1.1.x, you will need the JDBC1.2 driver.
 	@echo To compile, type:
-	@echo "  make jdbc1"
+	@echo "  $(MAKE) jdbc1"
 	@echo
 	@echo "If you are using JDK1.2 (aka Java2) you need the JDBC2."
 	@echo To compile, type:
-	@echo "  make jdbc2"
+	@echo "  $(MAKE) jdbc2"
 	@echo ------------------------------------------------------------
 
 msg:	
@@ -59,10 +59,10 @@ msg:
 	@echo
 	@echo ------------------------------------------------------------
 	@echo To build the examples, type:
-	@echo "  make examples"
+	@echo "  $(MAKE) examples"
 	@echo
 	@echo "To build the CORBA example (requires Java2):"
-	@echo "  make corba"
+	@echo "  $(MAKE) corba"
 	@echo ------------------------------------------------------------
 	@echo
 
diff --git a/src/interfaces/libpgeasy/Makefile.in b/src/interfaces/libpgeasy/Makefile.in
index 46adbd683de59f7099bbc7a5fd6087f035187fe7..b7e0a52eb7bb4e71b41b494be3090bf02e71b36b 100644
--- a/src/interfaces/libpgeasy/Makefile.in
+++ b/src/interfaces/libpgeasy/Makefile.in
@@ -4,7 +4,7 @@
 #    Makefile for pgeasy library
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/libpgeasy/Attic/Makefile.in,v 1.5 2000/01/10 15:41:28 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/libpgeasy/Attic/Makefile.in,v 1.6 2000/03/08 01:58:33 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -23,9 +23,7 @@ endif
 
 OBJS= libpgeasy.o halt.o
 
-SHLIB_LINK+= -L../libpq -lpq
-
-SHLIB_LINK+= -L../libpq -lpq
+SHLIB_LINK+= $(LIBPQ)
 
 # If crypt is a separate library, rather than part of libc, it may need
 # to be referenced separately to keep (broken) linkers happy.  (This is
diff --git a/src/interfaces/libpgtcl/Makefile.in b/src/interfaces/libpgtcl/Makefile.in
index 3b5f15b85a1039dca114a728c8e3de500588ff94..fa766ff5f0be38f2156948f930622bb9866f514b 100644
--- a/src/interfaces/libpgtcl/Makefile.in
+++ b/src/interfaces/libpgtcl/Makefile.in
@@ -6,7 +6,7 @@
 # Copyright (c) 1994, Regents of the University of California
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/Makefile.in,v 1.38 2000/01/10 15:41:29 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/libpgtcl/Attic/Makefile.in,v 1.39 2000/03/08 01:58:36 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -27,7 +27,7 @@ endif
 
 OBJS= pgtcl.o pgtclCmds.o pgtclId.o
 
-SHLIB_LINK+= -L../libpq -lpq
+SHLIB_LINK+= $(LIBPQ)
 
 # If crypt is a separate library, rather than part of libc, it may need
 # to be referenced separately to keep (broken) linkers happy.  (This is
diff --git a/src/interfaces/libpq++/Makefile.in b/src/interfaces/libpq++/Makefile.in
index b6f57dc8cf365a26ce323829e4f237ee6141715e..d85125431205bd2fe4fe85bc493509956eddad70 100644
--- a/src/interfaces/libpq++/Makefile.in
+++ b/src/interfaces/libpq++/Makefile.in
@@ -6,7 +6,7 @@
 # Copyright (c) 1994, Regents of the University of California
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile.in,v 1.20 2000/01/10 15:41:31 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/Makefile.in,v 1.21 2000/03/08 01:58:37 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -43,9 +43,9 @@ endif
 OBJS = pgconnection.o pgdatabase.o pgtransdb.o pgcursordb.o pglobject.o 
 
 ifeq ($(PORTNAME), win)
-SHLIB_LINK+= --driver-name g++ -L../libpq -lpq
+SHLIB_LINK+= --driver-name g++ $(LIBPQ)
 else
-SHLIB_LINK= -L../libpq -lpq
+SHLIB_LINK= $(LIBPQ)
 endif
 
 # For CC on IRIX, must use CC as linker/archiver of C++ libraries
diff --git a/src/makefiles/Makefile.netbsd b/src/makefiles/Makefile.netbsd
new file mode 100644
index 0000000000000000000000000000000000000000..14ebbfecf337d6da731ea9015745619b78736300
--- /dev/null
+++ b/src/makefiles/Makefile.netbsd
@@ -0,0 +1,16 @@
+ifdef ELF_SYSTEM
+LDFLAGS += -Wl,-E
+endif
+%.so: %.o
+ifdef ELF_SYSTEM
+	$(LD) -x -Bshareable -o $@ $<
+else
+	$(LD) $(LDREL) $(LDOUT) $<.obj -x $<
+	@echo building shared object $@
+	@rm -f $@.pic
+	@${AR} cq $@.pic `lorder $<.obj | tsort`
+	${RANLIB} $@.pic
+	@rm -f $@
+	$(LD) -x -Bshareable -Bforcearchive \
+	  -o $@ $@.pic
+endif
diff --git a/src/pl/plpgsql/src/Makefile.in b/src/pl/plpgsql/src/Makefile.in
index 781c48330150368f3f431f5f6852aed37c35fd0b..049cbde284b1f8757d944be1076239a7ebeffadf 100644
--- a/src/pl/plpgsql/src/Makefile.in
+++ b/src/pl/plpgsql/src/Makefile.in
@@ -4,7 +4,7 @@
 #    Makefile for the plpgsql shared object
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/Makefile.in,v 1.20 2000/02/23 22:24:45 momjian Exp $
+#    $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/Makefile.in,v 1.21 2000/03/08 01:58:44 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -31,7 +31,7 @@ endif
 
 OBJS=	pl_parse.o pl_handler.o pl_comp.o pl_exec.o pl_funcs.o
 
-SHLIB_LINK+= -L$(LIBPQDIR) -lpq
+SHLIB_LINK+= $(LIBPQ)
 
 # If crypt is a separate library, rather than part of libc, it may need
 # to be referenced separately to keep (broken) linkers happy.  (This is
diff --git a/src/pl/tcl/Makefile b/src/pl/tcl/Makefile
index 8e400e1dfab396b8083c521d6715d5048a7d1693..085baeb5924610861ab7c6c34a86834cc861380a 100644
--- a/src/pl/tcl/Makefile
+++ b/src/pl/tcl/Makefile
@@ -4,7 +4,7 @@
 #    Makefile for the pltcl shared object
 #
 # IDENTIFICATION
-#    $Header: /cvsroot/pgsql/src/pl/tcl/Makefile,v 1.10 1998/12/13 23:46:49 tgl Exp $
+#    $Header: /cvsroot/pgsql/src/pl/tcl/Makefile,v 1.11 2000/03/08 01:58:46 momjian Exp $
 #
 #-------------------------------------------------------------------------
 
@@ -75,7 +75,7 @@ CFLAGS+= -I$(SRCDIR)/backend
 
 CFLAGS+= $(TCL_DEFS)
 
-LDADD+= -L$(LIBPQDIR) -lpq
+LDADD+= $(LIBPQ)
         
 #
 # DLOBJS is the dynamically-loaded object file.