|
44 | 44 | # (ld supports -shared)
|
45 | 45 | # * mingw gcc 3.2/ld 2.13 works
|
46 | 46 | # (ld supports -shared)
|
| 47 | +# * llvm-mingw with Clang 11 works |
| 48 | +# (lld supports -shared) |
47 | 49 |
|
48 | 50 | import os
|
49 | 51 | import sys
|
@@ -109,41 +111,46 @@ def __init__(self, verbose=0, dry_run=0, force=0):
|
109 | 111 | "Compiling may fail because of undefined preprocessor macros."
|
110 | 112 | % details)
|
111 | 113 |
|
112 |
| - self.gcc_version, self.ld_version, self.dllwrap_version = \ |
113 |
| - get_versions() |
114 |
| - self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % |
115 |
| - (self.gcc_version, |
116 |
| - self.ld_version, |
117 |
| - self.dllwrap_version) ) |
118 |
| - |
119 |
| - # ld_version >= "2.10.90" and < "2.13" should also be able to use |
120 |
| - # gcc -mdll instead of dllwrap |
121 |
| - # Older dllwraps had own version numbers, newer ones use the |
122 |
| - # same as the rest of binutils ( also ld ) |
123 |
| - # dllwrap 2.10.90 is buggy |
124 |
| - if self.ld_version >= "2.10.90": |
125 |
| - self.linker_dll = "gcc" |
126 |
| - else: |
127 |
| - self.linker_dll = "dllwrap" |
| 114 | + self.cc = os.environ.get('CC', 'gcc') |
| 115 | + self.cxx = os.environ.get('CXX', 'g++') |
| 116 | + |
| 117 | + if ('gcc' in self.cc): # Start gcc workaround |
| 118 | + self.gcc_version, self.ld_version, self.dllwrap_version = \ |
| 119 | + get_versions() |
| 120 | + self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % |
| 121 | + (self.gcc_version, |
| 122 | + self.ld_version, |
| 123 | + self.dllwrap_version) ) |
| 124 | + |
| 125 | + # ld_version >= "2.10.90" and < "2.13" should also be able to use |
| 126 | + # gcc -mdll instead of dllwrap |
| 127 | + # Older dllwraps had own version numbers, newer ones use the |
| 128 | + # same as the rest of binutils ( also ld ) |
| 129 | + # dllwrap 2.10.90 is buggy |
| 130 | + if self.ld_version >= "2.10.90": |
| 131 | + self.linker_dll = self.cc |
| 132 | + else: |
| 133 | + self.linker_dll = "dllwrap" |
128 | 134 |
|
129 |
| - # ld_version >= "2.13" support -shared so use it instead of |
130 |
| - # -mdll -static |
131 |
| - if self.ld_version >= "2.13": |
| 135 | + # ld_version >= "2.13" support -shared so use it instead of |
| 136 | + # -mdll -static |
| 137 | + if self.ld_version >= "2.13": |
| 138 | + shared_option = "-shared" |
| 139 | + else: |
| 140 | + shared_option = "-mdll -static" |
| 141 | + else: # Assume linker is up to date |
| 142 | + self.linker_dll = self.cc |
132 | 143 | shared_option = "-shared"
|
133 |
| - else: |
134 |
| - shared_option = "-mdll -static" |
135 | 144 |
|
136 |
| - # Hard-code GCC because that's what this is all about. |
137 |
| - # XXX optimization, warnings etc. should be customizable. |
138 |
| - self.set_executables(compiler='gcc -mcygwin -O -Wall', |
139 |
| - compiler_so='gcc -mcygwin -mdll -O -Wall', |
140 |
| - compiler_cxx='g++ -mcygwin -O -Wall', |
141 |
| - linker_exe='gcc -mcygwin', |
| 145 | + self.set_executables(compiler='%s -mcygwin -O -Wall' % self.cc, |
| 146 | + compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc, |
| 147 | + compiler_cxx='%s -mcygwin -O -Wall' % self.cxx, |
| 148 | + linker_exe='%s -mcygwin' % self.cc, |
142 | 149 | linker_so=('%s -mcygwin %s' %
|
143 | 150 | (self.linker_dll, shared_option)))
|
144 | 151 |
|
145 | 152 | # cygwin and mingw32 need different sets of libraries
|
146 |
| - if self.gcc_version == "2.91.57": |
| 153 | + if ('gcc' in self.cc and self.gcc_version == "2.91.57"): |
147 | 154 | # cygwin shouldn't need msvcrt, but without the dlls will crash
|
148 | 155 | # (gcc version 2.91.57) -- perhaps something about initialization
|
149 | 156 | self.dll_libraries=["msvcrt"]
|
@@ -281,26 +288,26 @@ def __init__(self, verbose=0, dry_run=0, force=0):
|
281 | 288 |
|
282 | 289 | # ld_version >= "2.13" support -shared so use it instead of
|
283 | 290 | # -mdll -static
|
284 |
| - if self.ld_version >= "2.13": |
285 |
| - shared_option = "-shared" |
286 |
| - else: |
| 291 | + if ('gcc' in self.cc and self.ld_version < "2.13"): |
287 | 292 | shared_option = "-mdll -static"
|
| 293 | + else: |
| 294 | + shared_option = "-shared" |
288 | 295 |
|
289 | 296 | # A real mingw32 doesn't need to specify a different entry point,
|
290 | 297 | # but cygwin 2.91.57 in no-cygwin-mode needs it.
|
291 |
| - if self.gcc_version <= "2.91.57": |
| 298 | + if ('gcc' in self.cc and self.gcc_version <= "2.91.57"): |
292 | 299 | entry_point = '--entry _DllMain@12'
|
293 | 300 | else:
|
294 | 301 | entry_point = ''
|
295 | 302 |
|
296 |
| - if is_cygwingcc(): |
| 303 | + if is_cygwincc(self.cc): |
297 | 304 | raise CCompilerError(
|
298 | 305 | 'Cygwin gcc cannot be used with --compiler=mingw32')
|
299 | 306 |
|
300 |
| - self.set_executables(compiler='gcc -O -Wall', |
301 |
| - compiler_so='gcc -mdll -O -Wall', |
302 |
| - compiler_cxx='g++ -O -Wall', |
303 |
| - linker_exe='gcc', |
| 307 | + self.set_executables(compiler='%s -O -Wall' % self.cc, |
| 308 | + compiler_so='%s -mdll -O -Wall' % self.cc, |
| 309 | + compiler_cxx='%s -O -Wall' % self.cxx, |
| 310 | + linker_exe='%s' % self.cc, |
304 | 311 | linker_so='%s %s %s'
|
305 | 312 | % (self.linker_dll, shared_option,
|
306 | 313 | entry_point))
|
@@ -351,6 +358,10 @@ def check_config_h():
|
351 | 358 | if "GCC" in sys.version:
|
352 | 359 | return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
353 | 360 |
|
| 361 | + # Clang would also work |
| 362 | + if "Clang" in sys.version: |
| 363 | + return CONFIG_H_OK, "sys.version mentions 'Clang'" |
| 364 | + |
354 | 365 | # let's see if __GNUC__ is mentioned in python.h
|
355 | 366 | fn = sysconfig.get_config_h_filename()
|
356 | 367 | try:
|
@@ -397,7 +408,7 @@ def get_versions():
|
397 | 408 | commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version']
|
398 | 409 | return tuple([_find_exe_version(cmd) for cmd in commands])
|
399 | 410 |
|
400 |
| -def is_cygwingcc(): |
401 |
| - '''Try to determine if the gcc that would be used is from cygwin.''' |
402 |
| - out_string = check_output(['gcc', '-dumpmachine']) |
| 411 | +def is_cygwincc(cc): |
| 412 | + '''Try to determine if the compiler that would be used is from cygwin.''' |
| 413 | + out_string = check_output([cc, '-dumpmachine']) |
403 | 414 | return out_string.strip().endswith(b'cygwin')
|
0 commit comments