Skip to content

Commit a2606f9

Browse files
committed
config-mingw: Add (i686|x86_64)-w64-mingw32 toolchain support from MXE
* Add support for 32 and 64-bit w64-mingw32 toolchains from MXE. See http://mxe.cc/ * Add "errmap.h" header including "PC/errmap.h" * Update original mingw patch to avoid patching pyconfig.h. Not useful anymore since this commit introduced one specific to w64-mingw32 toolchain. * Set PYCONFIG_BUILD_DIR to ensure the new pyconfig.h and errmap.h files are included when building. Detailed list of changes: * remove use of _MSC_VER * report error if compiler different from MinGW is used * replace "_WIN64" with "__MINGW64__" * MS_WINX64 is kept for compatibility with extensions that may depend on it. * if not already defined, define COMPILER as "[GCC X.Y.Z]" * remove "hypot" define: both hypot and _hypot are defined toolchain header "" * remove "ssize_t" typedef: it is defined in toolchain header "stddef.h" * remove "pid_t" typedef: it is defined in toolchain header "sys/types.h" * remove explicit define of "PLATFORM", already associated in getplatform.c in libpython/CMakeLists.txt * define HAVE_DIRENT_H * move include of "io.h" after defining compiler. It avoid "#error NTDDI_VERSION and _WIN32_WINNT mismatch!" in x86_64-w64-mingw32.static/include/sdkddkver.h. * remove check for NO_STDIO_H
1 parent c0fa091 commit a2606f9

File tree

4 files changed

+60
-113
lines changed

4 files changed

+60
-113
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,9 @@ elseif(WIN32)
356356
# live along side the python executable.
357357
# See function '_init_posix()' and '_init_non_posix()'
358358
# in 'Lib/sysconfig.py'
359+
if(MINGW)
360+
set(PYCONFIG_BUILD_DIR cmake/config-mingw)
361+
endif()
359362
endif()
360363

361364
# Install 'pyconfig.h'

cmake/config-mingw/errmap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#include "../PC/errmap.h"

cmake/config-mingw/pyconfig.h

Lines changed: 56 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
/* pyconfig.h. NOT Generated automatically by configure.
55
6-
This is a manually maintained version used for the Watcom,
7-
Borland and Microsoft Visual C++ compilers. It is a
8-
standard part of the Python distribution.
6+
This is a manually maintained version (initially based
7+
on "PC/pyconfig.h") used for (i686|x86_64)-w64-mingw32
8+
toolchains (provided by MXE).
99
1010
WINDOWS DEFINES:
1111
The code specific to Windows should be wrapped around one of
@@ -29,18 +29,6 @@ WIN32 is still required for the locale module.
2929
# define Py_BUILD_CORE
3030
#endif /* USE_DL_EXPORT */
3131

32-
33-
#define HAVE_IO_H
34-
#define HAVE_SYS_UTIME_H
35-
#define HAVE_TEMPNAM
36-
#define HAVE_TMPFILE
37-
#define HAVE_TMPNAM
38-
#define HAVE_CLOCK
39-
#define HAVE_STRERROR
40-
#ifdef HAVE_IO_H
41-
#include <io.h>
42-
#endif
43-
4432
#define HAVE_HYPOT
4533
#define HAVE_STRFTIME
4634
#define DONT_HAVE_SIG_ALARM
@@ -61,67 +49,53 @@ WIN32 is still required for the locale module.
6149
#define USE_SOCKET
6250
#endif
6351

64-
65-
/* Compiler specific defines */
66-
6752
/* ------------------------------------------------------------------------*/
68-
/* Microsoft C defines _MSC_VER */
69-
#ifdef _MSC_VER
70-
71-
/* We want COMPILER to expand to a string containing _MSC_VER's *value*.
72-
* This is horridly tricky, because the stringization operator only works
73-
* on macro arguments, and doesn't evaluate macros passed *as* arguments.
74-
* Attempts simpler than the following appear doomed to produce "_MSC_VER"
75-
* literally in the string.
76-
*/
53+
/* (i686|x86_64)-w64-mingw32 toolchains defines __MINGW32__ */
54+
#ifndef __MINGW32__
55+
# error "This file is should be used with MingW compiler"
56+
#endif
57+
7758
#define _Py_PASTE_VERSION(SUFFIX) \
78-
("[MSC v." _Py_STRINGIZE(_MSC_VER) " " SUFFIX "]")
79-
/* e.g., this produces, after compile-time string catenation,
80-
* ("[MSC v.1200 32 bit (Intel)]")
81-
*
82-
* _Py_STRINGIZE(_MSC_VER) expands to
83-
* _Py_STRINGIZE1((_MSC_VER)) expands to
84-
* _Py_STRINGIZE2(_MSC_VER) but as this call is the result of token-pasting
85-
* it's scanned again for macros and so further expands to (under MSVC 6)
86-
* _Py_STRINGIZE2(1200) which then expands to
87-
* "1200"
88-
*/
89-
#define _Py_STRINGIZE(X) _Py_STRINGIZE1((X))
90-
#define _Py_STRINGIZE1(X) _Py_STRINGIZE2 ## X
91-
#define _Py_STRINGIZE2(X) #X
92-
93-
/* MSVC defines _WINxx to differentiate the windows platform types
94-
95-
Note that for compatibility reasons _WIN32 is defined on Win32
59+
("\n[GCC v" __VERSION__ " " SUFFIX "]")
60+
61+
#ifndef COMPILER
62+
# ifdef __MINGW64__
63+
# define COMPILER _Py_PASTE_VERSION("64 bit (AMD64)")
64+
# else
65+
# define COMPILER _Py_PASTE_VERSION("32 bit (i686)")
66+
# endif
67+
#endif /* !COMPILER */
68+
69+
/* MinGW defines __MINGWxx__ to differentiate the windows platform types
70+
71+
Note that for compatibility reasons __MINGW32__ is defined on Win32
9672
*and* on Win64. For the same reasons, in Python, MS_WIN32 is
9773
defined on Win32 *and* Win64. Win32 only code must therefore be
9874
guarded as follows:
9975
#if defined(MS_WIN32) && !defined(MS_WIN64)
100-
Some modules are disabled on Itanium processors, therefore we
101-
have MS_WINI64 set for those targets, otherwise MS_WINX64
10276
*/
103-
#ifdef _WIN64
104-
#define MS_WIN64
77+
78+
#if !defined(MS_WIN64) && defined(__MINGW64__)
79+
# define MS_WIN64
10580
#endif
10681

107-
/* set the COMPILER */
10882
#ifdef MS_WIN64
109-
#define COMPILER _Py_PASTE_VERSION("64 bit (Unknown)")
110-
#endif /* MS_WIN64 */
83+
# define MS_WINX64
84+
#endif
11185

11286
/* set the version macros for the windows headers */
11387
#ifdef MS_WINX64
11488
/* 64 bit only runs on XP or greater */
115-
#define Py_WINVER _WIN32_WINNT_WINXP
116-
#define Py_NTDDI NTDDI_WINXP
89+
# define Py_WINVER _WIN32_WINNT_WINXP
90+
# define Py_NTDDI NTDDI_WINXP
11791
#else
11892
/* Python 2.6+ requires Windows 2000 or greater */
119-
#ifdef _WIN32_WINNT_WIN2K
120-
#define Py_WINVER _WIN32_WINNT_WIN2K
121-
#else
122-
#define Py_WINVER 0x0500
123-
#endif
124-
#define Py_NTDDI NTDDI_WIN2KSP4
93+
# ifdef _WIN32_WINNT_WIN2K
94+
# define Py_WINVER _WIN32_WINNT_WIN2K
95+
# else
96+
# define Py_WINVER 0x0500
97+
# endif
98+
# define Py_NTDDI NTDDI_WIN2KSP4
12599
#endif
126100

127101
/* We only set these values when building Python - we don't want to force
@@ -132,54 +106,41 @@ WIN32 is still required for the locale module.
132106
determines at runtime they are available.
133107
*/
134108
#if defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE)
135-
#ifndef NTDDI_VERSION
136-
#define NTDDI_VERSION Py_NTDDI
137-
#endif
138-
#ifndef WINVER
139-
#define WINVER Py_WINVER
140-
#endif
141-
#ifndef _WIN32_WINNT
142-
#define _WIN32_WINNT Py_WINVER
143-
#endif
144-
#endif
145-
146-
/* _W64 is not defined for VC6 or eVC4 */
147-
#ifndef _W64
148-
#define _W64
149-
#endif
109+
# ifndef NTDDI_VERSION
110+
# define NTDDI_VERSION Py_NTDDI
111+
# endif
112+
# ifndef WINVER
113+
# define WINVER Py_WINVER
114+
# endif
115+
# ifndef _WIN32_WINNT
116+
# define _WIN32_WINNT Py_WINVER
117+
# endif
118+
#endif /* defined(Py_BUILD_CORE) || defined(Py_BUILD_CORE_MODULE) */
150119

151120
/* Define like size_t, omitting the "unsigned" */
152-
#ifdef MS_WIN64
153-
typedef __int64 ssize_t;
154-
#else
155-
typedef _W64 int ssize_t;
156-
#endif
157121
#define HAVE_SSIZE_T 1
158122

159-
#if defined(MS_WIN32) && !defined(MS_WIN64)
160-
#define COMPILER _Py_PASTE_VERSION("32 bit (Unknown)")
161-
#endif /* MS_WIN32 && !MS_WIN64 */
162-
163-
typedef int pid_t;
164-
165123
#include <float.h>
166124
#define Py_IS_NAN _isnan
167125
#define Py_IS_INFINITY(X) (!_finite(X) && !_isnan(X))
168126
#define Py_IS_FINITE(X) _finite(X)
169127
#define copysign _copysign
170128

171-
#define hypot _hypot
172-
173-
#endif /* _MSC_VER */
174-
175129
#include <basetsd.h>
176130

177131
/* ------------------------------------------------------------------------*/
178132
/* End of compilers - finish up */
179133

180-
#ifndef NO_STDIO_H
181-
# include <stdio.h>
182-
#endif
134+
#define HAVE_IO_H
135+
#define HAVE_SYS_UTIME_H
136+
#define HAVE_TEMPNAM
137+
#define HAVE_TMPFILE
138+
#define HAVE_TMPNAM
139+
#define HAVE_CLOCK
140+
#define HAVE_STRERROR
141+
142+
#include <io.h>
143+
#include <stdio.h>
183144

184145
/* 64 bit ints are usually spelt __int64 unless compiler has overridden */
185146
#define HAVE_LONG_LONG 1
@@ -220,7 +181,6 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
220181
/* maintain "win32" sys.platform for backward compatibility of Python code,
221182
the Win64 API should be close enough to the Win32 API to make this
222183
preferable */
223-
# define PLATFORM "win32"
224184
# define SIZEOF_VOID_P 8
225185
# define SIZEOF_TIME_T 8
226186
# define SIZEOF_OFF_T 4
@@ -234,7 +194,6 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
234194
should define this. */
235195
# define HAVE_LARGEFILE_SUPPORT
236196
#elif defined(MS_WIN32)
237-
# define PLATFORM "win32"
238197
# define HAVE_LARGEFILE_SUPPORT
239198
# define SIZEOF_VOID_P 4
240199
# define SIZEOF_OFF_T 4
@@ -261,7 +220,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
261220
#define HAVE_UINTPTR_T 1
262221
#define HAVE_INTPTR_T 1
263222

264-
#endif
223+
#endif /* MS_WIN32 */
265224

266225
/* define signed and unsigned exact-width 32-bit and 64-bit types, used in the
267226
implementation of Python long integers. */
@@ -330,7 +289,7 @@ Py_NO_ENABLE_SHARED to find out. Also support MS_NO_COREDLL for b/w compat */
330289
#define HAVE_DIRECT_H 1
331290

332291
/* Define if you have dirent.h. */
333-
/* #define DIRENT 1 */
292+
#define HAVE_DIRENT_H 1
334293

335294
/* Define to the type of elements in the array set by `getgroups'.
336295
Usually this is either `int' or `gid_t'. */

cmake/patches-win32/03-mingw32.patch

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,3 @@
9191
+#if (defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__) || defined(__MINGW32__)) && !defined(__QNX__)
9292
#define INITFUNC initnt
9393
#define MODNAME "nt"
94-
95-
--- /home/david/Python-2.7.1/PC/pyconfig.h 2009-10-24 14:28:38.000000000 +0100
96-
+++ PC/pyconfig.h 2011-01-29 16:03:17.000000000 +0000
97-
@@ -227,6 +227,12 @@
98-
#include <basetsd.h>
99-
#endif
100-
101-
+
102-
+#ifdef __MINGW32__
103-
+# define HAVE_DIRENT_H
104-
+#endif // __MINGW32__
105-
+
106-
+
107-
/* ------------------------------------------------------------------------*/
108-
/* The Borland compiler defines __BORLANDC__ */
109-
/* XXX These defines are likely incomplete, but should be easy to fix. */

0 commit comments

Comments
 (0)