Skip to content

Commit c75c81c

Browse files
Roumen Petrovmingwandroid
authored andcommitted
MINGW: build extensions with GCC
1 parent 1a28498 commit c75c81c

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

Lib/distutils/command/build_ext.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def finalize_options(self):
181181
# for extensions under windows use different directories
182182
# for Release and Debug builds.
183183
# also Python's library directory must be appended to library_dirs
184-
if os.name == 'nt':
184+
if os.name == 'nt' and not self.plat_name.startswith(('mingw')):
185185
# the 'libs' directory is for binary installs - we assume that
186186
# must be the *native* platform. But we don't really support
187187
# cross-compiling via a binary install anyway, so we let it go.
@@ -682,6 +682,20 @@ def get_libraries(self, ext):
682682
# pyconfig.h that MSVC groks. The other Windows compilers all seem
683683
# to need it mentioned explicitly, though, so that's what we do.
684684
# Append '_d' to the python import library on debug builds.
685+
686+
# Use self.plat_name as it works even in case of
687+
# cross-compilation (at least for mingw build).
688+
if self.plat_name.startswith('mingw'):
689+
from distutils import sysconfig
690+
extra = []
691+
for lib in (
692+
sysconfig.get_config_var('BLDLIBRARY').split()
693+
+ sysconfig.get_config_var('SHLIBS').split()
694+
):
695+
if lib.startswith('-l'):
696+
extra.append(lib[2:])
697+
return ext.libraries + extra
698+
685699
if sys.platform == "win32":
686700
from distutils.msvccompiler import MSVCCompiler
687701
if not isinstance(self.compiler, MSVCCompiler):

Lib/distutils/util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ def get_platform ():
4040
For other non-POSIX platforms, currently just returns 'sys.platform'.
4141
"""
4242
if os.name == 'nt':
43+
if 'GCC' in sys.version:
44+
return 'mingw'
4345
# sniff sys.version for architecture.
4446
prefix = " bit ("
4547
i = sys.version.find(prefix)

Lib/sysconfig.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,8 @@ def get_platform():
629629
For other non-POSIX platforms, currently just returns 'sys.platform'.
630630
"""
631631
if os.name == 'nt':
632+
if 'GCC' in sys.version:
633+
return 'mingw'
632634
# sniff sys.version for architecture.
633635
prefix = " bit ("
634636
i = sys.version.find(prefix)

0 commit comments

Comments
 (0)