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