From f43ec05d05bb22e7bd398ea7a8399d157eca6fb4 Mon Sep 17 00:00:00 2001
From: Bruce Momjian <bruce@momjian.us>
Date: Wed, 8 Mar 2000 01:58:46 +0000
Subject: [PATCH] I've made a diff against the 7.0beta1 tree that accomplishes
 several things:

        1) adds NetBSD shared lib support on both ELF and a.out platforms

        2) replaces "-L$(LIBPQDIR) -lpq" with "$(LIBPQ)" defined in
           Makefile.global.  This makes it much easier to build stuff in
           the source tree after you've already installed the libraries.

        3) adds TEMPLATEDIR in Makefile.global that indicates where the
           database templates are stored.  This separates the template files
           from real libraries that are installed in $(LIBDIR).
        4) changes include order of <readline/readline.h> and <readline.h>.
           The latest GNU readline installs its headers under a readline
           subdirectory.

In addition to applying the patch below the following files need to be copied:

        backend/port/dynloader:
                bsd.h -> netbsd.h
                bsd.c -> netbsd.c
        include/port:
                bsd.h -> netbsd.h
        makefiles:
                Makefile.bsd -> Makefile.netbsd

It would be great to see this incorporated into the source tree before
the 7.0 release is cut.

        Thanks!

     -- Johnny C. Lam <lamj@stat.cmu.edu>
---
 src/Makefile.global.in               |  10 ++-
 src/Makefile.shlib                   |  20 ++++-
 src/backend/Makefile                 |  25 ++++---
 src/backend/port/dynloader/netbsd.c  | 107 +++++++++++++++++++++++++++
 src/backend/port/dynloader/netbsd.h  |  49 ++++++++++++
 src/bin/pg_ctl/Makefile              |   4 +-
 src/bin/pg_dump/Makefile.in          |   4 +-
 src/bin/pg_encoding/Makefile         |   4 +-
 src/bin/pgtclsh/Makefile             |   7 +-
 src/bin/psql/Makefile.in             |   4 +-
 src/bin/psql/input.h                 |  18 ++---
 src/configure.in                     |   6 +-
 src/include/port/netbsd.h            |  43 +++++++++++
 src/interfaces/ecpg/lib/Makefile.in  |   8 +-
 src/interfaces/jdbc/Makefile         |  10 +--
 src/interfaces/libpgeasy/Makefile.in |   6 +-
 src/interfaces/libpgtcl/Makefile.in  |   4 +-
 src/interfaces/libpq++/Makefile.in   |   6 +-
 src/makefiles/Makefile.netbsd        |  16 ++++
 src/pl/plpgsql/src/Makefile.in       |   4 +-
 src/pl/tcl/Makefile                  |   4 +-
 21 files changed, 297 insertions(+), 62 deletions(-)
 create mode 100644 src/backend/port/dynloader/netbsd.c
 create mode 100644 src/backend/port/dynloader/netbsd.h
 create mode 100644 src/include/port/netbsd.h
 create mode 100644 src/makefiles/Makefile.netbsd

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 5027503bc60..658a2b1d891 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 169e59311dc..441feec22a5 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 fe77dde8e23..1033de1c8ab 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 00000000000..b77dea182f7
--- /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 00000000000..ad583242835
--- /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 6f57b868de4..c9315a16145 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 f387b729e0b..752b4af1a6f 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 ddad3ecb281..df4e9d7f3f8 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 459ed4660b1..35894763387 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 976f07c8f30..6221d4cb89c 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 e539ba29145..c141d1658cd 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 dd79e1a9774..45ecc9117bb 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 00000000000..8406844d079
--- /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 a462030ff5b..de846dd7f9c 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 faf22386a23..95789f765f3 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 46adbd683de..b7e0a52eb7b 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 3b5f15b85a1..fa766ff5f0b 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 b6f57dc8cf3..d8512543120 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 00000000000..14ebbfecf33
--- /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 781c4833015..049cbde284b 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 8e400e1dfab..085baeb5924 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.
-- 
GitLab