Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e5e5a32

Browse files
committed
Briefly,
* configure + Makefile changes * shared memory attaching in EXEC_BACKEND case (+ minor fix for apparent cygwin bug under cygwin/EXEC_BACKEND case only) * PATH env var separator differences * missing win32 rand functions added * placeholder replacements for sync etc under port.h To those who are really interested, and there are a few of you: the attached patch + file will allow the source base to be compiled (and, for some definition, "run") under MingW, with the following caveats (I wanted to first properly fix all but the last of these, but y'all won't quit asking for a patch :-): * child death: SIGCHLD not yet sent, so as a minimum, you'll need to put in some sort of delay after StartupDatabase, and handle setting StartupPID to 0 etc (ie. the stuff the reaper() signal function is supposed to do) * dirmod.c: comment out the elog calls * dfmgr.c: some hackage required to substitute_libpath_macro * slru/xact.c: comment out the errno checking after the readdir (fixed by next version of MingW) Again, this is only if you *really* want to see postgres compile and start, and is a nice leg-up for working on the other Win32 TODO list items. Just don't expect too much else from it at this point... Claudio Natoli
1 parent 10bb17e commit e5e5a32

File tree

13 files changed

+204
-27
lines changed

13 files changed

+204
-27
lines changed

configure

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ echo "$as_me: using CFLAGS=$CFLAGS" >&6;}
25022502

25032503
# We already have this in Makefile.win32, but configure needs it too
25042504
if test "$PORTNAME" = "win32"; then
2505-
CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32"
2505+
CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND"
25062506
fi
25072507

25082508
# Check if the compiler still works with the template settings
@@ -12079,6 +12079,7 @@ esac
1207912079
case $host_os in mingw*)
1208012080
LIBOBJS="$LIBOBJS dirmod.$ac_objext"
1208112081
LIBOBJS="$LIBOBJS copydir.$ac_objext"
12082+
LIBOBJS="$LIBOBJS rand.$ac_objext"
1208212083
LIBOBJS="$LIBOBJS gettimeofday.$ac_objext"
1208312084
LIBOBJS="$LIBOBJS pipe.$ac_objext" ;;
1208412085
esac

src/Makefile.global.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*-makefile-*-
2-
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.173 2004/01/19 21:20:06 tgl Exp $
2+
# $PostgreSQL: pgsql/src/Makefile.global.in,v 1.174 2004/02/02 00:11:30 momjian Exp $
33

44
#------------------------------------------------------------------------------
55
# All PostgreSQL makefiles include this file and use the variables it sets,
@@ -346,6 +346,11 @@ LIBS += -lpgport
346346
LDFLAGS := -L$(top_builddir)/src/port $(LDFLAGS)
347347
endif
348348

349+
# to make ws2_32.lib the last library
350+
ifeq ($(PORTNAME),win32)
351+
LIBS += -lws2_32
352+
endif
353+
349354
# Not really standard libc functions, used by the backend.
350355
TAS = @TAS@
351356

src/backend/Makefile

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/backend/Makefile,v 1.97 2003/11/29 19:51:39 pgsql Exp $
7+
# $PostgreSQL: pgsql/src/backend/Makefile,v 1.98 2004/02/02 00:11:30 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -32,12 +32,15 @@ endif
3232
all: submake-libpgport postgres $(POSTGRES_IMP)
3333

3434
ifneq ($(PORTNAME), cygwin)
35+
ifneq ($(PORTNAME), win32)
3536

3637
postgres: $(OBJS)
3738
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@
3839

39-
else # cygwin
40+
endif
41+
endif
4042

43+
ifeq ($(PORTNAME), cygwin)
4144
postgres: $(OBJS) $(DLLINIT) postgres.def libpostgres.a
4245
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
4346
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(LIBS)
@@ -53,6 +56,24 @@ libpostgres.a: postgres.def
5356

5457
endif # cygwin
5558

59+
ifeq ($(PORTNAME), win32)
60+
61+
postgres: $(OBJS) $(DLLINIT) postgres.def libpostgres.a
62+
$(DLLTOOL) --dllname $@$(X) --output-exp $@.exp --def postgres.def
63+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,$@.base $@.exp $(OBJS) $(LIBS)
64+
$(DLLTOOL) --dllname $@$(X) --base-file $@.base --output-exp $@.exp --def postgres.def
65+
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) $@.exp $(OBJS) $(LIBS)
66+
rm -f $@.exp $@.base
67+
68+
postgres.def: $(OBJS)
69+
$(DLLTOOL) --export-all --output-def $@ $^
70+
71+
libpostgres.a: postgres.def
72+
$(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
73+
74+
endif # win32
75+
76+
5677
ifeq ($(PORTNAME), aix)
5778

5879
postgres: $(POSTGRES_IMP)
@@ -130,6 +151,11 @@ ifeq ($(PORTNAME), cygwin)
130151
ifeq ($(MAKE_DLL), true)
131152
$(INSTALL_DATA) libpostgres.a $(DESTDIR)$(libdir)/libpostgres.a
132153
endif
154+
endif
155+
ifeq ($(PORTNAME), win32)
156+
ifeq ($(MAKE_DLL), true)
157+
$(INSTALL_DATA) libpostgres.a $(DESTDIR)$(libdir)/libpostgres.a
158+
endif
133159
endif
134160
$(MAKE) -C catalog install-data
135161
$(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample $(DESTDIR)$(datadir)/pg_hba.conf.sample
@@ -157,6 +183,11 @@ ifeq ($(MAKE_DLL), true)
157183
$(mkinstalldirs) $(DESTDIR)$(libdir)
158184
endif
159185
endif
186+
ifeq ($(PORTNAME), win32)
187+
ifeq ($(MAKE_DLL), true)
188+
$(mkinstalldirs) $(DESTDIR)$(libdir)
189+
endif
190+
endif
160191
ifeq ($(MAKE_EXPORTS), true)
161192
$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
162193
endif
@@ -173,6 +204,11 @@ ifeq ($(PORTNAME), cygwin)
173204
ifeq ($(MAKE_DLL), true)
174205
rm -f $(DESTDIR)$(libdir)/libpostgres.a
175206
endif
207+
endif
208+
ifeq ($(PORTNAME), win32)
209+
ifeq ($(MAKE_DLL), true)
210+
rm -f $(DESTDIR)$(libdir)/libpostgres.a
211+
endif
176212
endif
177213
$(MAKE) -C catalog uninstall-data
178214
rm -f $(DESTDIR)$(datadir)/pg_hba.conf.sample \
@@ -189,6 +225,9 @@ clean:
189225
$(top_builddir)/src/include/utils/fmgroids.h
190226
ifeq ($(PORTNAME), cygwin)
191227
rm -f postgres.dll postgres.def libpostgres.a
228+
endif
229+
ifeq ($(PORTNAME), win32)
230+
rm -f postgres.dll postgres.def libpostgres.a
192231
endif
193232
for i in $(DIRS); do $(MAKE) -C $$i clean || exit; done
194233

src/backend/main/main.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.72 2004/01/27 00:45:26 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.73 2004/02/02 00:11:31 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -227,7 +227,11 @@ main(int argc, char *argv[])
227227
*/
228228
len = strlen(new_argv[0]);
229229

230-
if (len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 0)
230+
if ((len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 0)
231+
#ifdef WIN32
232+
|| (len >= 14 && strcmp(new_argv[0] + len - 14, "postmaster.exe") == 0)
233+
#endif
234+
)
231235
{
232236
/* Called as "postmaster" */
233237
exit(PostmasterMain(argc, new_argv));

src/backend/port/sysv_shmem.c

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Portions Copyright (c) 1994, Regents of the University of California
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.29 2004/01/27 00:45:26 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/port/sysv_shmem.c,v 1.30 2004/02/02 00:11:31 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -140,7 +140,12 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
140140
/* use intimate shared memory on Solaris */
141141
memAddress = shmat(shmid, 0, SHM_SHARE_MMU);
142142
#else
143+
144+
#ifdef EXEC_BACKEND
145+
memAddress = shmat(shmid, UsedShmemSegAddr, 0);
146+
#else
143147
memAddress = shmat(shmid, 0, 0);
148+
#endif
144149
#endif
145150

146151
if (memAddress == (void *) -1)
@@ -244,18 +249,32 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
244249
PGShmemHeader *hdr;
245250
IpcMemoryId shmid;
246251

247-
/* Room for a header? */
248-
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
249-
252+
#ifdef EXEC_BACKEND
250253
/* If Exec case, just attach and return the pointer */
251-
if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
254+
if (UsedShmemSegAddr != NULL && !makePrivate)
252255
{
256+
void* origUsedShmemSegAddr = UsedShmemSegAddr;
257+
258+
#ifdef CYGWIN
259+
/* cygipc (currently) appears to not detach on exec. */
260+
PGSharedMemoryDetach();
261+
UsedShmemSegAddr = origUsedShmemSegAddr;
262+
#endif
263+
elog(DEBUG3,"Attaching to %x",UsedShmemSegAddr);
253264
hdr = PGSharedMemoryAttach((IpcMemoryKey) UsedShmemSegID, &shmid);
254265
if (hdr == NULL)
255-
elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%lu, addr=%p) failed: %m",
256-
UsedShmemSegID, UsedShmemSegAddr);
266+
elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %m",
267+
(int) UsedShmemSegID, UsedShmemSegAddr);
268+
if (hdr != origUsedShmemSegAddr)
269+
elog(FATAL,"attaching to shared mem returned unexpected address (got %p, expected %p)",
270+
hdr,UsedShmemSegAddr);
271+
UsedShmemSegAddr = hdr;
257272
return hdr;
258273
}
274+
#endif
275+
276+
/* Room for a header? */
277+
Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
259278

260279
/* Make sure PGSharedMemoryAttach doesn't fail without need */
261280
UsedShmemSegAddr = NULL;
@@ -354,12 +373,18 @@ PGSharedMemoryDetach(void)
354373
{
355374
if (UsedShmemSegAddr != NULL)
356375
{
357-
if (shmdt(UsedShmemSegAddr) < 0)
376+
if ((shmdt(UsedShmemSegAddr) < 0)
377+
#if (defined(EXEC_BACKEND) && defined(CYGWIN))
378+
/* Work-around for cygipc exec bug */
379+
&& shmdt(NULL) < 0
380+
#endif
381+
)
358382
elog(LOG, "shmdt(%p) failed: %m", UsedShmemSegAddr);
359383
UsedShmemSegAddr = NULL;
360384
}
361385
}
362386

387+
363388
/*
364389
* Attach to shared memory and make sure it has a Postgres header
365390
*

src/backend/port/win32/shmem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ shmat(int memId, void *shmaddr, int flag)
3232
/* TODO -- shmat needs to count # attached to shared mem */
3333
void *lpmem = MapViewOfFileEx((HANDLE) memId,
3434
FILE_MAP_WRITE | FILE_MAP_READ,
35-
0, 0, /* (DWORD)pshmdsc->segsize */ s_segsize, shmaddr);
35+
0, 0, /* (DWORD)pshmdsc->segsize */ 0 /* s_segsize */, shmaddr);
3636

3737
if (lpmem == NULL)
3838
{

src/backend/utils/init/findbe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $PostgreSQL: pgsql/src/backend/utils/init/findbe.c,v 1.40 2003/11/29 19:52:01 pgsql Exp $
10+
* $PostgreSQL: pgsql/src/backend/utils/init/findbe.c,v 1.41 2004/02/02 00:11:31 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -205,9 +205,9 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
205205
{
206206
elog(DEBUG2, "searching PATH for executable");
207207
path = strdup(p); /* make a modifiable copy */
208-
for (startp = path, endp = strchr(path, ':');
208+
for (startp = path, endp = strchr(path, PATHSEP);
209209
startp && *startp;
210-
startp = endp + 1, endp = strchr(startp, ':'))
210+
startp = endp + 1, endp = strchr(startp, PATHSEP))
211211
{
212212
if (startp == endp) /* it's a "::" */
213213
continue;

src/bin/initdb/initdb.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
* Portions Copyright (c) 1994, Regents of the University of California
4444
* Portions taken from FreeBSD.
4545
*
46-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.21 2004/01/31 22:10:00 neilc Exp $
46+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.22 2004/02/02 00:11:31 momjian Exp $
4747
*
4848
*-------------------------------------------------------------------------
4949
*/
@@ -144,11 +144,6 @@ static const char *backend_options = "-F -O -c search_path=pg_catalog -c exit_on
144144
#define DEVNULL "/dev/null"
145145
#endif
146146

147-
#ifdef WIN32
148-
#define PATHSEP ';'
149-
#else
150-
#define PATHSEP ':'
151-
#endif
152147

153148
/* detected path to postgres and (we assume) friends */
154149
char *pgpath;

src/include/port.h

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $PostgreSQL: pgsql/src/include/port.h,v 1.15 2003/11/29 22:40:53 pgsql Exp $
9+
* $PostgreSQL: pgsql/src/include/port.h,v 1.16 2004/02/02 00:11:31 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -44,6 +44,10 @@ extern int pgunlink(const char *path);
4444

4545
extern int copydir(char *fromdir, char *todir);
4646

47+
/* Missing rand functions */
48+
extern long lrand48(void);
49+
extern void srand48(long seed);
50+
4751
/* Last parameter not used */
4852
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
4953

@@ -122,3 +126,20 @@ extern int pqGethostbyname(const char *name,
122126
char *buffer, size_t buflen,
123127
struct hostent **result,
124128
int *herrno);
129+
130+
/* $PATH (or %PATH%) path separator */
131+
#ifdef WIN32
132+
#define PATHSEP ';'
133+
#else
134+
#define PATHSEP ':'
135+
#endif
136+
137+
/* FIXME: [win32] Placeholder win32 replacements, to allow continued development */
138+
#ifdef WIN32
139+
#define fsync(a) _commit(a)
140+
#define sync() _flushall()
141+
#define WEXITSTATUS(w) (((w) >> 8) & 0xff)
142+
#define WIFEXITED(w) (((w) & 0xff) == 0)
143+
#define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
144+
#define WTERMSIG(w) ((w) & 0x7f)
145+
#endif

src/interfaces/libpq/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# Copyright (c) 1994, Regents of the University of California
66
#
7-
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.96 2003/11/30 06:09:50 momjian Exp $
7+
# $PostgreSQL: pgsql/src/interfaces/libpq/Makefile,v 1.97 2004/02/02 00:11:31 momjian Exp $
88
#
99
#-------------------------------------------------------------------------
1010

@@ -33,6 +33,9 @@ endif
3333
# shared library link. (The order in which you list them here doesn't
3434
# matter.)
3535
SHLIB_LINK += $(filter -lcrypt -ldes -lkrb -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(THREAD_LIBS)
36+
ifeq ($(PORTNAME), win32)
37+
SHLIB_LINK += -lwsock32 -lws2_32
38+
endif
3639

3740

3841
all: all-lib

src/interfaces/libpq/pqsignal.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/interfaces/libpq/pqsignal.c,v 1.19 2004/01/09 02:02:43 momjian Exp $
12+
* $PostgreSQL: pgsql/src/interfaces/libpq/pqsignal.c,v 1.20 2004/02/02 00:11:31 momjian Exp $
1313
*
1414
* NOTES
1515
* This shouldn't be in libpq, but the monitor and some other
@@ -44,6 +44,7 @@ pqsignal(int signo, pqsigfunc func)
4444
pqsigfunc
4545
pqsignalinquire(int signo)
4646
{
47+
#ifndef WIN32
4748
#if !defined(HAVE_POSIX_SIGNALS)
4849
pqsigfunc old_sigfunc;
4950
int old_sigmask;
@@ -61,4 +62,7 @@ pqsignalinquire(int signo)
6162
return SIG_ERR;
6263
return oact.sa_handler;
6364
#endif /* !HAVE_POSIX_SIGNALS */
65+
#else
66+
return SIG_DFL;
67+
#endif
6468
}

src/interfaces/libpq/win32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
#define WIN32_LEAN_AND_MEAN
2323
#define WIN32_EXTRA_LEAN
2424
#define VC_EXTRALEAN
25+
#ifndef __MINGW32__
2526
#define NOGDI
27+
#endif
2628
#define NOCRYPT
2729

2830
#include <windows.h>

0 commit comments

Comments
 (0)