58 lines
2.5 KiB
Diff
58 lines
2.5 KiB
Diff
From fc151450deaf55f69d559e64b572446da8dcdbc8 Mon Sep 17 00:00:00 2001
|
|
From: Christoph Reiter <reiter.christoph@gmail.com>
|
|
Date: Tue, 21 Sep 2021 20:52:22 +0200
|
|
Subject: [PATCH 070/N] distutils: MINGW build extensions with GCC
|
|
|
|
---
|
|
Lib/distutils/command/build_ext.py | 16 +++++++++++++++-
|
|
Lib/distutils/util.py | 2 ++
|
|
2 files changed, 17 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
|
|
index f287b34..1654a94 100644
|
|
--- a/Lib/distutils/command/build_ext.py
|
|
+++ b/Lib/distutils/command/build_ext.py
|
|
@@ -186,7 +186,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.
|
|
@@ -712,6 +712,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 2ce5c5b..fb7d1ad 100644
|
|
--- a/Lib/distutils/util.py
|
|
+++ b/Lib/distutils/util.py
|
|
@@ -37,6 +37,8 @@ def get_host_platform():
|
|
|
|
"""
|
|
if os.name == 'nt':
|
|
+ if 'GCC' in sys.version:
|
|
+ return 'mingw'
|
|
if 'amd64' in sys.version.lower():
|
|
return 'win-amd64'
|
|
if '(arm)' in sys.version.lower():
|