Index: configure =================================================================== RCS file: /projects/cvsroot/pgsql-server/configure,v retrieving revision 1.321 diff -c -r1.321 configure *** configure 19 Jan 2004 21:20:04 -0000 1.321 --- configure 28 Jan 2004 10:09:43 -0000 *************** *** 2502,2508 **** # We already have this in Makefile.win32, but configure needs it too if test "$PORTNAME" = "win32"; then ! CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32" fi # Check if the compiler still works with the template settings --- 2502,2508 ---- # We already have this in Makefile.win32, but configure needs it too if test "$PORTNAME" = "win32"; then ! CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND" fi # Check if the compiler still works with the template settings *************** *** 12079,12084 **** --- 12079,12085 ---- case $host_os in mingw*) LIBOBJS="$LIBOBJS dirmod.$ac_objext" LIBOBJS="$LIBOBJS copydir.$ac_objext" + LIBOBJS="$LIBOBJS rand.$ac_objext" LIBOBJS="$LIBOBJS gettimeofday.$ac_objext" LIBOBJS="$LIBOBJS pipe.$ac_objext" ;; esac Index: src/Makefile.global.in =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/Makefile.global.in,v retrieving revision 1.173 diff -c -r1.173 Makefile.global.in *** src/Makefile.global.in 19 Jan 2004 21:20:06 -0000 1.173 --- src/Makefile.global.in 28 Jan 2004 10:09:44 -0000 *************** *** 346,351 **** --- 346,356 ---- LDFLAGS := -L$(top_builddir)/src/port $(LDFLAGS) endif + # to make ws2_32.lib the last library + ifeq ($(PORTNAME),win32) + LIBS += -lws2_32 + endif + # Not really standard libc functions, used by the backend. TAS = @TAS@ Index: src/backend/Makefile =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/Makefile,v retrieving revision 1.97 diff -c -r1.97 Makefile *** src/backend/Makefile 29 Nov 2003 19:51:39 -0000 1.97 --- src/backend/Makefile 28 Jan 2004 10:09:44 -0000 *************** *** 32,43 **** all: submake-libpgport postgres $(POSTGRES_IMP) ifneq ($(PORTNAME), cygwin) postgres: $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@ ! else # cygwin postgres: $(OBJS) $(DLLINIT) postgres.def libpostgres.a $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(LIBS) --- 32,46 ---- all: submake-libpgport postgres $(POSTGRES_IMP) ifneq ($(PORTNAME), cygwin) + ifneq ($(PORTNAME), win32) postgres: $(OBJS) $(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@ ! endif ! endif + ifeq ($(PORTNAME), cygwin) postgres: $(OBJS) $(DLLINIT) postgres.def libpostgres.a $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(LIBS) *************** *** 53,58 **** --- 56,79 ---- endif # cygwin + ifeq ($(PORTNAME), win32) + + postgres: $(OBJS) $(DLLINIT) postgres.def libpostgres.a + $(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def + $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(LIBS) + $(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def + $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) $@.exp $(OBJS) $(LIBS) + rm -f $@.exp $@.base + + postgres.def: $(OBJS) + $(DLLTOOL) --export-all --output-def $@ $^ + + libpostgres.a: postgres.def + $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@ + + endif # win32 + + ifeq ($(PORTNAME), aix) postgres: $(POSTGRES_IMP) *************** *** 131,136 **** --- 152,162 ---- $(INSTALL_DATA) libpostgres.a $(DESTDIR)$(libdir)/libpostgres.a endif endif + ifeq ($(PORTNAME), win32) + ifeq ($(MAKE_DLL), true) + $(INSTALL_DATA) libpostgres.a $(DESTDIR)$(libdir)/libpostgres.a + endif + endif $(MAKE) -C catalog install-data $(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample $(DESTDIR)$(datadir)/pg_hba.conf.sample $(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample $(DESTDIR)$(datadir)/pg_ident.conf.sample *************** *** 157,162 **** --- 183,193 ---- $(mkinstalldirs) $(DESTDIR)$(libdir) endif endif + ifeq ($(PORTNAME), win32) + ifeq ($(MAKE_DLL), true) + $(mkinstalldirs) $(DESTDIR)$(libdir) + endif + endif ifeq ($(MAKE_EXPORTS), true) $(mkinstalldirs) $(DESTDIR)$(pkglibdir) endif *************** *** 174,179 **** --- 205,215 ---- rm -f $(DESTDIR)$(libdir)/libpostgres.a endif endif + ifeq ($(PORTNAME), win32) + ifeq ($(MAKE_DLL), true) + rm -f $(DESTDIR)$(libdir)/libpostgres.a + endif + endif $(MAKE) -C catalog uninstall-data rm -f $(DESTDIR)$(datadir)/pg_hba.conf.sample \ $(DESTDIR)$(datadir)/pg_service.conf.sample \ *************** *** 188,193 **** --- 224,232 ---- $(top_srcdir)/src/include/parser/parse.h \ $(top_builddir)/src/include/utils/fmgroids.h ifeq ($(PORTNAME), cygwin) + rm -f postgres.dll postgres.def libpostgres.a + endif + ifeq ($(PORTNAME), win32) rm -f postgres.dll postgres.def libpostgres.a endif for i in $(DIRS); do $(MAKE) -C $$i clean || exit; done Index: src/backend/main/main.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/main/main.c,v retrieving revision 1.72 diff -c -r1.72 main.c *** src/backend/main/main.c 27 Jan 2004 00:45:26 -0000 1.72 --- src/backend/main/main.c 28 Jan 2004 10:09:45 -0000 *************** *** 227,233 **** */ len = strlen(new_argv[0]); ! if (len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 0) { /* Called as "postmaster" */ exit(PostmasterMain(argc, new_argv)); --- 227,237 ---- */ len = strlen(new_argv[0]); ! if ((len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 0) ! #ifdef WIN32 ! || (len >= 14 && strcmp(new_argv[0] + len - 14, "postmaster.exe") == 0) ! #endif ! ) { /* Called as "postmaster" */ exit(PostmasterMain(argc, new_argv)); Index: src/backend/port/sysv_shmem.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/port/sysv_shmem.c,v retrieving revision 1.29 diff -c -r1.29 sysv_shmem.c *** src/backend/port/sysv_shmem.c 27 Jan 2004 00:45:26 -0000 1.29 --- src/backend/port/sysv_shmem.c 28 Jan 2004 10:09:46 -0000 *************** *** 140,147 **** --- 140,152 ---- /* use intimate shared memory on Solaris */ memAddress = shmat(shmid, 0, SHM_SHARE_MMU); #else + + #ifdef EXEC_BACKEND + memAddress = shmat(shmid, UsedShmemSegAddr, 0); + #else memAddress = shmat(shmid, 0, 0); #endif + #endif if (memAddress == (void *) -1) elog(FATAL, "shmat(id=%d) failed: %m", shmid); *************** *** 244,261 **** PGShmemHeader *hdr; IpcMemoryId shmid; ! /* Room for a header? */ ! Assert(size > MAXALIGN(sizeof(PGShmemHeader))); ! /* If Exec case, just attach and return the pointer */ ! if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate) { hdr = PGSharedMemoryAttach((IpcMemoryKey) UsedShmemSegID, &shmid); if (hdr == NULL) ! elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%lu, addr=%p) failed: %m", ! UsedShmemSegID, UsedShmemSegAddr); return hdr; } /* Make sure PGSharedMemoryAttach doesn't fail without need */ UsedShmemSegAddr = NULL; --- 249,280 ---- PGShmemHeader *hdr; IpcMemoryId shmid; ! #ifdef EXEC_BACKEND /* If Exec case, just attach and return the pointer */ ! if (UsedShmemSegAddr != NULL && !makePrivate) { + void* origUsedShmemSegAddr = UsedShmemSegAddr; + + #ifdef CYGWIN + /* cygipc (currently) appears to not detach on exec. */ + PGSharedMemoryDetach(); + UsedShmemSegAddr = origUsedShmemSegAddr; + #endif + elog(DEBUG3,"Attaching to %x",UsedShmemSegAddr); hdr = PGSharedMemoryAttach((IpcMemoryKey) UsedShmemSegID, &shmid); if (hdr == NULL) ! elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %m", ! (int) UsedShmemSegID, UsedShmemSegAddr); ! if (hdr != origUsedShmemSegAddr) ! elog(FATAL,"attaching to shared mem returned unexpected address (got %p, expected %p)", ! hdr,UsedShmemSegAddr); ! UsedShmemSegAddr = hdr; return hdr; } + #endif + + /* Room for a header? */ + Assert(size > MAXALIGN(sizeof(PGShmemHeader))); /* Make sure PGSharedMemoryAttach doesn't fail without need */ UsedShmemSegAddr = NULL; *************** *** 354,364 **** { if (UsedShmemSegAddr != NULL) { ! if (shmdt(UsedShmemSegAddr) < 0) elog(LOG, "shmdt(%p) failed: %m", UsedShmemSegAddr); UsedShmemSegAddr = NULL; } } /* * Attach to shared memory and make sure it has a Postgres header --- 373,389 ---- { if (UsedShmemSegAddr != NULL) { ! if ((shmdt(UsedShmemSegAddr) < 0) ! #if (defined(EXEC_BACKEND) && defined(CYGWIN)) ! /* Work-around for cygipc exec bug */ ! && shmdt(NULL) < 0 ! #endif ! ) elog(LOG, "shmdt(%p) failed: %m", UsedShmemSegAddr); UsedShmemSegAddr = NULL; } } + /* * Attach to shared memory and make sure it has a Postgres header Index: src/backend/port/win32/shmem.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/port/win32/shmem.c,v retrieving revision 1.2 diff -c -r1.2 shmem.c *** src/backend/port/win32/shmem.c 4 Aug 2003 02:40:02 -0000 1.2 --- src/backend/port/win32/shmem.c 28 Jan 2004 10:09:46 -0000 *************** *** 32,38 **** /* TODO -- shmat needs to count # attached to shared mem */ void *lpmem = MapViewOfFileEx((HANDLE) memId, FILE_MAP_WRITE | FILE_MAP_READ, ! 0, 0, /* (DWORD)pshmdsc->segsize */ s_segsize, shmaddr); if (lpmem == NULL) { --- 32,38 ---- /* TODO -- shmat needs to count # attached to shared mem */ void *lpmem = MapViewOfFileEx((HANDLE) memId, FILE_MAP_WRITE | FILE_MAP_READ, ! 0, 0, /* (DWORD)pshmdsc->segsize */ 0 /* s_segsize */, shmaddr); if (lpmem == NULL) { Index: src/backend/utils/init/findbe.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/init/findbe.c,v retrieving revision 1.40 diff -c -r1.40 findbe.c *** src/backend/utils/init/findbe.c 29 Nov 2003 19:52:01 -0000 1.40 --- src/backend/utils/init/findbe.c 28 Jan 2004 10:09:46 -0000 *************** *** 205,213 **** { elog(DEBUG2, "searching PATH for executable"); path = strdup(p); /* make a modifiable copy */ ! for (startp = path, endp = strchr(path, ':'); startp && *startp; ! startp = endp + 1, endp = strchr(startp, ':')) { if (startp == endp) /* it's a "::" */ continue; --- 205,213 ---- { elog(DEBUG2, "searching PATH for executable"); path = strdup(p); /* make a modifiable copy */ ! for (startp = path, endp = strchr(path, PATHSEP); startp && *startp; ! startp = endp + 1, endp = strchr(startp, PATHSEP)) { if (startp == endp) /* it's a "::" */ continue; Index: src/bin/initdb/initdb.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/bin/initdb/initdb.c,v retrieving revision 1.19 diff -c -r1.19 initdb.c *** src/bin/initdb/initdb.c 26 Jan 2004 22:35:32 -0000 1.19 --- src/bin/initdb/initdb.c 28 Jan 2004 10:09:49 -0000 *************** *** 144,154 **** #define DEVNULL "/dev/null" #endif - #ifdef WIN32 - #define PATHSEP ';' - #else - #define PATHSEP ':' - #endif /* detected path to postgres and (we assume) friends */ char *pgpath; --- 144,149 ---- Index: src/include/port.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/port.h,v retrieving revision 1.15 diff -c -r1.15 port.h *** src/include/port.h 29 Nov 2003 22:40:53 -0000 1.15 --- src/include/port.h 28 Jan 2004 10:09:49 -0000 *************** *** 44,49 **** --- 44,53 ---- extern int copydir(char *fromdir, char *todir); + /* Missing rand functions */ + extern long lrand48(void); + extern void srand48(long seed); + /* Last parameter not used */ extern int gettimeofday(struct timeval * tp, struct timezone * tzp); *************** *** 122,124 **** --- 126,145 ---- char *buffer, size_t buflen, struct hostent **result, int *herrno); + + /* $PATH (or %PATH%) path separator */ + #ifdef WIN32 + #define PATHSEP ';' + #else + #define PATHSEP ':' + #endif + + /* FIXME: [win32] Placeholder win32 replacements, to allow continued development */ + #ifdef WIN32 + #define fsync(a) _commit(a) + #define sync() _flushall() + #define WEXITSTATUS(w) (((w) >> 8) & 0xff) + #define WIFEXITED(w) (((w) & 0xff) == 0) + #define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f)) + #define WTERMSIG(w) ((w) & 0x7f) + #endif Index: src/interfaces/libpq/Makefile =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/Makefile,v retrieving revision 1.96 diff -c -r1.96 Makefile *** src/interfaces/libpq/Makefile 30 Nov 2003 06:09:50 -0000 1.96 --- src/interfaces/libpq/Makefile 28 Jan 2004 10:09:50 -0000 *************** *** 32,38 **** # Add libraries that libpq depends (or might depend) on into the # shared library link. (The order in which you list them here doesn't # matter.) ! SHLIB_LINK += $(filter -lcrypt -ldes -lkrb -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(THREAD_LIBS) all: all-lib --- 32,38 ---- # Add libraries that libpq depends (or might depend) on into the # shared library link. (The order in which you list them here doesn't # matter.) ! SHLIB_LINK += $(filter -lcrypt -ldes -lkrb -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(THREAD_LIBS) -lwsock32 -lws2_32 all: all-lib Index: src/interfaces/libpq/pqsignal.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/pqsignal.c,v retrieving revision 1.19 diff -c -r1.19 pqsignal.c *** src/interfaces/libpq/pqsignal.c 9 Jan 2004 02:02:43 -0000 1.19 --- src/interfaces/libpq/pqsignal.c 28 Jan 2004 10:09:50 -0000 *************** *** 44,49 **** --- 44,50 ---- pqsigfunc pqsignalinquire(int signo) { + #ifndef WIN32 #if !defined(HAVE_POSIX_SIGNALS) pqsigfunc old_sigfunc; int old_sigmask; *************** *** 61,64 **** --- 62,68 ---- return SIG_ERR; return oact.sa_handler; #endif /* !HAVE_POSIX_SIGNALS */ + #else + return SIG_DFL; + #endif } Index: src/interfaces/libpq/win32.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/interfaces/libpq/win32.c,v retrieving revision 1.7 diff -c -r1.7 win32.c *** src/interfaces/libpq/win32.c 5 Sep 2003 02:08:36 -0000 1.7 --- src/interfaces/libpq/win32.c 28 Jan 2004 10:09:50 -0000 *************** *** 22,28 **** --- 22,30 ---- #define WIN32_LEAN_AND_MEAN #define WIN32_EXTRA_LEAN #define VC_EXTRALEAN + #ifndef __MINGW32__ #define NOGDI + #endif #define NOCRYPT #include