Blame 0410-MINGW-build-extensions-with-GCC.patch

ddb6764
diff -rupN Python-2.7.13/Lib/distutils/command/build_ext.py Python-2.7.13-new/Lib/distutils/command/build_ext.py
ddb6764
--- Python-2.7.13/Lib/distutils/command/build_ext.py	2017-01-21 01:46:06.421608463 +0100
ddb6764
+++ Python-2.7.13-new/Lib/distutils/command/build_ext.py	2017-01-21 01:46:08.148590025 +0100
ddb6764
@@ -180,7 +180,7 @@ class build_ext (Command):
ddb6764
         # for extensions under windows use different directories
ddb6764
         # for Release and Debug builds.
ddb6764
         # also Python's library directory must be appended to library_dirs
ddb6764
-        if os.name == 'nt':
ddb6764
+        if os.name == 'nt' and not self.plat_name.startswith(('mingw')):
ddb6764
             # the 'libs' directory is for binary installs - we assume that
ddb6764
             # must be the *native* platform.  But we don't really support
ddb6764
             # cross-compiling via a binary install anyway, so we let it go.
ddb6764
@@ -700,6 +700,20 @@ class build_ext (Command):
ddb6764
         # pyconfig.h that MSVC groks.  The other Windows compilers all seem
ddb6764
         # to need it mentioned explicitly, though, so that's what we do.
ddb6764
         # Append '_d' to the python import library on debug builds.
ddb6764
+
ddb6764
+        # Use self.plat_name as it works even in case of
ddb6764
+        # cross-compilation (at least for mingw build).
ddb6764
+        if self.plat_name.startswith('mingw'):
ddb6764
+            from distutils import sysconfig
ddb6764
+            extra = []
ddb6764
+            for lib in (
ddb6764
+                sysconfig.get_config_var('BLDLIBRARY').split()
ddb6764
+                + sysconfig.get_config_var('SHLIBS').split()
ddb6764
+                ):
ddb6764
+                if lib.startswith('-l'):
ddb6764
+                    extra.append(lib[2:])
ddb6764
+            return ext.libraries + extra
ddb6764
+
ddb6764
         if sys.platform == "win32":
ddb6764
             from distutils.msvccompiler import MSVCCompiler
ddb6764
             if not isinstance(self.compiler, MSVCCompiler):
ddb6764
diff -rupN Python-2.7.13/Lib/distutils/util.py Python-2.7.13-new/Lib/distutils/util.py
ddb6764
--- Python-2.7.13/Lib/distutils/util.py	2016-12-17 21:05:06.000000000 +0100
ddb6764
+++ Python-2.7.13-new/Lib/distutils/util.py	2017-01-21 01:46:08.148590025 +0100
ddb6764
@@ -38,6 +38,8 @@ def get_platform ():
ddb6764
     For other non-POSIX platforms, currently just returns 'sys.platform'.
ddb6764
     """
ddb6764
     if os.name == 'nt':
ddb6764
+        if 'GCC' in sys.version:
ddb6764
+            return 'mingw'
ddb6764
         # sniff sys.version for architecture.
ddb6764
         prefix = " bit ("
ddb6764
         i = string.find(sys.version, prefix)
ddb6764
diff -rupN Python-2.7.13/Lib/sysconfig.py Python-2.7.13-new/Lib/sysconfig.py
ddb6764
--- Python-2.7.13/Lib/sysconfig.py	2017-01-21 01:46:04.068633585 +0100
ddb6764
+++ Python-2.7.13-new/Lib/sysconfig.py	2017-01-21 01:46:08.148590025 +0100
ddb6764
@@ -560,6 +560,8 @@ def get_platform():
ddb6764
     """
ddb6764
     import re
ddb6764
     if os.name == 'nt':
ddb6764
+        if 'GCC' in sys.version:
ddb6764
+            return 'mingw'
ddb6764
         # sniff sys.version for architecture.
ddb6764
         prefix = " bit ("
ddb6764
         i = sys.version.find(prefix)