summaryrefslogtreecommitdiff
path: root/python/python-2.7.14-mingw.patch
blob: 9f9dc6c14b77570f00fe5c46c9cbe88d536f8385 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
diff -ru misc/Python-2.7.14/Include/pyport.h misc/build/Python-2.7.14/Include/pyport.h
--- misc/Python-2.7.14/Include/pyport.h	2016-06-25 16:49:30.000000000 -0500
+++ misc/build/Python-2.7.14/Include/pyport.h	2016-09-02 16:42:21.498048000 -0500
@@ -9,6 +9,30 @@
 #include <inttypes.h>
 #endif
 
+#if defined(__MINGW32__)
+#undef HAVE_FORKPTY
+#undef HAVE_OPENPTY
+#undef HAVE_DEV_PTMX
+#undef _POSIX_THREADS
+#undef HAVE_PTHREAD_H
+#define MS_WINDOWS
+#define MS_WIN32
+#define Py_WIN_WIDE_FILENAMES
+#ifndef PYTHONPATH
+#	define PYTHONPATH ".\\lib;.\\lib\\python" VERSION ";.\\lib\\python" VERSION "\\lib-dynload;.\\lib\\python" VERSION "\\plat-winmingw32;.\\lib\\python" VERSION "\\lib-tk"
+#endif
+#define NT_THREADS
+#define WITH_THREAD
+#define WINVER 0x0501
+#ifdef socklen_t
+#undef socklen_t
+#endif
+#define HAVE_ADDRINFO
+#define HAVE_GETADDRINFO
+#define HAVE_GETNAMEINFO
+#define HAVE_GETPEERNAME
+#endif
+
 #ifdef HAVE_STDINT_H
 #include <stdint.h>
 #endif
diff -ru misc/Python-2.7.14/Lib/distutils/ccompiler.py misc/build/Python-2.7.14/Lib/distutils/ccompiler.py
--- misc/Python-2.7.14/Lib/distutils/ccompiler.py	2016-06-25 16:49:30.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/distutils/ccompiler.py	2016-09-02 16:42:21.499097000 -0500
@@ -896,6 +896,7 @@
     # on a cygwin built python we can use gcc like an ordinary UNIXish
     # compiler
     ('cygwin.*', 'unix'),
+    ('winmingw*', 'unix'),
     ('os2emx', 'emx'),
 
     # OS name mappings
diff -ru misc/Python-2.7.14/Lib/distutils/command/build_ext.py misc/build/Python-2.7.14/Lib/distutils/command/build_ext.py
--- misc/Python-2.7.14/Lib/distutils/command/build_ext.py	2016-06-25 16:49:30.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/distutils/command/build_ext.py	2016-09-02 16:42:21.499914000 -0500
@@ -224,7 +224,7 @@
 
         # for extensions under Cygwin and AtheOS Python's library directory must be
         # appended to library_dirs
-        if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
+        if sys.platform[:6] == 'cygwin' or sys.platform[:8] == 'winmingw' or sys.platform[:6] == 'atheos':
             if sys.executable.startswith(os.path.join(sys.exec_prefix, "bin")):
                 # building third party extensions
                 self.library_dirs.append(os.path.join(sys.prefix, "lib",
@@ -726,7 +726,7 @@
             # don't extend ext.libraries, it may be shared with other
             # extensions, it is a reference to the original list
             return ext.libraries + [pythonlib]
-        elif sys.platform[:6] == "cygwin":
+        elif sys.platform[:6] == "cygwin" or sys.platform[:8] == "winmingw":
             template = "python%d.%d"
             pythonlib = (template %
                    (sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
diff -ru misc/Python-2.7.14/Lib/distutils/command/install.py misc/build/Python-2.7.14/Lib/distutils/command/install.py
--- misc/Python-2.7.14/Lib/distutils/command/install.py	2016-06-25 16:49:30.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/distutils/command/install.py	2016-09-02 16:42:21.500659000 -0500
@@ -348,9 +348,10 @@
 
         # Convert directories from Unix /-separated syntax to the local
         # convention.
-        self.convert_paths('lib', 'purelib', 'platlib',
-                           'scripts', 'data', 'headers',
-                           'userbase', 'usersite')
+        if os.sep != '/':
+            self.convert_paths('lib', 'purelib', 'platlib',
+                               'scripts', 'data', 'headers',
+                               'userbase', 'usersite')
 
         # Well, we're not actually fully completely finalized yet: we still
         # have to deal with 'extra_path', which is the hack for allowing
@@ -362,7 +363,7 @@
 
         # If a new root directory was supplied, make all the installation
         # dirs relative to it.
-        if self.root is not None:
+        if self.root is not None and self.root != "":
             self.change_roots('libbase', 'lib', 'purelib', 'platlib',
                               'scripts', 'data', 'headers')
 
@@ -501,7 +502,10 @@
     def convert_paths (self, *names):
         for name in names:
             attr = "install_" + name
-            setattr(self, attr, convert_path(getattr(self, attr)))
+            if self.root is None or self.root == "":
+                setattr(self, attr, getattr(self, attr).replace('/', os.sep))
+            else:
+                setattr(self, attr, convert_path(getattr(self, attr)))
 
 
     def handle_extra_path (self):
diff -ru misc/Python-2.7.14/Lib/distutils/spawn.py misc/build/Python-2.7.14/Lib/distutils/spawn.py
--- misc/Python-2.7.14/Lib/distutils/spawn.py	2016-06-25 16:49:30.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/distutils/spawn.py	2016-09-02 16:42:21.501126000 -0500
@@ -212,7 +212,7 @@
     paths = path.split(os.pathsep)
     base, ext = os.path.splitext(executable)
 
-    if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'):
+    if (sys.platform == 'win32' or sys.platform[:8] == "winmingw" or os.name == 'os2') and (ext != '.exe'):
         executable = executable + '.exe'
 
     if not os.path.isfile(executable):
diff -ru misc/Python-2.7.14/Lib/distutils/sysconfig.py misc/build/Python-2.7.14/Lib/distutils/sysconfig.py
--- misc/Python-2.7.14/Lib/distutils/sysconfig.py	2016-06-25 16:49:30.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/distutils/sysconfig.py	2016-09-02 16:42:21.501681000 -0500
@@ -450,6 +450,9 @@
     global _config_vars
     if _config_vars is None:
         func = globals().get("_init_" + os.name)
+        if sys.platform[:8] == "winmingw":
+            func = globals().get("_init_posix")
+
         if func:
             func()
         else:
diff -ru misc/Python-2.7.14/Lib/distutils/unixccompiler.py misc/build/Python-2.7.14/Lib/distutils/unixccompiler.py
--- misc/Python-2.7.14/Lib/distutils/unixccompiler.py	2016-06-25 16:49:30.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/distutils/unixccompiler.py	2016-09-02 16:44:54.962041000 -0500
@@ -82,7 +82,7 @@
     xcode_stub_lib_extension = ".tbd"
     static_lib_format = shared_lib_format = dylib_lib_format = "lib%s%s"
     xcode_stub_lib_format = dylib_lib_format
-    if sys.platform == "cygwin":
+    if sys.platform == "cygwin" or sys.platform == "winmingw":
         exe_extension = ".exe"
 
     def preprocess(self, source,
diff -ru misc/Python-2.7.14/Lib/os.py misc/build/Python-2.7.14/Lib/os.py
--- misc/Python-2.7.14/Lib/os.py	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/os.py	2016-09-02 16:42:21.503786000 -0500
@@ -38,7 +38,21 @@
     except AttributeError:
         return [n for n in dir(module) if n[0] != '_']
 
-if 'posix' in _names:
+if 'winmingw32' in _names:
+    name = 'nt'
+    linesep = '\r\n'
+    from posix import *
+    try:
+        from posix import _exit
+    except ImportError:
+        pass
+    import ntpath as path
+
+    import posix
+    __all__.extend(_get_exports_list(posix))
+    del posix
+
+elif 'posix' in _names:
     name = 'posix'
     linesep = '\n'
     from posix import *
diff -ru misc/Python-2.7.14/Lib/socket.py misc/build/Python-2.7.14/Lib/socket.py
--- misc/Python-2.7.14/Lib/socket.py	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Lib/socket.py	2016-09-02 16:42:21.504874000 -0500
@@ -157,7 +157,7 @@
     'sendall', 'setblocking',
     'settimeout', 'gettimeout', 'shutdown')
 
-if os.name == "nt":
+if os.name == "nt" and sys.platform[:8] != "winmingw":
     _socketmethods = _socketmethods + ('ioctl',)
 
 if sys.platform == "riscos":
diff -ru misc/Python-2.7.14/Makefile.pre.in misc/build/Python-2.7.14/Makefile.pre.in
--- misc/Python-2.7.14/Makefile.pre.in	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Makefile.pre.in	2016-09-02 16:42:21.506300000 -0500
@@ -125,6 +125,16 @@
 BLDSHARED=	@BLDSHARED@ $(LDFLAGS)
 LDCXXSHARED=	@LDCXXSHARED@
 DESTSHARED=	$(BINLIBDEST)/lib-dynload
+ifeq (@MACHDEP@,winmingw32)
+DESTSHAREDFORRULES=	$(shell cd $(DESTSHARED) && pwd || echo DESTSHARED)
+LIBPYTHONPATH=	$(shell cd $(DESTDIR)$(LIBDEST) && cmd /c cd | sed -e s:\\\\:/:g)
+DESTPYTHONPATH=	$(LIBPYTHONPATH);$(shell cd $(DESTDIR)$(DESTSHARED) && cmd /c cd | sed -e s:\\\\:/:g)
+LIBDESTPARAM=	$(shell if test -z "$(DESTDIR)" ; then cd $(LIBDEST) && cmd /c cd | sed -e s:\\\\:/:g ; else echo $(LIBDEST) ; fi)
+PREFIXPARAM=	$(shell if test -z "$(DESTDIR)" ; then cd $(prefix) && cmd /c cd | sed -e s:\\\\:/:g ; else echo $(prefix) ; fi)
+BINDIRPARAM=	$(shell if test -z "$(DESTDIR)" ; then cd $(BINDIR) && cmd /c cd | sed -e s:\\\\:/:g ; else echo $(BINDIR) ; fi)
+DESTSHAREDPARAM=	$(shell if test -z "$(DESTDIR)" ; then cd $(DESTSHARED) && cmd /c cd | sed -e s:\\\\:/:g ; else echo $(DESTSHARED) ; fi)
+DESTDIRPARAM=	$(shell if test ! -z "$(DESTDIR)" ; then cd $(DESTDIR) && cmd /c | sed -e s:\\\\:/:g ; fi)
+endif
 
 # Executable suffix (.exe on Windows and Mac OS X)
 EXE=		@EXEEXT@
@@ -225,7 +235,7 @@
 # Modules
 MODULE_OBJS=	\
 		Modules/config.o \
-		Modules/getpath.o \
+		@GETPATH_OBJS@ \
 		Modules/main.o \
 		Modules/gcmodule.o
 
@@ -646,6 +656,10 @@
 		-DVPATH='"$(VPATH)"' \
 		-o $@ $(srcdir)/Modules/getpath.c
 
+PC/getpathp.o: $(srcdir)/PC/getpathp.c Makefile
+	$(CC) -c $(PY_CFLAGS) -DVERSION='"$(VERSION)"' \
+		-o $@ $(srcdir)/PC/getpathp.c
+
 Modules/python.o: $(srcdir)/Modules/python.c
 	$(MAINCC) -c $(PY_CFLAGS) -o $@ $(srcdir)/Modules/python.c
 
@@ -700,6 +714,12 @@
 Objects/unicodectype.o:	$(srcdir)/Objects/unicodectype.c \
 				$(srcdir)/Objects/unicodetype_db.h
 
+Objects/exceptions.o:	$(srcdir)/Objects/exceptions.c
+		$(CC) -c $(PY_CFLAGS) -I$(srcdir)/PC -o $@ $(srcdir)/Objects/exceptions.c
+
+PC/import_nt.o: $(srcdir)/PC/import_nt.c
+		$(CC) -c $(PY_CFLAGS) -I$(srcdir)/Python -o $@ $(srcdir)/PC/import_nt.c
+
 STRINGLIB_HEADERS= \
 		$(srcdir)/Include/bytes_methods.h \
 		$(srcdir)/Objects/stringlib/count.h \
@@ -928,7 +948,11 @@
 # Install shared libraries enabled by Setup
 DESTDIRS=	$(exec_prefix) $(LIBDIR) $(BINLIBDEST) $(DESTSHARED)
 
+ifeq (@MACHDEP@,winmingw32)
+oldsharedinstall: $(DESTSHAREDFORRULES) $(SHAREDMODS)
+else
 oldsharedinstall: $(DESTSHARED) $(SHAREDMODS)
+endif
 		@for i in X $(SHAREDMODS); do \
 		  if test $$i != X; then \
 		    echo $(INSTALL_SHARED) $$i $(DESTSHARED)/`basename $$i`; \
@@ -936,7 +960,11 @@
 		  fi; \
 		done
 
+ifeq (@MACHDEP@,winmingw32)
+$(DESTSHAREDFORRULES):
+else
 $(DESTSHARED):
+endif
 		@for i in $(DESTDIRS); \
 		do \
 			if test ! -d $(DESTDIR)$$i; then \
@@ -1054,7 +1082,11 @@
 		unittest unittest/test \
 		lib-old \
 		curses pydoc_data $(MACHDEPS)
+ifeq (@MACHDEP@,winmingw32)
+libinstall:	build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c sharedinstall
+else
 libinstall:	build_all $(srcdir)/Lib/$(PLATDIR) $(srcdir)/Modules/xxmodule.c
+endif
 	@for i in $(SCRIPTDIR) $(LIBDEST); \
 	do \
 		if test ! -d $(DESTDIR)$$i; then \
@@ -1114,6 +1082,26 @@
 		$(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \
 			$(DESTDIR)$(LIBDEST)/distutils/tests ; \
 	fi
+ifeq (@MACHDEP@,winmingw32)
+	PYTHONPATH="$(DESTPYTHONPATH)"  $(RUNSHARED) \
+		./$(BUILDPYTHON) -Wi -tt $(LIBPYTHONPATH)/compileall.py \
+		-d $(LIBDESTPARAM) -f \
+		-x 'bad_coding|badsyntax|site-packages' $(LIBPYTHONPATH)
+	PYTHONPATH="$(DESTPYTHONPATH)"  $(RUNSHARED) \
+		./$(BUILDPYTHON) -Wi -tt -O $(LIBPYTHONPATH)/compileall.py \
+		-d $(LIBDESTPARAM) -f \
+		-x 'bad_coding|badsyntax|site-packages' $(LIBPYTHONPATH)
+	-PYTHONPATH="$(DESTPYTHONPATH)"  $(RUNSHARED) \
+		./$(BUILDPYTHON) -Wi -t $(LIBPYTHONPATH)/compileall.py \
+		-d $(LIBDESTPARAM)/site-packages -f \
+		-x badsyntax $(LIBPYTHONPATH)/site-packages
+	-PYTHONPATH="$(DESTPYTHONPATH)"  $(RUNSHARED) \
+		./$(BUILDPYTHON) -Wi -t -O $(LIBPYTHONPATH)/compileall.py \
+		-d $(LIBDESTPARAM)/site-packages -f \
+		-x badsyntax $(LIBPYTHONPATH)/site-packages
+	-PYTHONPATH="$(DESTPYTHONPATH)"  $(RUNSHARED) \
+		./$(BUILDPYTHON) -Wi -t -c "import lib2to3.pygram, lib2to3.patcomp;lib2to3.patcomp.PatternCompiler()"
+else
 	PYTHONPATH=$(DESTDIR)$(LIBDEST)  $(RUNSHARED) \
 		$(PYTHON_FOR_BUILD) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
 		-d $(LIBDEST) -f \
@@ -1140,6 +1190,7 @@
 # Create the PLATDIR source directory, if one wasn't distributed..
 $(srcdir)/Lib/$(PLATDIR):
 	mkdir $(srcdir)/Lib/$(PLATDIR)
+ifneq (@MACHDEP@,winmingw32)
 	cp $(srcdir)/Lib/plat-generic/regen $(srcdir)/Lib/$(PLATDIR)/regen
 	export PATH; PATH="`pwd`:$$PATH"; \
 	export PYTHONPATH; PYTHONPATH="$(srcdir)/Lib:$(abs_builddir)/`cat pybuilddir.txt`"; \
@@ -1153,6 +1207,7 @@
 	  PYTHON_FOR_BUILD="$(PYTHON_FOR_BUILD)"; \
 	fi; \
 	cd $(srcdir)/Lib/$(PLATDIR); $(RUNSHARED) ./regen
+endif
 
 python-config: $(srcdir)/Misc/python-config.in
 	# Substitution happens here, as the completely-expanded BINDIR
@@ -1246,6 +1300,15 @@
 
 # Install the dynamically loadable modules
 # This goes into $(exec_prefix)
+ifeq (@MACHDEP@,winmingw32)
+sharedinstall: $(DESTSHAREDFORRULES)
+       $(RUNSHARED) ./$(BUILDPYTHON) -E $(srcdir)/setup.py install \
+               --prefix=$(PREFIXPARAM) \
+               --install-scripts=$(BINDIRPARAM) \
+               --install-platlib=$(DESTSHAREDPARAM) \
+               --root=$(DESTDIRPARAM)
+else
+
 sharedinstall: sharedmods
 	$(RUNSHARED) $(PYTHON_FOR_BUILD) $(srcdir)/setup.py install \
 	   	--prefix=$(prefix) \
@@ -1253,6 +1316,7 @@
 		--install-platlib=$(DESTSHARED) \
 		--root=$(DESTDIR)/
 	-rm $(DESTDIR)$(DESTSHARED)/_sysconfigdata.py*
+endif
 
 # Here are a couple of targets for MacOSX again, to install a full
 # framework-based Python. frameworkinstall installs everything, the
diff -ru misc/Python-2.7.14/Modules/Setup.config.in misc/build/Python-2.7.14/Modules/Setup.config.in
--- misc/Python-2.7.14/Modules/Setup.config.in	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/Setup.config.in	2016-09-02 16:42:21.507091000 -0500
@@ -9,5 +9,9 @@
 # The signal module
 @USE_SIGNAL_MODULE@signal signalmodule.c
 
+# The password module
+@USE_PASSWORD_MODULE@pwd pwdmodule.c	# this is needed to find out the user's home dir
+					# if $HOME is not set
+
 # The rest of the modules previously listed in this file are built
 # by the setup.py script in Python 2.1 and later.
diff -ru misc/Python-2.7.14/Modules/Setup.dist misc/build/Python-2.7.14/Modules/Setup.dist
--- misc/Python-2.7.14/Modules/Setup.dist	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/Setup.dist	2016-09-02 16:42:21.507936000 -0500
@@ -114,7 +114,7 @@
 
 posix posixmodule.c		# posix (UNIX) system calls
 errno errnomodule.c		# posix (UNIX) errno values
-pwd pwdmodule.c			# this is needed to find out the user's home dir
+#pwd pwdmodule.c			# this is needed to find out the user's home dir
 				# if $HOME is not set
 _sre _sre.c			# Fredrik Lundh's new regular expressions
 _codecs _codecsmodule.c		# access to the builtin codecs and codec registry
diff -ru misc/Python-2.7.14/Modules/_ctypes/libffi/configure misc/build/Python-2.7.14/Modules/_ctypes/libffi/configure
--- misc/Python-2.7.14/Modules/_ctypes/libffi/configure	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/_ctypes/libffi/configure	2016-09-02 16:42:21.516830000 -0500
@@ -18807,6 +18807,12 @@
 fi
 
 
+case $host_os in
+mingw*)
+	srcdir=`cd $srcdir && cmd /c cd | sed -e 's:\\\\:/:g'`
+	;;
+esac
+
 ac_config_commands="$ac_config_commands include"
 
 ac_config_commands="$ac_config_commands src"
diff -ru misc/Python-2.7.14/Modules/_ctypes/libffi/configure.ac misc/build/Python-2.7.14/Modules/_ctypes/libffi/configure.ac
--- misc/Python-2.7.14/Modules/_ctypes/libffi/configure.ac	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/_ctypes/libffi/configure.ac	2016-09-02 16:42:21.517727000 -0500
@@ -613,6 +613,12 @@
 fi
 AC_SUBST(toolexeclibdir)
 
+case $host_os in
+mingw*)
+	srcdir=`cd $srcdir && cmd /c cd | sed -e 's:\\\\:/:g'`
+	;;
+esac
+
 AC_CONFIG_COMMANDS(include, [test -d include || mkdir include])
 AC_CONFIG_COMMANDS(src, [
 test -d src || mkdir src
diff -ru misc/Python-2.7.14/Modules/_ctypes/libffi/include/ffi.h.in misc/build/Python-2.7.14/Modules/_ctypes/libffi/include/ffi.h.in
--- misc/Python-2.7.14/Modules/_ctypes/libffi/include/ffi.h.in	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/_ctypes/libffi/include/ffi.h.in	2016-09-02 16:42:21.518314000 -0500
@@ -433,7 +433,11 @@
 			    ffi_type *rtype,
 			    ffi_type **atypes);
 
+#ifdef MS_WIN32
+int ffi_call(ffi_cif *cif,
+#else
 void ffi_call(ffi_cif *cif,
+#endif
 	      void (*fn)(void),
 	      void *rvalue,
 	      void **avalue);
diff -ru misc/Python-2.7.14/Modules/config.c.in misc/build/Python-2.7.14/Modules/config.c.in
--- misc/Python-2.7.14/Modules/config.c.in	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/config.c.in	2016-09-02 16:42:21.518926000 -0500
@@ -48,6 +48,9 @@
     {"__builtin__", NULL},
     {"sys", NULL},
     {"exceptions", NULL},
+#ifdef __MINGW32__
+	{"winmingw32", NULL},
+#endif
 
     /* This lives in gcmodule.c */
     {"gc", initgc},
diff -ru misc/Python-2.7.14/Modules/posixmodule.c misc/build/Python-2.7.14/Modules/posixmodule.c
--- misc/Python-2.7.14/Modules/posixmodule.c	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/posixmodule.c	2016-09-02 16:42:21.523456000 -0500
@@ -132,6 +132,15 @@
 #define HAVE_FSYNC      1
 #define fsync _commit
 #else
+#ifdef __MINGW32__
+#define HAVE_SPAWNV	1
+#define HAVE_EXECV      1
+#define HAVE_GETCWD     1
+#define HAVE_OPENDIR    1
+#define HAVE_PIPE       1
+#define HAVE_POPEN      1
+#define HAVE_SYSTEM	1
+#else
 #if defined(PYOS_OS2) && defined(PYCC_GCC) || defined(__VMS)
 /* Everything needed is defined in PC/os2emx/pyconfig.h or vms/pyconfig.h */
 #else                   /* all other compilers */
@@ -157,6 +166,7 @@
 #define HAVE_WAIT       1
 #define HAVE_TTYNAME    1
 #endif  /* PYOS_OS2 && PYCC_GCC && __VMS */
+#endif  /* __MINGW32__ */
 #endif  /* _MSC_VER */
 #endif  /* __BORLANDC__ */
 #endif  /* ! __WATCOMC__ || __QNX__ */
@@ -277,6 +287,14 @@
 #define pclose  _pclose
 #endif /* _MSC_VER */
 
+#ifdef __MINGW32__
+#include "osdefs.h"
+#include <windows.h>
+#include <shellapi.h>	/* for ShellExecute() */
+#define popen	_popen
+#define pclose	_pclose
+#endif
+
 #if defined(PYCC_VACPP) && defined(PYOS_OS2)
 #include <io.h>
 #endif /* OS2 */
@@ -630,7 +648,7 @@
 */
 #include <crt_externs.h>
 static char **environ;
-#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
+#elif !defined(_MSC_VER) && !defined(__MINGW32__) && ( !defined(__WATCOMC__) || defined(__QNX__) )
 extern char **environ;
 #endif /* !_MSC_VER */
 
@@ -1049,7 +1067,7 @@
     int st_ctime_nsec;
 };
 
-static __int64 secs_between_epochs = 11644473600; /* Seconds between 1.1.1601 and 1.1.1970 */
+static __int64 secs_between_epochs = 11644473600LL; /* Seconds between 1.1.1601 and 1.1.1970 */
 
 static void
 FILE_TIME_to_time_t_nsec(FILETIME *in_ptr, time_t *time_out, int* nsec_out)
@@ -1568,7 +1586,7 @@
     return v;
 }
 
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) && !defined(__MINGW32__)
 
 /* IsUNCRoot -- test whether the supplied path is of the form \\SERVER\SHARE\,
    where / can be used in place of \ and the trailing slash is optional.
diff -ru misc/Python-2.7.14/Modules/socketmodule.c misc/build/Python-2.7.14/Modules/socketmodule.c
--- misc/Python-2.7.14/Modules/socketmodule.c	2016-06-25 16:49:31.000000000 -0500
+++ misc/build/Python-2.7.14/Modules/socketmodule.c	2016-09-02 16:42:21.526595000 -0500
@@ -341,7 +341,7 @@
   /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and
    * EAI_* constants are defined in (the already included) ws2tcpip.h.
    */
-#else
+#elif !defined(__MINGW32__)
 #  include "addrinfo.h"
 #endif
 
diff -ru misc/Python-2.7.14/PC/_winreg.c misc/build/Python-2.7.14/PC/_winreg.c
--- misc/Python-2.7.14/PC/_winreg.c	2016-06-25 16:49:32.000000000 -0500
+++ misc/build/Python-2.7.14/PC/_winreg.c	2016-09-02 16:42:21.528227000 -0500
@@ -1792,6 +1792,9 @@
 }
 
 #define ADD_KEY(val) inskey(d, #val, val)
+#ifndef REG_LEGAL_CHANGE_FILTER
+#define REG_LEGAL_CHANGE_FILTER (REG_NOTIFY_CHANGE_NAME|REG_NOTIFY_CHANGE_ATTRIBUTES|REG_NOTIFY_CHANGE_LAST_SET|REG_NOTIFY_CHANGE_SECURITY)
+#endif
 
 PyMODINIT_FUNC init_winreg(void)
 {
diff -ru misc/Python-2.7.14/Python/dynload_win.c misc/build/Python-2.7.14/Python/dynload_win.c
--- misc/Python-2.7.14/Python/dynload_win.c	2016-06-25 16:49:32.000000000 -0500
+++ misc/build/Python-2.7.14/Python/dynload_win.c	2016-09-02 16:42:21.528984000 -0500
@@ -28,6 +28,7 @@
 /* Case insensitive string compare, to avoid any dependencies on particular
    C RTL implementations */
 
+#ifndef __MINGW32__
 static int strcasecmp (char *string1, char *string2)
 {
     int first, second;
@@ -41,6 +42,7 @@
 
     return (first - second);
 }
+#endif
 
 
 /* Function to return the name of the "python" DLL that the supplied module
diff -ru misc/Python-2.7.14/Python/frozenmain.c misc/build/Python-2.7.14/Python/frozenmain.c
--- misc/Python-2.7.14/Python/frozenmain.c	2016-06-25 16:49:32.000000000 -0500
+++ misc/build/Python-2.7.14/Python/frozenmain.c	2016-09-02 16:46:11.594746000 -0500
@@ -3,7 +3,7 @@
 
 #include "Python.h"
 
-#ifdef MS_WINDOWS
+#if defined(MS_WINDOWS) && !defined(__MINGW32__)
 extern void PyWinFreeze_ExeInit(void);
 extern void PyWinFreeze_ExeTerm(void);
 extern int PyInitFrozenExtensions(void);
@@ -32,13 +32,13 @@
         setbuf(stderr, (char *)NULL);
     }
 
-#ifdef MS_WINDOWS
+#ifdef MS_WINDOWS && !defined(__MINGW32__)
     PyInitFrozenExtensions();
 #endif /* MS_WINDOWS */
     if (argc >= 1)
         Py_SetProgramName(argv[0]);
     Py_Initialize();
-#ifdef MS_WINDOWS
+#ifdef MS_WINDOWS && !defined(__MINGW32__)
     PyWinFreeze_ExeInit();
 #endif
 
@@ -61,7 +61,7 @@
     if (inspect && isatty((int)fileno(stdin)))
         sts = PyRun_AnyFile(stdin, "<stdin>") != 0;
 
-#ifdef MS_WINDOWS
+#ifdef MS_WINDOWS && !defined(__MINGW32__)
     PyWinFreeze_ExeTerm();
 #endif
     Py_Finalize();
Only in misc/build/Python-2.7.14/Python: frozenmain.c.rej