From 92bdafeff51231d4252c384ef288ecab1e5c1a5b Mon Sep 17 00:00:00 2001 From: Roumen Petrov Date: Sat, 2 Mar 2013 22:27:02 +0200 Subject: [PATCH 15/24] MINGW: build extensions with GCC --- Lib/distutils/command/build_ext.py | 16 +++++++++++++++- Lib/distutils/util.py | 2 ++ Lib/sysconfig.py | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py index 5ae4f77..431d414 100644 --- a/Lib/distutils/command/build_ext.py +++ b/Lib/distutils/command/build_ext.py @@ -190,7 +190,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. @@ -691,6 +691,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 --git a/Lib/distutils/util.py b/Lib/distutils/util.py index efb3834..e5af80c 100644 --- a/Lib/distutils/util.py +++ b/Lib/distutils/util.py @@ -40,6 +40,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 = sys.version.find(prefix) diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py index ee38a20..8720e50 100644 --- a/Lib/sysconfig.py +++ b/Lib/sysconfig.py @@ -607,6 +607,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 = sys.version.find(prefix) -- 1.7.12.1