Skip to content

Commit 1a0c76c

Browse files
committed
Enable compiling with the mingw-w64 32 bit compiler.
Original patch by Lars Kanis, reviewed by Nishiyama Tomoaki and tweaked some by me. This compiler, or at least the latest version of it, is currently broken, and only passes the regression tests if built with -O0.
1 parent ab7d421 commit 1a0c76c

File tree

10 files changed

+207
-9
lines changed

10 files changed

+207
-9
lines changed

config/ac_func_accept_argtypes.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ AC_DEFUN([AC_FUNC_ACCEPT_ARGTYPES],
4646
[AC_CACHE_VAL(ac_cv_func_accept_arg1,dnl
4747
[AC_CACHE_VAL(ac_cv_func_accept_arg2,dnl
4848
[AC_CACHE_VAL(ac_cv_func_accept_arg3,dnl
49-
[for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL' 'SOCKET'; do
49+
[for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL' 'SOCKET WSAAPI'; do
5050
for ac_cv_func_accept_arg1 in 'int' 'unsigned int' 'SOCKET'; do
5151
for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
5252
for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do

configure

Lines changed: 157 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14328,6 +14328,159 @@ done
1432814328

1432914329
fi
1433014330

14331+
if test "$PORTNAME" = "win32" ; then
14332+
14333+
for ac_header in crtdefs.h
14334+
do
14335+
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
14336+
if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
14337+
{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
14338+
$as_echo_n "checking for $ac_header... " >&6; }
14339+
if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
14340+
$as_echo_n "(cached) " >&6
14341+
fi
14342+
ac_res=`eval 'as_val=${'$as_ac_Header'}
14343+
$as_echo "$as_val"'`
14344+
{ $as_echo "$as_me:$LINENO: result: $ac_res" >&5
14345+
$as_echo "$ac_res" >&6; }
14346+
else
14347+
# Is the header compilable?
14348+
{ $as_echo "$as_me:$LINENO: checking $ac_header usability" >&5
14349+
$as_echo_n "checking $ac_header usability... " >&6; }
14350+
cat >conftest.$ac_ext <<_ACEOF
14351+
/* confdefs.h. */
14352+
_ACEOF
14353+
cat confdefs.h >>conftest.$ac_ext
14354+
cat >>conftest.$ac_ext <<_ACEOF
14355+
/* end confdefs.h. */
14356+
$ac_includes_default
14357+
#include <$ac_header>
14358+
_ACEOF
14359+
rm -f conftest.$ac_objext
14360+
if { (ac_try="$ac_compile"
14361+
case "(($ac_try" in
14362+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
14363+
*) ac_try_echo=$ac_try;;
14364+
esac
14365+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
14366+
$as_echo "$ac_try_echo") >&5
14367+
(eval "$ac_compile") 2>conftest.er1
14368+
ac_status=$?
14369+
grep -v '^ *+' conftest.er1 >conftest.err
14370+
rm -f conftest.er1
14371+
cat conftest.err >&5
14372+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
14373+
(exit $ac_status); } && {
14374+
test -z "$ac_c_werror_flag" ||
14375+
test ! -s conftest.err
14376+
} && test -s conftest.$ac_objext; then
14377+
ac_header_compiler=yes
14378+
else
14379+
$as_echo "$as_me: failed program was:" >&5
14380+
sed 's/^/| /' conftest.$ac_ext >&5
14381+
14382+
ac_header_compiler=no
14383+
fi
14384+
14385+
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
14386+
{ $as_echo "$as_me:$LINENO: result: $ac_header_compiler" >&5
14387+
$as_echo "$ac_header_compiler" >&6; }
14388+
14389+
# Is the header present?
14390+
{ $as_echo "$as_me:$LINENO: checking $ac_header presence" >&5
14391+
$as_echo_n "checking $ac_header presence... " >&6; }
14392+
cat >conftest.$ac_ext <<_ACEOF
14393+
/* confdefs.h. */
14394+
_ACEOF
14395+
cat confdefs.h >>conftest.$ac_ext
14396+
cat >>conftest.$ac_ext <<_ACEOF
14397+
/* end confdefs.h. */
14398+
#include <$ac_header>
14399+
_ACEOF
14400+
if { (ac_try="$ac_cpp conftest.$ac_ext"
14401+
case "(($ac_try" in
14402+
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
14403+
*) ac_try_echo=$ac_try;;
14404+
esac
14405+
eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\""
14406+
$as_echo "$ac_try_echo") >&5
14407+
(eval "$ac_cpp conftest.$ac_ext") 2>conftest.er1
14408+
ac_status=$?
14409+
grep -v '^ *+' conftest.er1 >conftest.err
14410+
rm -f conftest.er1
14411+
cat conftest.err >&5
14412+
$as_echo "$as_me:$LINENO: \$? = $ac_status" >&5
14413+
(exit $ac_status); } >/dev/null && {
14414+
test -z "$ac_c_preproc_warn_flag$ac_c_werror_flag" ||
14415+
test ! -s conftest.err
14416+
}; then
14417+
ac_header_preproc=yes
14418+
else
14419+
$as_echo "$as_me: failed program was:" >&5
14420+
sed 's/^/| /' conftest.$ac_ext >&5
14421+
14422+
ac_header_preproc=no
14423+
fi
14424+
14425+
rm -f conftest.err conftest.$ac_ext
14426+
{ $as_echo "$as_me:$LINENO: result: $ac_header_preproc" >&5
14427+
$as_echo "$ac_header_preproc" >&6; }
14428+
14429+
# So? What about this header?
14430+
case $ac_header_compiler:$ac_header_preproc:$ac_c_preproc_warn_flag in
14431+
yes:no: )
14432+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&5
14433+
$as_echo "$as_me: WARNING: $ac_header: accepted by the compiler, rejected by the preprocessor!" >&2;}
14434+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the compiler's result" >&5
14435+
$as_echo "$as_me: WARNING: $ac_header: proceeding with the compiler's result" >&2;}
14436+
ac_header_preproc=yes
14437+
;;
14438+
no:yes:* )
14439+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: present but cannot be compiled" >&5
14440+
$as_echo "$as_me: WARNING: $ac_header: present but cannot be compiled" >&2;}
14441+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: check for missing prerequisite headers?" >&5
14442+
$as_echo "$as_me: WARNING: $ac_header: check for missing prerequisite headers?" >&2;}
14443+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: see the Autoconf documentation" >&5
14444+
$as_echo "$as_me: WARNING: $ac_header: see the Autoconf documentation" >&2;}
14445+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&5
14446+
$as_echo "$as_me: WARNING: $ac_header: section \"Present But Cannot Be Compiled\"" >&2;}
14447+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: proceeding with the preprocessor's result" >&5
14448+
$as_echo "$as_me: WARNING: $ac_header: proceeding with the preprocessor's result" >&2;}
14449+
{ $as_echo "$as_me:$LINENO: WARNING: $ac_header: in the future, the compiler will take precedence" >&5
14450+
$as_echo "$as_me: WARNING: $ac_header: in the future, the compiler will take precedence" >&2;}
14451+
( cat <<\_ASBOX
14452+
## ---------------------------------------- ##
14453+
## Report this to pgsql-bugs@postgresql.org ##
14454+
## ---------------------------------------- ##
14455+
_ASBOX
14456+
) | sed "s/^/$as_me: WARNING: /" >&2
14457+
;;
14458+
esac
14459+
{ $as_echo "$as_me:$LINENO: checking for $ac_header" >&5
14460+
$as_echo_n "checking for $ac_header... " >&6; }
14461+
if { as_var=$as_ac_Header; eval "test \"\${$as_var+set}\" = set"; }; then
14462+
$as_echo_n "(cached) " >&6
14463+
else
14464+
eval "$as_ac_Header=\$ac_header_preproc"
14465+
fi
14466+
ac_res=`eval 'as_val=${'$as_ac_Header'}
14467+
$as_echo "$as_val"'`
14468+
{ $as_echo "$as_me:$LINENO: result: $ac_res" >&5
14469+
$as_echo "$ac_res" >&6; }
14470+
14471+
fi
14472+
as_val=`eval 'as_val=${'$as_ac_Header'}
14473+
$as_echo "$as_val"'`
14474+
if test "x$as_val" = x""yes; then
14475+
cat >>confdefs.h <<_ACEOF
14476+
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
14477+
_ACEOF
14478+
14479+
fi
14480+
14481+
done
14482+
14483+
fi
1433114484

1433214485
##
1433314486
## Types, structures, compiler characteristics
@@ -17997,7 +18150,8 @@ fi
1799718150
# compiler characteristic, but you'd be wrong. We must check this before
1799818151
# probing existence of related functions such as fseeko, since the largefile
1799918152
# defines can affect what is generated for that.
18000-
# Check whether --enable-largefile was given.
18153+
if test "$PORTNAME" != "win32"; then
18154+
# Check whether --enable-largefile was given.
1800118155
if test "${enable_largefile+set}" = set; then
1800218156
enableval=$enable_largefile;
1800318157
fi
@@ -18353,6 +18507,7 @@ rm -rf conftest*
1835318507
fi
1835418508
fi
1835518509

18510+
fi
1835618511

1835718512
# Check for largefile support (must be after AC_SYS_LARGEFILE)
1835818513
# The cast to long int works around a bug in the HP C Compiler
@@ -18808,7 +18963,7 @@ else
1880818963
if test "${ac_cv_func_accept_arg3+set}" = set; then
1880918964
$as_echo_n "(cached) " >&6
1881018965
else
18811-
for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL' 'SOCKET'; do
18966+
for ac_cv_func_accept_return in 'int' 'unsigned int PASCAL' 'SOCKET WSAAPI'; do
1881218967
for ac_cv_func_accept_arg1 in 'int' 'unsigned int' 'SOCKET'; do
1881318968
for ac_cv_func_accept_arg2 in 'struct sockaddr *' 'const struct sockaddr *' 'void *'; do
1881418969
for ac_cv_func_accept_arg3 in 'int' 'size_t' 'socklen_t' 'unsigned int' 'void'; do

configure.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,9 @@ if test "$with_ossp_uuid" = yes ; then
11011101
[AC_MSG_ERROR([header file <ossp/uuid.h> or <uuid.h> is required for OSSP-UUID])])])
11021102
fi
11031103

1104+
if test "$PORTNAME" = "win32" ; then
1105+
AC_CHECK_HEADERS(crtdefs.h)
1106+
fi
11041107

11051108
##
11061109
## Types, structures, compiler characteristics
@@ -1174,7 +1177,9 @@ fi
11741177
# compiler characteristic, but you'd be wrong. We must check this before
11751178
# probing existence of related functions such as fseeko, since the largefile
11761179
# defines can affect what is generated for that.
1177-
AC_SYS_LARGEFILE
1180+
if test "$PORTNAME" != "win32"; then
1181+
AC_SYS_LARGEFILE
1182+
fi
11781183

11791184
# Check for largefile support (must be after AC_SYS_LARGEFILE)
11801185
AC_CHECK_SIZEOF([off_t])

src/include/c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
#endif
5959
#include "postgres_ext.h"
6060

61-
#if _MSC_VER >= 1400 || defined(WIN64)
61+
#define HAVE_CRTDEFS_H 1
62+
#if _MSC_VER >= 1400 || defined(HAVE_CRTDEFS_H)
6263
#define errcode __msvc_errcode
6364
#include <crtdefs.h>
6465
#undef errcode

src/include/pg_config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
/* Define to 1 if you have the `class' function. */
100100
#undef HAVE_CLASS
101101

102+
/* Define to 1 if you have the <crtdefs.h> header file. */
103+
#undef HAVE_CRTDEFS_H
104+
102105
/* Define to 1 if you have the `crypt' function. */
103106
#undef HAVE_CRYPT
104107

src/include/port/win32.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* The Mingw64 headers choke if this is already defined - they
3232
* define it themselves.
3333
*/
34-
#if !defined(WIN64) || defined(WIN32_ONLY_COMPILER)
34+
#if !defined(__MINGW64_VERSION_MAJOR) || defined(WIN32_ONLY_COMPILER)
3535
#define _WINSOCKAPI_
3636
#endif
3737
#include <winsock2.h>
@@ -225,9 +225,13 @@ int setitimer(int which, const struct itimerval * value, struct itimerval * ov
225225
#define fseeko(stream, offset, origin) _fseeki64(stream, offset, origin)
226226
#define ftello(stream) _ftelli64(stream)
227227
#else
228+
#ifndef fseeko
228229
#define fseeko(stream, offset, origin) fseeko64(stream, offset, origin)
230+
#endif
231+
#ifndef ftello
229232
#define ftello(stream) ftello64(stream)
230233
#endif
234+
#endif
231235

232236
/*
233237
* Supplement to <sys/types.h>.
@@ -264,16 +268,36 @@ typedef int pid_t;
264268
#undef EINTR
265269
#define EINTR WSAEINTR
266270
#define EAGAIN WSAEWOULDBLOCK
271+
#ifndef EMSGSIZE
267272
#define EMSGSIZE WSAEMSGSIZE
273+
#endif
274+
#ifndef EAFNOSUPPORT
268275
#define EAFNOSUPPORT WSAEAFNOSUPPORT
276+
#endif
277+
#ifndef EWOULDBLOCK
269278
#define EWOULDBLOCK WSAEWOULDBLOCK
279+
#endif
280+
#ifndef ECONNRESET
270281
#define ECONNRESET WSAECONNRESET
282+
#endif
283+
#ifndef EINPROGRESS
271284
#define EINPROGRESS WSAEINPROGRESS
285+
#endif
286+
#ifndef ENOBUFS
272287
#define ENOBUFS WSAENOBUFS
288+
#endif
289+
#ifndef EPROTONOSUPPORT
273290
#define EPROTONOSUPPORT WSAEPROTONOSUPPORT
291+
#endif
292+
#ifndef ECONNREFUSED
274293
#define ECONNREFUSED WSAECONNREFUSED
294+
#endif
295+
#ifndef EBADFD
275296
#define EBADFD WSAENOTSOCK
297+
#endif
298+
#ifndef EOPNOTSUPP
276299
#define EOPNOTSUPP WSAEOPNOTSUPP
300+
#endif
277301

278302
/*
279303
* Extended locale functions with gratuitous underscore prefixes.

src/interfaces/ecpg/test/resultmap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
compat_informix/dec_test:stdout:i.86-pc-win32vc=compat_informix-dec_test-MinGW32.stdout
22
compat_informix/dec_test:stdout:i.86-pc-mingw32=compat_informix-dec_test-MinGW32.stdout
33
compat_informix/dec_test:stdout:x86_64-w64-mingw32=compat_informix-dec_test-MinGW32.stdout
4+
compat_informix/dec_test:stdout:i.86-w64-mingw32=compat_informix-dec_test-MinGW32.stdout
45
pgtypeslib/num_test:stdout:i.86-pc-win32vc=pgtypeslib-num_test-MinGW32.stdout
56
pgtypeslib/num_test:stdout:i.86-pc-mingw32=pgtypeslib-num_test-MinGW32.stdout
67
pgtypeslib/num_test:stdout:x86_64-w64-mingw32=pgtypeslib-num_test-MinGW32.stdout
8+
pgtypeslib/num_test:stdout:i.86-w64-mingw32=pgtypeslib-num_test-MinGW32.stdout
79
pgtypeslib/num_test2:stdout:i.86-pc-win32vc=pgtypeslib-num_test2-MinGW32.stdout
810
pgtypeslib/num_test2:stdout:i.86-pc-mingw32=pgtypeslib-num_test2-MinGW32.stdout
911
pgtypeslib/num_test2:stdout:x86_64-w64-mingw32=pgtypeslib-num_test2-MinGW32.stdout
12+
pgtypeslib/num_test2:stdout:i.86-w64-mingw32=pgtypeslib-num_test2-MinGW32.stdout

src/interfaces/libpq/win32.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,15 @@
2222
#undef EAGAIN /* doesn't apply on sockets */
2323
#undef EINTR
2424
#define EINTR WSAEINTR
25+
#ifndef EWOULDBLOCK
2526
#define EWOULDBLOCK WSAEWOULDBLOCK
27+
#endif
28+
#ifndef ECONNRESET
2629
#define ECONNRESET WSAECONNRESET
30+
#endif
31+
#ifndef EINPROGRESS
2732
#define EINPROGRESS WSAEINPROGRESS
33+
#endif
2834

2935
/*
3036
* support for handling Windows Socket errors

src/port/getaddrinfo.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,10 @@ gai_strerror(int errcode)
328328
case EAI_MEMORY:
329329
return "Not enough memory";
330330
#endif
331-
#ifdef EAI_NODATA
332-
#if !defined(WIN64) && !defined(WIN32_ONLY_COMPILER) /* MSVC/WIN64 duplicate */
331+
#if defined(EAI_NODATA) && EAI_NODATA != EAI_NONAME /* MSVC/WIN64 duplicate */
333332
case EAI_NODATA:
334333
return "No host data of that type was found";
335334
#endif
336-
#endif
337335
#ifdef EAI_SERVICE
338336
case EAI_SERVICE:
339337
return "Class type not found";

src/test/regress/resultmap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
float4:out:i.86-pc-mingw32=float4-exp-three-digits.out
22
float4:out:x86_64-w64-mingw32=float4-exp-three-digits.out
3+
float4:out:i.86-w64-mingw32=float4-exp-three-digits.out
34
float4:out:i.86-pc-win32vc=float4-exp-three-digits.out
45
float8:out:i.86-.*-freebsd=float8-small-is-zero.out
56
float8:out:i.86-.*-openbsd=float8-small-is-zero.out
67
float8:out:i.86-.*-netbsd=float8-small-is-zero.out
78
float8:out:m68k-.*-netbsd=float8-small-is-zero.out
89
float8:out:i.86-pc-mingw32=float8-exp-three-digits-win32.out
910
float8:out:x86_64-w64-mingw32=float8-exp-three-digits-win32.out
11+
float8:out:i.86-w64-mingw32=float8-exp-three-digits-win32.out
1012
float8:out:i.86-pc-win32vc=float8-exp-three-digits-win32.out
1113
float8:out:i.86-pc-cygwin=float8-small-is-zero.out
1214
int8:out:i.86-pc-mingw32=int8-exp-three-digits.out
1315
int8:out:x86_64-w64-mingw32=int8-exp-three-digits.out
16+
int8:out:i.86-w64-mingw32=int8-exp-three-digits.out
1417
int8:out:i.86-pc-win32vc=int8-exp-three-digits.out

0 commit comments

Comments
 (0)