diff -urN pgsql/src/Makefile.shlib /usr/src/pgsql/src/Makefile.shlib
--- pgsql/src/Makefile.shlib	Sat Oct 31 04:58:51 1998
+++ /usr/src/pgsql/src/Makefile.shlib	Thu Nov 19 21:45:41 1998
@@ -155,6 +155,10 @@
   endif
 endif
 
+ifeq ($(PORTNAME), win)
+  install-shlib-dep	:= install-shlib
+  shlib				:= $(NAME)$(DLSUFFIX)
+endif
 
 # Default target definition.  Note shlib is empty if not building a shlib.
 
@@ -162,6 +166,7 @@
 
 # Rules to build regular and shared libraries
 
+ifneq ($(PORTNAME), win)
 lib$(NAME).a: $(OBJS)
 ifdef MK_NO_LORDER
 	$(AR) $(AROPT) $@ $(OBJS) 
@@ -169,9 +174,20 @@
 	$(AR) $(AROPT) $@ `lorder $(OBJS) | tsort`
 endif
 	$(RANLIB) $@
+endif
 
+ifneq ($(PORTNAME), win)
 $(shlib): $(OBJS)
 	$(LD) $(LDFLAGS_SL) -o $@ $(OBJS) $(SHLIB_LINK)
+else
+$(shlib) lib$(NAME).a: $(OBJS) $(SRCDIR)/utils/dllinit.o
+	$(DLLTOOL) --export-all --output-def $(NAME).def $(OBJS)
+	$(DLLWRAP) -o $(shlib) --dllname $(shlib) --def $(NAME).def $(OBJS) $(SRCDIR)/utils/dllinit.o $(DLLINIT) $(SHLIB_LINK)
+	$(DLLTOOL) --dllname $(shlib) --def $(NAME).def --output-lib lib$(NAME).a
+
+$(SRCDIR)/utils/dllinit.o: $(SRCDIR)/utils/dllinit.c
+	$(MAKE) -C $(SRCDIR)/utils dllinit.o
+endif
 
 # Rules to install regular and shared libraries
 
@@ -182,6 +198,7 @@
 
 install-shlib: $(shlib)
 	$(INSTALL) $(INSTL_SHLIB_OPTS) $(shlib) $(LIBDIR)/$(shlib)
+ifneq ($(PORTNAME), win)
 	if [ "$(shlib)" != "lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION)" ]; then \
 		cd $(LIBDIR); \
 		rm -f lib$(NAME)$(DLSUFFIX).$(SO_MAJOR_VERSION); \
@@ -192,3 +209,4 @@
 		rm -f lib$(NAME)$(DLSUFFIX); \
 		$(LN_S) $(shlib) lib$(NAME)$(DLSUFFIX); \
 	fi
+endif
diff -urN pgsql/src/backend/Makefile /usr/src/pgsql/src/backend/Makefile
--- pgsql/src/backend/Makefile	Mon Apr 27 06:04:05 1998
+++ /usr/src/pgsql/src/backend/Makefile	Thu Nov 19 21:47:16 1998
@@ -45,12 +45,22 @@
 	main nodes optimizer parser port postmaster regex rewrite \
 	storage tcop utils
 
+ifeq ($(MAKE_DLL), true)
+DLLDIRS = access bootstrap catalog commands executor lib libpq \
+	nodes optimizer parser port postmaster regex rewrite \
+	storage tcop utils
+endif
+
 ifdef TIOGA
 DIRS += tioga
 endif
 
 OBJS = $(DIRS:%=%/SUBSYS.o)
 
+ifeq ($(MAKE_DLL), true)
+DLLOBJS = $(DLLDIRS:%=%/SUBSYS.o)
+endif
+
 # kerberos flags
 
 ifdef KRBVERS
@@ -58,12 +68,35 @@
 LDFLAGS+= $(KRBLIBS)
 endif
 
+ifeq ($(MAKE_DLL), true)
+DLLOBJS+= ../utils/version.o
+DLLLIBS= -L/usr/local/lib -lcygipc -lcrypt -lcygwin -lkernel32
+
+postgres.def: $(DLLOBJS)
+	$(DLLTOOL) --export-all --output-def $@ $(DLLOBJS)
+
+postgres.dll: $(DLLOBJS) ../utils/dllinit.o postgres.def
+	$(DLLWRAP) -o $@ --def postgres.def $(DLLOBJS) ../utils/dllinit.o $(DLLLIBS)
+
+libpostgres.a: $(DLLOBJS) ../utils/dllinit.o postgres.def
+	$(DLLTOOL) --dllname postgres.dll --def postgres.def --output-lib $@
+endif
 
 all: postgres $(POSTGRES_IMP) global1.bki.source local1_template1.bki.source \
 				global1.description local1_template1.description
 
+ifneq ($(PORTNAME), win)
+postgres: fmgr.h $(OBJS) ../utils/version.o
+	$(CC) -o postgres $(OBJS) ../utils/version.o $(LDFLAGS)
+else
+ifeq ($(MAKE_DLL), true)
+postgres: fmgr.h main/SUBSYS.o libpostgres.a postgres.dll
+	$(CC) -o postgres main/SUBSYS.o -L. -lpostgres
+else
 postgres: fmgr.h $(OBJS) ../utils/version.o
 	$(CC) -o postgres $(OBJS) ../utils/version.o $(LDFLAGS)
+endif
+endif
 
 $(OBJS): $(DIRS:%=%.dir)
 
@@ -71,7 +104,10 @@
 	$(MAKE) -C $(subst .dir,,$@) all 
 
 ../utils/version.o:
-	$(MAKE) -C ../utils version.o        
+	$(MAKE) -C ../utils version.o
+
+../utils/dllinit.c:
+	$(MAKE) -C ../utils dllinit.o
 
 global1.bki.source local1_template1.bki.source \
 global1.description local1_template1.description: catalog/$@
@@ -86,7 +122,6 @@
 postgres.o: $(OBJS)
 	$(CC) -r -o postgres.o $(OBJS) $(LDFLAGS)
 
-
 ############################################################################
 # The following targets are specified in make commands that appear in the
 # make files in our subdirectories.
@@ -101,9 +136,14 @@
 
 #############################################################################
 clean:
-	rm -f postgres $(POSTGRES_IMP) fmgr.h parse.h \
+	rm -f postgres$(X) $(POSTGRES_IMP) fmgr.h parse.h \
 	    global1.bki.source local1_template1.bki.source \
 	    global1.description local1_template1.description
+ifeq ($(PORTNAME), win)
+ifeq ($(MAKE_DLL), true)
+	rm -f postgres.dll postgres.def libpostgres.a
+endif
+endif
 	for i in $(DIRS); do $(MAKE) -C $$i clean; done
 
 .DEFAULT:
@@ -129,12 +169,18 @@
          global1.bki.source local1_template1.bki.source \
          global1.description local1_template1.description \
          libpq/pg_hba.conf.sample optimizer/geqo/pg_geqo.sample
-	$(INSTALL) $(INSTL_EXE_OPTS) postgres $(BINDIR)/postgres
+	$(INSTALL) $(INSTL_EXE_OPTS) postgres$(X) $(BINDIR)/postgres$(X)
 ifeq ($(MAKE_EXPORTS), true)
 	$(INSTALL) $(INSTLOPTS) $(POSTGRES_IMP) $(LIBDIR)/$(POSTGRES_IMP)
 endif
 	@rm -f $(BINDIR)/postmaster
-	ln -s postgres $(BINDIR)/postmaster
+	ln -s postgres$(X) $(BINDIR)/postmaster
+ifeq ($(PORTNAME), win)
+ifeq ($(MAKE_DLL), true)
+	$(INSTALL) $(INSTLOPTS) postgres.dll $(BINDIR)/postgres.dll
+	$(INSTALL) $(INSTLOPTS) libpostgres.a $(LIBDIR)/libpostgres.a
+endif
+endif
 	$(INSTALL) $(INSTLOPTS) fmgr.h $(HEADERDIR)/fmgr.h
 	$(INSTALL) $(INSTLOPTS) global1.bki.source \
 	  $(LIBDIR)/global1.bki.source
diff -urN pgsql/src/backend/bootstrap/bootstrap.c /usr/src/pgsql/src/backend/bootstrap/bootstrap.c
--- pgsql/src/backend/bootstrap/bootstrap.c	Tue Sep 01 06:27:21 1998
+++ /usr/src/pgsql/src/backend/bootstrap/bootstrap.c	Thu Nov 19 21:43:33 1998
@@ -17,6 +17,9 @@
 #include <signal.h>
 #include <setjmp.h>
 #include <string.h>
+#ifdef __CYGWIN32__
+#include <getopt.h>
+#endif
 
 #define BOOTSTRAP_INCLUDE		/* mask out stuff in tcop/tcopprot.h */
 
diff -urN pgsql/src/backend/catalog/Makefile /usr/src/pgsql/src/backend/catalog/Makefile
--- pgsql/src/backend/catalog/Makefile	Thu Oct 08 19:29:19 1998
+++ /usr/src/pgsql/src/backend/catalog/Makefile	Thu Nov 19 21:43:35 1998
@@ -39,17 +39,26 @@
                 )
 
 global1.bki.source: $(GENBKI) $(GLOBALBKI_SRCS)
+ifneq ($(PORTNAME), win)
 	sh $(SHOPTS) $(GENBKI) $(BKIOPTS) $(GLOBALBKI_SRCS) > $@ 2>global1.description
+else
+	$(GENBKI) $(BKIOPTS) $(GLOBALBKI_SRCS) > $@ 2>global1.description
+endif
 
 local1_template1.bki.source: $(GENBKI) $(LOCALBKI_SRCS)
+ifneq ($(PORTNAME), win)
 	sh $(SHOPTS) $(GENBKI) $(BKIOPTS) $(LOCALBKI_SRCS) > $@ 2>local1_template1.description
+else
+	$(GENBKI) $(BKIOPTS) $(LOCALBKI_SRCS) > $@ 2>local1_template1.description
+endif
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
 
 clean: 
 	rm -f SUBSYS.o $(OBJS) global1.bki.source local1_template1.bki.source \
-				global1.description local1_template1.description
+				global1.description local1_template1.description \
+				$(GENBKI)
 
 ifeq (depend,$(wildcard depend))
 include depend
diff -urN pgsql/src/backend/libpq/pqcomm.c /usr/src/pgsql/src/backend/libpq/pqcomm.c
--- pgsql/src/backend/libpq/pqcomm.c	Tue Oct 13 21:44:40 1998
+++ /usr/src/pgsql/src/backend/libpq/pqcomm.c	Thu Nov 19 21:43:53 1998
@@ -88,6 +88,17 @@
 void
 pq_init(int fd)
 {
+#ifdef __CYGWIN32__
+	/*  the fd file handle isn't readable :)
+	    it can probably be an error in Cygwin B19.3 */
+	int flags, res;
+	
+/*	flags = fcntl(fd, F_GETFL);*/
+/*	TPRINTF(TRACE_VERBOSE, "flags=%d", flags);*/
+	flags = O_RDWR;
+	res = fcntl(fd, F_SETFL, flags);
+#endif
+	
 	Pfin = fdopen(fd, "r");
 	Pfout = fdopen(dup(fd), "w");
 	if (!Pfin || !Pfout)
diff -urN pgsql/src/backend/port/dynloader/win.c /usr/src/pgsql/src/backend/port/dynloader/win.c
--- pgsql/src/backend/port/dynloader/win.c	Thu Jan 01 01:00:00 1970
+++ /usr/src/pgsql/src/backend/port/dynloader/win.c	Thu Nov 19 21:44:19 1998
@@ -0,0 +1,4 @@
+/* Dummy file used for nothing at this point
+ *
+ * see win.h
+ */
diff -urN pgsql/src/backend/port/dynloader/win.h /usr/src/pgsql/src/backend/port/dynloader/win.h
--- pgsql/src/backend/port/dynloader/win.h	Thu Jan 01 01:00:00 1970
+++ /usr/src/pgsql/src/backend/port/dynloader/win.h	Thu Nov 19 21:44:19 1998
@@ -0,0 +1,34 @@
+/*-------------------------------------------------------------------------
+ *
+ * win.h--
+ *	  port-specific prototypes for Intel x86/Window NT
+ *
+ *
+ * Copyright (c) 1994, Regents of the University of California
+ *
+ * win.h,v 1.2 1995/03/17 06:40:18 andrew Exp
+ *
+ *-------------------------------------------------------------------------
+  */
+#ifndef PORT_PROTOS_H
+#define PORT_PROTOS_H
+
+#include <dlfcn.h>
+#include "fmgr.h"				/* for func_ptr */
+#include "utils/dynamic_loader.h"
+
+ /* dynloader.c */
+/*
+ * Dynamic Loader on Intel x86/Windows NT
+ *
+ * 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.
+ *
+  */
+#define pg_dlopen(f)		dlopen(f,1)
+#define pg_dlsym		dlsym
+#define pg_dlclose		dlclose
+#define pg_dlerror		dlerror
+
+#endif	 /* PORT_PROTOS_H */
diff -urN pgsql/src/backend/port/snprintf.c /usr/src/pgsql/src/backend/port/snprintf.c
--- pgsql/src/backend/port/snprintf.c	Thu Oct 08 01:34:47 1998
+++ /usr/src/pgsql/src/backend/port/snprintf.c	Thu Nov 19 21:44:20 1998
@@ -36,6 +36,7 @@
 #include "pathnames.h"
 #endif
 
+#include <features.h>
 #include "postgres.h"
 
 #include "regex/cdefs.h"
diff -urN pgsql/src/backend/postmaster/postmaster.c /usr/src/pgsql/src/backend/postmaster/postmaster.c
--- pgsql/src/backend/postmaster/postmaster.c	Tue Sep 01 06:31:21 1998
+++ /usr/src/pgsql/src/backend/postmaster/postmaster.c	Thu Nov 19 21:44:24 1998
@@ -73,6 +73,10 @@
 #include <sys/select.h>
 #endif
 
+#ifdef __CYGWIN32__
+#include <getopt.h>
+#endif
+
 #include "storage/ipc.h"
 #include "libpq/libpq.h"
 #include "libpq/auth.h"
@@ -522,6 +526,7 @@
 			exit(1);
 		}
 	}
+#ifndef __CYGWIN32__
 	status = StreamServerPort(NULL, PostPortName, &ServerSock_UNIX);
 	if (status != STATUS_OK)
 	{
@@ -529,7 +534,7 @@
 				progname);
 		exit(1);
 	}
-
+#endif
 	/* set up shared memory and semaphores */
 	EnableMemoryContext(TRUE);
 	reset_shared(PostPortName);
@@ -688,12 +693,14 @@
 
 		/* new connection pending on our well-known port's socket */
 
+#ifndef __CYGWIN32__
 		if (ServerSock_UNIX != INVALID_SOCK &&
 			FD_ISSET(ServerSock_UNIX, &rmask) &&
 			(port = ConnCreate(ServerSock_UNIX)) != NULL)
 			PacketReceiveSetup(&port->pktInfo,
 							   readStartupPacket,
 							   (void *) port);
+#endif
 
 		if (ServerSock_INET != INVALID_SOCK &&
 			FD_ISSET(ServerSock_INET, &rmask) &&
@@ -802,6 +809,7 @@
 	FD_ZERO(rmask);
 	FD_ZERO(wmask);
 
+#ifndef __CYGWIN32__
 	if (ServerSock_UNIX != INVALID_SOCK)
 	{
 		FD_SET(ServerSock_UNIX, rmask);
@@ -809,6 +817,7 @@
 		if (ServerSock_UNIX > nsocks)
 			nsocks = ServerSock_UNIX;
 	}
+#endif
 
 	if (ServerSock_INET != INVALID_SOCK)
 	{
@@ -1433,7 +1442,9 @@
 	/* Close the postmater sockets */
 	if (NetServer)
 		StreamClose(ServerSock_INET);
+#ifndef __CYGWIN32__
 	StreamClose(ServerSock_UNIX);
+#endif
 
 	/* Save port for ps status */
 	MyProcPort = port;
@@ -1542,8 +1553,10 @@
 	 */
 	if (ServerSock_INET != INVALID_SOCK)
 		StreamClose(ServerSock_INET);
+#ifndef __CYGWIN32__
 	if (ServerSock_UNIX != INVALID_SOCK)
 		StreamClose(ServerSock_UNIX);
+#endif
 	proc_exit(status);
 }
 
diff -urN pgsql/src/backend/tcop/postgres.c /usr/src/pgsql/src/backend/tcop/postgres.c
--- pgsql/src/backend/tcop/postgres.c	Fri Oct 16 07:05:13 1998
+++ /usr/src/pgsql/src/backend/tcop/postgres.c	Thu Nov 19 21:44:35 1998
@@ -39,6 +39,9 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <netdb.h>
+#ifdef __CYGWIN32__
+#include <getopt.h>
+#endif
 
 #include "postgres.h"
 #include "miscadmin.h"
diff -urN pgsql/src/backend/utils/init/postinit.c /usr/src/pgsql/src/backend/utils/init/postinit.c
--- pgsql/src/backend/utils/init/postinit.c	Tue Sep 01 06:33:17 1998
+++ /usr/src/pgsql/src/backend/utils/init/postinit.c	Thu Nov 19 21:44:52 1998
@@ -176,7 +176,11 @@
 
 	errormsg[0] = '\0';
 
+#ifndef __CYGWIN32__
 	if ((fd = open(DataDir, O_RDONLY, 0)) == -1)
+#else
+	if ((fd = open(DataDir, O_RDONLY | O_DIROPEN, 0)) == -1)
+#endif
 		sprintf(errormsg, "Database system does not exist.  "
 				"PGDATA directory '%s' not found.\n\tNormally, you "
 				"create a database system by running initdb.",
@@ -212,7 +216,11 @@
 	name = DatabaseName;
 	myPath = DatabasePath;
 
+#ifndef __CYGWIN32__
 	if ((fd = open(myPath, O_RDONLY, 0)) == -1)
+#else
+	if ((fd = open(myPath, O_RDONLY | O_DIROPEN, 0)) == -1)
+#endif
 		sprintf(errormsg,
 				"Database '%s' does not exist."
 			"\n\tWe know this because the directory '%s' does not exist."
diff -urN pgsql/src/bin/pg_dump/Makefile.in /usr/src/pgsql/src/bin/pg_dump/Makefile.in
--- pgsql/src/bin/pg_dump/Makefile.in	Sun Aug 30 07:06:53 1998
+++ /usr/src/pgsql/src/bin/pg_dump/Makefile.in	Thu Nov 19 21:45:03 1998
@@ -39,7 +39,7 @@
 	$(MAKE) -C $(LIBPQDIR) libpq.a
 
 install: pg_dump
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_dump $(BINDIR)/pg_dump
+	$(INSTALL) $(INSTL_EXE_OPTS) pg_dump$(X) $(BINDIR)/pg_dump$(X)
 	$(INSTALL) $(INSTL_EXE_OPTS) pg_dumpall $(BINDIR)/pg_dumpall
 	$(INSTALL) $(INSTL_EXE_OPTS) pg_upgrade $(BINDIR)/pg_upgrade
 
@@ -47,7 +47,7 @@
 	$(CC) -MM $(CFLAGS) *.c >depend
 
 clean: 
-	rm -f pg_dump $(OBJS) 
+	rm -f pg_dump$(X) $(OBJS) 
 
 ifeq (depend,$(wildcard depend))
 include depend
diff -urN pgsql/src/bin/pg_dump/pg_dump.c /usr/src/pgsql/src/bin/pg_dump/pg_dump.c
--- pgsql/src/bin/pg_dump/pg_dump.c	Mon Oct 26 02:05:07 1998
+++ /usr/src/pgsql/src/bin/pg_dump/pg_dump.c	Thu Nov 19 21:45:04 1998
@@ -76,6 +76,10 @@
 #include <termios.h>
 #endif
 
+#ifdef __CYGWIN32__
+#include <getopt.h>
+#endif
+
 #include "pg_dump.h"
 
 static void dumpSequence(FILE *fout, TableInfo tbinfo);
diff -urN pgsql/src/bin/pg_id/Makefile /usr/src/pgsql/src/bin/pg_id/Makefile
--- pgsql/src/bin/pg_id/Makefile	Mon Apr 06 18:51:04 1998
+++ /usr/src/pgsql/src/bin/pg_id/Makefile	Thu Nov 19 21:45:04 1998
@@ -33,13 +33,13 @@
 	$(MAKE) -C $(LIBPQDIR) libpq.a
 
 install: pg_id
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_id $(BINDIR)/pg_id
+	$(INSTALL) $(INSTL_EXE_OPTS) pg_id$(X) $(BINDIR)/pg_id$(X)
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
 
 clean: 
-	rm -f pg_id $(OBJS) 
+	rm -f pg_id$(X) $(OBJS) 
 
 ifeq (depend,$(wildcard depend))
 include depend
diff -urN pgsql/src/bin/pg_id/pg_id.c /usr/src/pgsql/src/bin/pg_id/pg_id.c
--- pgsql/src/bin/pg_id/pg_id.c	Mon Jun 15 21:30:03 1998
+++ /usr/src/pgsql/src/bin/pg_id/pg_id.c	Thu Nov 19 21:45:04 1998
@@ -18,7 +18,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
-
+#ifdef __CYGWIN32__
+#include <getopt.h>
+#endif
 
 int
 main(int argc, char **argv)
diff -urN pgsql/src/bin/pg_passwd/Makefile /usr/src/pgsql/src/bin/pg_passwd/Makefile
--- pgsql/src/bin/pg_passwd/Makefile	Mon Apr 06 18:51:20 1998
+++ /usr/src/pgsql/src/bin/pg_passwd/Makefile	Thu Nov 19 21:45:04 1998
@@ -15,7 +15,7 @@
 	$(CC) -o pg_passwd $(OBJS) $(LDFLAGS)
 
 install: pg_passwd
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_passwd $(BINDIR)/pg_passwd
+	$(INSTALL) $(INSTL_EXE_OPTS) pg_passwd$(X) $(BINDIR)/pg_passwd$(X)
 
 .PHONY: submake
 submake:
@@ -25,7 +25,7 @@
 	$(CC) -MM $(CFLAGS) *.c >depend
 
 clean:
-	rm -f pg_passwd $(OBJS)
+	rm -f pg_passwd$(X) $(OBJS)
 
 ifeq (depend,$(wildcard depend))
 include depend
diff -urN pgsql/src/bin/pg_version/Makefile.in /usr/src/pgsql/src/bin/pg_version/Makefile.in
--- pgsql/src/bin/pg_version/Makefile.in	Mon Apr 06 18:51:27 1998
+++ /usr/src/pgsql/src/bin/pg_version/Makefile.in	Thu Nov 19 21:45:05 1998
@@ -28,13 +28,13 @@
 	$(MAKE) -C ../../utils version.o
 
 install: pg_version
-	$(INSTALL) $(INSTL_EXE_OPTS) pg_version $(BINDIR)/pg_version
+	$(INSTALL) $(INSTL_EXE_OPTS) pg_version$(X) $(BINDIR)/pg_version$(X)
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
 
 clean: 
-	rm -f pg_version pg_version.o
+	rm -f pg_version$(X) pg_version.o
 
 ifeq (depend,$(wildcard depend))
 include depend
diff -urN pgsql/src/bin/psql/Makefile.in /usr/src/pgsql/src/bin/psql/Makefile.in
--- pgsql/src/bin/psql/Makefile.in	Sun Jul 26 06:31:20 1998
+++ /usr/src/pgsql/src/bin/psql/Makefile.in	Thu Nov 19 21:45:05 1998
@@ -43,13 +43,13 @@
 	$(MAKE) -C $(LIBPQDIR) libpq.a
 
 install: psql
-	$(INSTALL) $(INSTL_EXE_OPTS) psql $(BINDIR)/psql
+	$(INSTALL) $(INSTL_EXE_OPTS) psql$(X) $(BINDIR)/psql$(X)
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
 
 clean: 
-	rm -f psql $(OBJS) 
+	rm -f psql$(X) $(OBJS) 
 
 ifeq (depend,$(wildcard depend))
 include depend
diff -urN pgsql/src/bin/psql/psql.c /usr/src/pgsql/src/bin/psql/psql.c
--- pgsql/src/bin/psql/psql.c	Mon Oct 26 02:04:37 1998
+++ /usr/src/pgsql/src/bin/psql/psql.c	Thu Nov 19 21:45:05 1998
@@ -40,6 +40,9 @@
 #ifdef HAVE_TERMIOS_H
 #include <termios.h>
 #endif
+#ifdef __CYGWIN32__
+#include <getopt.h>
+#endif
 
 #ifdef HAVE_LIBREADLINE
 #ifdef HAVE_READLINE_H
diff -urN pgsql/src/configure /usr/src/pgsql/src/configure
--- pgsql/src/configure	Mon Nov 02 06:30:06 1998
+++ /usr/src/pgsql/src/configure	Thu Nov 19 21:45:06 1998
@@ -668,7 +668,6 @@
 
 
 
-
 echo "checking echo setting..."
 if echo '\c' | grep -s c >/dev/null 2>&1
 then
@@ -730,7 +729,6 @@
 CC=`grep '^CC:' template/$TEMPLATE | awk -F: '{print $2}'`
 LIBS=`grep '^LIBS:' template/$TEMPLATE | awk -F: '{print $2}'`
 
-
 # Check whether --with-includes or --without-includes was given.
 if test "${with_includes+set}" = set; then
   withval="$with_includes"
@@ -746,7 +744,7 @@
 
 
 if test "$INCLUDE_DIRS"; then
-	for dir in $INCLUDE_DIRS; do
+	for dir in $INCLUDE_DIRS $SRCH_INC; do
 		if test -d "$dir"; then
 			PGSQL_CPPFLAGS="$PGSQL_CPPFLAGS -I$dir"
 		else
@@ -784,7 +782,7 @@
 
 
 if test "$LIBRARY_DIRS"; then
-	for dir in $LIBRARY_DIRS; do
+	for dir in $LIBRARY_DIRS $SRCH_LIB; do
 		if test -d "$dir"; then
 			PGSQL_LDFLAGS="$PGSQL_LDFLAGS -L$dir"
 		else
@@ -1526,11 +1524,11 @@
 
 ECHO_N_OUT=`echo -n "" | wc -c`
 ECHO_C_OUT=`echo "\c" | wc -c`
-if test "$ECHO_N_OUT" -eq 0; then
+if test $ECHO_N_OUT -eq 0; then
 	DASH_N='-n'
 	BACKSLASH_C=
 else
-	if test "ECHO_C_OUT" -eq 0; then
+	if test $ECHO_C_OUT -eq 0; then
 		DASH_N=
 		BACKSLASH_C='\\\\c'
 	else
diff -urN pgsql/src/configure.in /usr/src/pgsql/src/configure.in
--- pgsql/src/configure.in	Mon Nov 02 06:30:10 1998
+++ /usr/src/pgsql/src/configure.in	Thu Nov 19 21:45:06 1998
@@ -143,7 +143,7 @@
     ])
 
 if test "$INCLUDE_DIRS"; then
-	for dir in $INCLUDE_DIRS; do
+	for dir in $INCLUDE_DIRS $SRCH_INC; do
 		if test -d "$dir"; then
 			PGSQL_CPPFLAGS="$PGSQL_CPPFLAGS -I$dir"
 		else
@@ -175,7 +175,7 @@
     ])
 
 if test "$LIBRARY_DIRS"; then
-	for dir in $LIBRARY_DIRS; do
+	for dir in $LIBRARY_DIRS $SRCH_LIB; do
 		if test -d "$dir"; then
 			PGSQL_LDFLAGS="$PGSQL_LDFLAGS -L$dir"
 		else
diff -urN pgsql/src/include/c.h /usr/src/pgsql/src/include/c.h
--- pgsql/src/include/c.h	Sun Oct 04 17:38:55 1998
+++ /usr/src/pgsql/src/include/c.h	Thu Nov 19 21:45:09 1998
@@ -49,6 +49,10 @@
 */
 #include <stdlib.h>
 
+#ifdef __CYGWIN32__
+#include <errno.h>
+#endif
+
 /* ----------------------------------------------------------------
  *				Section 1:	bool, true, false, TRUE, FALSE
  * ----------------------------------------------------------------
diff -urN pgsql/src/include/port/win.h /usr/src/pgsql/src/include/port/win.h
--- pgsql/src/include/port/win.h	Thu Jan 01 01:00:00 1970
+++ /usr/src/pgsql/src/include/port/win.h	Thu Nov 19 21:45:17 1998
@@ -0,0 +1,7 @@
+#define JMP_BUF
+#define HAS_TEST_AND_SET
+typedef unsigned char slock_t;
+
+#ifndef O_DIROPEN
+#define O_DIROPEN	0x100000	/* should be in sys/fcntl.h */
+#endif
diff -urN pgsql/src/interfaces/ecpg/lib/Makefile.in /usr/src/pgsql/src/interfaces/ecpg/lib/Makefile.in
--- pgsql/src/interfaces/ecpg/lib/Makefile.in	Mon Oct 19 01:00:40 1998
+++ /usr/src/pgsql/src/interfaces/ecpg/lib/Makefile.in	Thu Nov 19 21:54:51 1998
@@ -43,6 +43,9 @@
 .PHONY: clean
 clean:
 	rm -f lib$(NAME).a $(shlib) $(OBJS)
+ifeq ($(PORTNAME), win)
+	rm -f $(NAME).def
+endif
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
diff -urN pgsql/src/interfaces/ecpg/preproc/Makefile /usr/src/pgsql/src/interfaces/ecpg/preproc/Makefile
--- pgsql/src/interfaces/ecpg/preproc/Makefile	Fri Oct 16 05:40:38 1998
+++ /usr/src/pgsql/src/interfaces/ecpg/preproc/Makefile	Thu Nov 19 21:45:24 1998
@@ -15,10 +15,10 @@
 all:: ecpg
 
 clean:
-	rm -f *.o core a.out ecpg y.tab.h y.tab.c pgc.c *~
+	rm -f *.o core a.out ecpg$(X) y.tab.h y.tab.c pgc.c *~
 
 install: all
-	$(INSTALL) $(INSTL_EXE_OPTS) ecpg $(DESTDIR)$(BINDIR)
+	$(INSTALL) $(INSTL_EXE_OPTS) ecpg$(X) $(DESTDIR)$(BINDIR)
 
 uninstall:
 	rm -f $(DESTDIR)$(BINDIR)/ecpg
diff -urN pgsql/src/interfaces/libpq/Makefile.in /usr/src/pgsql/src/interfaces/libpq/Makefile.in
--- pgsql/src/interfaces/libpq/Makefile.in	Mon Oct 19 01:00:43 1998
+++ /usr/src/pgsql/src/interfaces/libpq/Makefile.in	Thu Nov 19 21:55:52 1998
@@ -135,6 +135,9 @@
 clean:
 	rm -f libpq.a $(shlib) $(OBJS)
 	rm -f dllist.c common.c wchar.c conv.c
+ifeq ($(PORTNAME), win)
+	rm -f pq.def
+endif
 
 depend dep:
 	$(CC) -MM $(CFLAGS) *.c >depend
diff -urN pgsql/src/interfaces/libpq/fe-connect.c /usr/src/pgsql/src/interfaces/libpq/fe-connect.c
--- pgsql/src/interfaces/libpq/fe-connect.c	Wed Oct 14 06:31:48 1998
+++ /usr/src/pgsql/src/interfaces/libpq/fe-connect.c	Thu Nov 19 21:45:29 1998
@@ -567,7 +567,7 @@
 		conn->raddr.in.sin_port = htons((unsigned short) (portno));
 		conn->raddr_len = sizeof(struct sockaddr_in);
 	}
-#ifndef WIN32
+#if !defined(WIN32) && !defined(__CYGWIN32__)
 	else
 		conn->raddr_len = UNIXSOCK_PATH(conn->raddr.un, portno);
 #endif
diff -urN pgsql/src/interfaces/libpq++/Makefile.in /usr/src/pgsql/src/interfaces/libpq++/Makefile.in
--- pgsql/src/interfaces/libpq++/Makefile.in	Mon Oct 19 01:00:46 1998
+++ /usr/src/pgsql/src/interfaces/libpq++/Makefile.in	Thu Nov 19 21:56:35 1998
@@ -87,6 +87,9 @@
 clean:
 	rm -f libpq++.a $(shlib) $(OBJS)
 	$(MAKE) -C examples clean
+ifeq ($(PORTNAME), win)
+	rm -f pq++.def
+endif
 
 dep depend:
 	$(CXX) -MM $(CXXFLAGS) *.cc >depend
diff -urN pgsql/src/interfaces/odbc/GNUmakefile.in /usr/src/pgsql/src/interfaces/odbc/GNUmakefile.in
--- pgsql/src/interfaces/odbc/GNUmakefile.in	Wed Oct 28 07:49:10 1998
+++ /usr/src/pgsql/src/interfaces/odbc/GNUmakefile.in	Thu Nov 19 21:45:35 1998
@@ -73,7 +73,7 @@
 distclean: clean
 	-rm -f config.h GNUmakefile Makefile.global
 	-rm -f config.cache config.log config.status
-	@if [ $SRCDIR ne $ODBCSRCDIR ]; then rm -f template makefiles port
+	@if [ $SRCDIR != $ODBCSRCDIR ]; then rm -f template makefiles port; fi
 
 .PHONY: standalone
 
diff -urN pgsql/src/lextest/Makefile /usr/src/pgsql/src/lextest/Makefile
--- pgsql/src/lextest/Makefile	Mon Apr 06 02:31:39 1998
+++ /usr/src/pgsql/src/lextest/Makefile	Thu Nov 19 21:45:41 1998
@@ -19,6 +19,6 @@
 	@echo "If this fails, flex is broken" | ./lextest || rm -f lextest
 
 clean:
-	rm -f lextest lex.yy.c lex.yy.o lextest.o
+	rm -f lextest$(X) lex.yy.c lex.yy.o lextest.o
 
 dep:
diff -urN pgsql/src/makefiles/Makefile.win /usr/src/pgsql/src/makefiles/Makefile.win
--- pgsql/src/makefiles/Makefile.win	Thu Jan 01 01:00:00 1970
+++ /usr/src/pgsql/src/makefiles/Makefile.win	Thu Nov 19 21:45:41 1998
@@ -0,0 +1,14 @@
+CFLAGS+= -I/usr/local/include
+LDFLAGS+= -g
+DLLTOOL= dlltool
+DLLWRAP= dllwrap
+DLLLIBS=-L/usr/local/lib -L$(LIBDIR) -lpostgres -lcygipc -lcygwin -lcrypt -lkernel32
+X=.exe
+MK_NO_LORDER=true
+MAKE_DLL=true
+#MAKE_DLL=false
+SHLIB_LINK=$(DLLLIBS)
+
+%.dll: %.o
+	$(DLLTOOL) --export-all --output-def $*.def $<
+	$(DLLWRAP) -o $@ --def $*.def $< $(SRCDIR)/utils/dllinit.o $(DLLLIBS)
diff -urN pgsql/src/pl/plpgsql/src/Makefile.in /usr/src/pgsql/src/pl/plpgsql/src/Makefile.in
--- pgsql/src/pl/plpgsql/src/Makefile.in	Fri Oct 30 16:05:23 1998
+++ /usr/src/pgsql/src/pl/plpgsql/src/Makefile.in	Thu Nov 19 21:57:32 1998
@@ -74,3 +74,6 @@
 clean:
 	rm -f lib$(NAME).a $(shlib)
 	rm -f *.o pl.tab.h pl_gram.c pl_scan.c
+ifeq ($(PORTNAME), win)
+	rm -f $(NAME).def
+endif
diff -urN pgsql/src/template/.similar /usr/src/pgsql/src/template/.similar
--- pgsql/src/template/.similar	Fri Oct 23 02:02:10 1998
+++ /usr/src/pgsql/src/template/.similar	Thu Nov 19 21:45:48 1998
@@ -13,6 +13,7 @@
 i386-pc-sunos5=solaris_i386_gcc
 i386-unknown-freebsd=freebsd
 i386-unknown-netbsd=netbsd
+i386-pc-cygwin32=cygwin32
 i486-pc-linux-gnu=linux_i386
 i586-pc-linux-gnu=linux_i386
 i586-pc-sco3.2v=sco
diff -urN pgsql/src/template/cygwin32 /usr/src/pgsql/src/template/cygwin32
--- pgsql/src/template/cygwin32	Thu Jan 01 01:00:00 1970
+++ /usr/src/pgsql/src/template/cygwin32	Thu Nov 19 21:45:48 1998
@@ -0,0 +1,11 @@
+AROPT:crs
+CFLAGS:-O2 -g
+SHARED_LIB:
+ALL:
+SRCH_INC:/usr/local/include
+SRCH_LIB:/usr/local/lib
+USE_LOCALE:no
+DLSUFFIX:.dll
+YFLAGS:-d -L /sw/cygwin/share/
+YACC:
+LIBS:-lcygipc
diff -urN pgsql/src/test/regress/GNUmakefile /usr/src/pgsql/src/test/regress/GNUmakefile
--- pgsql/src/test/regress/GNUmakefile	Sun Jul 26 06:31:41 1998
+++ /usr/src/pgsql/src/test/regress/GNUmakefile	Thu Nov 19 21:45:59 1998
@@ -43,19 +43,37 @@
 all: $(INFILES)
 	cd input; $(MAKE) all; cd ..
 	cd output; $(MAKE) all; cd ..
+#ifneq ($(PORTNAME), win)
 	$(MAKE) -C ../../../contrib/spi REFINT_VERBOSE=1 refint$(DLSUFFIX) \
 	autoinc$(DLSUFFIX)
+#else
+#	cat /dev/null > ../../../contrib/spi/refint$(DLSUFFIX)
+#	cat /dev/null > ../../../contrib/spi/autoinc$(DLSUFFIX)
+#endif
+
+#ifeq ($(PORTNAME), win)
+#regress.dll: regress.c
+#	cat /dev/null > $@
+#endif
 
 #
 # run the test
 #
 runtest: $(INFILES) 
+ifneq ($(PORTNAME), win)
 	MULTIBYTE=$(MULTIBYTE);export MULTIBYTE; \
 	$(SHELL) ./regress.sh 2>&1 | tee regress.out
+else
+	MULTIBYTE=$(MULTIBYTE);export MULTIBYTE; \
+	./regress.sh 2>&1 | tee regress.out
+endif
 	@echo "ACTUAL RESULTS OF REGRESSION TEST ARE NOW IN FILE regress.out"
 
 clean:
-	rm -f $(INFILES) regress.out
+	rm -f $(INFILES) regress.out regress.o regression.diffs
+ifeq ($(PORTNAME), win)
+	rm -f regress.def
+endif
 	$(MAKE) -C sql clean
 	$(MAKE) -C expected clean
 	$(MAKE) -C results clean
diff -urN pgsql/src/test/regress/regress.sh /usr/src/pgsql/src/test/regress/regress.sh
--- pgsql/src/test/regress/regress.sh	Fri Aug 28 16:17:57 1998
+++ /usr/src/pgsql/src/test/regress/regress.sh	Thu Nov 19 21:46:00 1998
@@ -18,7 +18,7 @@
 PGDATESTYLE="Postgres,US"; export PGDATESTYLE
 
 #FRONTEND=monitor
-FRONTEND="psql -n -e -q"
+FRONTEND="psql -h localhost -n -e -q"
 
 SYSTEM=`uname -s`
 
@@ -31,10 +31,10 @@
 echo ""
 
 echo "=============== destroying old regression database... ================="
-destroydb regression
+destroydb -h localhost regression
 
 echo "=============== creating new regression database...   ================="
-createdb regression
+createdb -h localhost regression
 if [ $? -ne 0 ]; then
      echo createdb failed
      exit 1
diff -urN pgsql/src/utils/Makefile /usr/src/pgsql/src/utils/Makefile
--- pgsql/src/utils/Makefile	Mon Apr 06 02:32:26 1998
+++ /usr/src/pgsql/src/utils/Makefile	Thu Nov 19 22:01:18 1998
@@ -27,6 +27,9 @@
 
 clean: 
 	rm -f version.o
+ifeq ($(PORTNAME), win)
+	rm -f dllinit.o
+endif
 
 ifeq (depend,$(wildcard depend))
 include depend
diff -urN pgsql/src/utils/dllinit.c /usr/src/pgsql/src/utils/dllinit.c
--- pgsql/src/utils/dllinit.c	Thu Jan 01 01:00:00 1970
+++ /usr/src/pgsql/src/utils/dllinit.c	Thu Nov 19 21:46:12 1998
@@ -0,0 +1,105 @@
+/* dllinit.c -- Portable DLL initialization. 
+   Copyright (C) 1998 Free Software Foundation, Inc.
+   Contributed by Mumit Khan (khan@xraylith.wisc.edu).
+
+   I've used DllMain as the DLL "main" since that's the most common 
+   usage. MSVC and Mingw32 both default to DllMain as the standard
+   callback from the linker entry point. Cygwin32 b19+ uses essentially 
+   the same, albeit slightly differently implemented, scheme. Please
+   see DECLARE_CYGWIN_DLL macro in <cygwin32/cygwin_dll.h> for more 
+   info on how Cygwin32 uses the callback function.
+
+   The real entry point is typically always defined by the runtime 
+   library, and usually never overridden by (casual) user. What you can 
+   override however is the callback routine that the entry point calls, 
+   and this file provides such a callback function, DllMain.
+
+   Mingw32: The default entry point for mingw32 is DllMainCRTStartup
+   which is defined in libmingw32.a This in turn calls DllMain which is
+   defined here. If not defined, there is a stub in libmingw32.a which
+   does nothing.
+
+   Cygwin32: The default entry point for cygwin32 b19 or newer is
+   __cygwin32_dll_entry which is defined in libcygwin.a. This in turn
+   calls the routine you supply to the DECLARE_CYGWIN_DLL (see below)
+   and, for this example, I've chose DllMain to be consistent with all
+   the other platforms.
+
+   MSVC: MSVC runtime calls DllMain, just like Mingw32.
+
+   Summary: If you need to do anything special in DllMain, just add it
+   here. Otherwise, the default setup should be just fine for 99%+ of
+   the time. I strongly suggest that you *not* change the entry point,
+   but rather change DllMain as appropriate.
+
+ */
+
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#undef WIN32_LEAN_AND_MEAN
+#include <stdio.h>
+
+BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, 
+                       LPVOID reserved /* Not used. */ );
+
+#ifdef __CYGWIN32__
+
+#include <cygwin32/cygwin_dll.h>
+DECLARE_CYGWIN_DLL( DllMain );
+/* save hInstance from DllMain */
+HINSTANCE __hDllInstance_base;
+
+#endif /* __CYGWIN32__ */
+
+struct _reent *_impure_ptr;
+
+extern struct _reent *__imp_reent_data;
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * DllMain --
+ *
+ *	This routine is called by the Mingw32, Cygwin32 or VC++ C run 
+ *	time library init code, or the Borland DllEntryPoint routine. It 
+ *	is responsible for initializing various dynamically loaded 
+ *	libraries.
+ *
+ * Results:
+ *      TRUE on sucess, FALSE on failure.
+ *
+ * Side effects:
+ *
+ *----------------------------------------------------------------------
+ */
+BOOL APIENTRY
+DllMain (
+	 HINSTANCE hInst /* Library instance handle. */ ,
+	 DWORD reason /* Reason this function is being called. */ ,
+	 LPVOID reserved /* Not used. */ )
+{
+
+#ifdef __CYGWIN32__
+  __hDllInstance_base = hInst;
+#endif /* __CYGWIN32__ */
+
+  _impure_ptr = __imp_reent_data;
+  
+  switch (reason)
+    {
+    case DLL_PROCESS_ATTACH:
+      break;
+
+    case DLL_PROCESS_DETACH:
+      break;
+
+    case DLL_THREAD_ATTACH:
+      break;
+
+    case DLL_THREAD_DETACH:
+      break;
+    }
+  return TRUE;
+}
+
