# 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"
+ CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND"
fi
# Check if the compiler still works with the template settings
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
# -*-makefile-*-
-# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.173 2004/01/19 21:20:06 tgl Exp $
+# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.174 2004/02/02 00:11:30 momjian Exp $
#------------------------------------------------------------------------------
# All PostgreSQL makefiles include this file and use the variables it sets,
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@
#
# Copyright (c) 1994, Regents of the University of California
#
-# $PostgreSQL: pgsql/src/backend/Makefile,v 1.97 2003/11/29 19:51:39 pgsql Exp $
+# $PostgreSQL: pgsql/src/backend/Makefile,v 1.98 2004/02/02 00:11:30 momjian Exp $
#
#-------------------------------------------------------------------------
all: submake-libpgport postgres $(POSTGRES_IMP)
ifneq ($(PORTNAME), cygwin)
+ifneq ($(PORTNAME), win32)
postgres: $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@
-else # cygwin
+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)
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)
ifeq ($(MAKE_DLL), true)
$(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
$(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
ifeq ($(MAKE_DLL), true)
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 \
$(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
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/main/main.c,v 1.72 2004/01/27 00:45:26 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/main/main.c,v 1.73 2004/02/02 00:11:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*/
len = strlen(new_argv[0]);
- if (len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 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));
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.29 2004/01/27 00:45:26 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.30 2004/02/02 00:11:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
/* 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)
PGShmemHeader *hdr;
IpcMemoryId shmid;
- /* Room for a header? */
- Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
-
+#ifdef EXEC_BACKEND
/* If Exec case, just attach and return the pointer */
- if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
+ 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=%lu, addr=%p) failed: %m",
- UsedShmemSegID, UsedShmemSegAddr);
+ 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;
{
if (UsedShmemSegAddr != NULL)
{
- if (shmdt(UsedShmemSegAddr) < 0)
+ 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
*
/* 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);
+ 0, 0, /* (DWORD)pshmdsc->segsize */ 0 /* s_segsize */, shmaddr);
if (lpmem == NULL)
{
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/init/findbe.c,v 1.40 2003/11/29 19:52:01 pgsql Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/init/findbe.c,v 1.41 2004/02/02 00:11:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
{
elog(DEBUG2, "searching PATH for executable");
path = strdup(p); /* make a modifiable copy */
- for (startp = path, endp = strchr(path, ':');
+ for (startp = path, endp = strchr(path, PATHSEP);
startp && *startp;
- startp = endp + 1, endp = strchr(startp, ':'))
+ startp = endp + 1, endp = strchr(startp, PATHSEP))
{
if (startp == endp) /* it's a "::" */
continue;
* Portions Copyright (c) 1994, Regents of the University of California
* Portions taken from FreeBSD.
*
- * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.21 2004/01/31 22:10:00 neilc Exp $
+ * $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.22 2004/02/02 00:11:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#define DEVNULL "/dev/null"
#endif
-#ifdef WIN32
-#define PATHSEP ';'
-#else
-#define PATHSEP ':'
-#endif
/* detected path to postgres and (we assume) friends */
char *pgpath;
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/include/port.h,v 1.15 2003/11/29 22:40:53 pgsql Exp $
+ * $PostgreSQL: pgsql/src/include/port.h,v 1.16 2004/02/02 00:11:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
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);
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
#
# Copyright (c) 1994, Regents of the University of California
#
-# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.96 2003/11/30 06:09:50 momjian Exp $
+# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.97 2004/02/02 00:11:31 momjian Exp $
#
#-------------------------------------------------------------------------
# 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)
+ifeq ($(PORTNAME), win32)
+SHLIB_LINK += -lwsock32 -lws2_32
+endif
all: all-lib
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/interfaces/libpq/pqsignal.c,v 1.19 2004/01/09 02:02:43 momjian Exp $
+ * $PostgreSQL: pgsql/src/interfaces/libpq/pqsignal.c,v 1.20 2004/02/02 00:11:31 momjian Exp $
*
* NOTES
* This shouldn't be in libpq, but the monitor and some other
pqsigfunc
pqsignalinquire(int signo)
{
+#ifndef WIN32
#if !defined(HAVE_POSIX_SIGNALS)
pqsigfunc old_sigfunc;
int old_sigmask;
return SIG_ERR;
return oact.sa_handler;
#endif /* !HAVE_POSIX_SIGNALS */
+#else
+ return SIG_DFL;
+#endif
}
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#define VC_EXTRALEAN
+#ifndef __MINGW32__
#define NOGDI
+#endif
#define NOCRYPT
#include <windows.h>
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * rand.c
+ * Missing rand implementations for Win32
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+#define RAND48_SEED_0 (0x330e)
+#define RAND48_SEED_1 (0xabcd)
+#define RAND48_SEED_2 (0x1234)
+#define RAND48_MULT_0 (0xe66d)
+#define RAND48_MULT_1 (0xdeec)
+#define RAND48_MULT_2 (0x0005)
+#define RAND48_ADD (0x000b)
+
+unsigned short _rand48_seed[3] = {
+ RAND48_SEED_0,
+ RAND48_SEED_1,
+ RAND48_SEED_2
+};
+unsigned short _rand48_mult[3] = {
+ RAND48_MULT_0,
+ RAND48_MULT_1,
+ RAND48_MULT_2
+};
+unsigned short _rand48_add = RAND48_ADD;
+
+void
+_dorand48(unsigned short xseed[3])
+{
+ unsigned long accu;
+ unsigned short temp[2];
+
+ accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
+ (unsigned long) _rand48_add;
+ temp[0] = (unsigned short) accu; /* lower 16 bits */
+ accu >>= sizeof(unsigned short) * 8;
+ accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
+ (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
+ temp[1] = (unsigned short) accu; /* middle 16 bits */
+ accu >>= sizeof(unsigned short) * 8;
+ accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
+ xseed[0] = temp[0];
+ xseed[1] = temp[1];
+ xseed[2] = (unsigned short) accu;
+}
+
+long
+lrand48(void)
+{
+ _dorand48(_rand48_seed);
+ return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >1);
+}
+
+void
+srand48(long seed)
+{
+ _rand48_seed[0] = RAND48_SEED_0;
+ _rand48_seed[1] = (unsigned short) seed;
+ _rand48_seed[2] = (unsigned short) (seed >16);
+ _rand48_mult[0] = RAND48_MULT_0;
+ _rand48_mult[1] = RAND48_MULT_1;
+ _rand48_mult[2] = RAND48_MULT_2;
+ _rand48_add = RAND48_ADD;
+}