|
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
|
@@ -110,41 +112,46 @@ def __init__(self, verbose=0, dry_run=0, force=0):
|
110 | 112 | "Compiling may fail because of undefined preprocessor macros."
|
111 | 113 | % details)
|
112 | 114 |
|
113 |
| - self.gcc_version, self.ld_version, self.dllwrap_version = \ |
114 |
| - get_versions() |
115 |
| - self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % |
116 |
| - (self.gcc_version, |
117 |
| - self.ld_version, |
118 |
| - self.dllwrap_version) ) |
119 |
| - |
120 |
| - # ld_version >= "2.10.90" and < "2.13" should also be able to use |
121 |
| - # gcc -mdll instead of dllwrap |
122 |
| - # Older dllwraps had own version numbers, newer ones use the |
123 |
| - # same as the rest of binutils ( also ld ) |
124 |
| - # dllwrap 2.10.90 is buggy |
125 |
| - if self.ld_version >= "2.10.90": |
126 |
| - self.linker_dll = "gcc" |
127 |
| - else: |
128 |
| - self.linker_dll = "dllwrap" |
| 115 | + self.cc = os.environ.get('CC', 'gcc') |
| 116 | + self.cxx = os.environ.get('CXX', 'g++') |
| 117 | + |
| 118 | + if ('gcc' in self.cc): # Start gcc workaround |
| 119 | + self.gcc_version, self.ld_version, self.dllwrap_version = \ |
| 120 | + get_versions() |
| 121 | + self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % |
| 122 | + (self.gcc_version, |
| 123 | + self.ld_version, |
| 124 | + self.dllwrap_version) ) |
| 125 | + |
| 126 | + # ld_version >= "2.10.90" and < "2.13" should also be able to use |
| 127 | + # gcc -mdll instead of dllwrap |
| 128 | + # Older dllwraps had own version numbers, newer ones use the |
| 129 | + # same as the rest of binutils ( also ld ) |
| 130 | + # dllwrap 2.10.90 is buggy |
| 131 | + if self.ld_version >= "2.10.90": |
| 132 | + self.linker_dll = self.cc |
| 133 | + else: |
| 134 | + self.linker_dll = "dllwrap" |
129 | 135 |
|
130 |
| - # ld_version >= "2.13" support -shared so use it instead of |
131 |
| - # -mdll -static |
132 |
| - if self.ld_version >= "2.13": |
| 136 | + # ld_version >= "2.13" support -shared so use it instead of |
| 137 | + # -mdll -static |
| 138 | + if self.ld_version >= "2.13": |
| 139 | + shared_option = "-shared" |
| 140 | + else: |
| 141 | + shared_option = "-mdll -static" |
| 142 | + else: # Assume linker is up to date |
| 143 | + self.linker_dll = self.cc |
133 | 144 | shared_option = "-shared"
|
134 |
| - else: |
135 |
| - shared_option = "-mdll -static" |
136 | 145 |
|
137 |
| - # Hard-code GCC because that's what this is all about. |
138 |
| - # XXX optimization, warnings etc. should be customizable. |
139 |
| - self.set_executables(compiler='gcc -mcygwin -O -Wall', |
140 |
| - compiler_so='gcc -mcygwin -mdll -O -Wall', |
141 |
| - compiler_cxx='g++ -mcygwin -O -Wall', |
142 |
| - linker_exe='gcc -mcygwin', |
| 146 | + self.set_executables(compiler='%s -mcygwin -O -Wall' % self.cc, |
| 147 | + compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc, |
| 148 | + compiler_cxx='%s -mcygwin -O -Wall' % self.cxx, |
| 149 | + linker_exe='%s -mcygwin' % self.cc, |
143 | 150 | linker_so=('%s -mcygwin %s' %
|
144 | 151 | (self.linker_dll, shared_option)))
|
145 | 152 |
|
146 | 153 | # cygwin and mingw32 need different sets of libraries
|
147 |
| - if self.gcc_version == "2.91.57": |
| 154 | + if ('gcc' in self.cc and self.gcc_version == "2.91.57"): |
148 | 155 | # cygwin shouldn't need msvcrt, but without the dlls will crash
|
149 | 156 | # (gcc version 2.91.57) -- perhaps something about initialization
|
150 | 157 | self.dll_libraries=["msvcrt"]
|
@@ -287,26 +294,26 @@ def __init__(self, verbose=0, dry_run=0, force=0):
|
287 | 294 |
|
288 | 295 | # ld_version >= "2.13" support -shared so use it instead of
|
289 | 296 | # -mdll -static
|
290 |
| - if self.ld_version >= "2.13": |
291 |
| - shared_option = "-shared" |
292 |
| - else: |
| 297 | + if ('gcc' in self.cc and self.ld_version < "2.13"): |
293 | 298 | shared_option = "-mdll -static"
|
| 299 | + else: |
| 300 | + shared_option = "-shared" |
294 | 301 |
|
295 | 302 | # A real mingw32 doesn't need to specify a different entry point,
|
296 | 303 | # but cygwin 2.91.57 in no-cygwin-mode needs it.
|
297 |
| - if self.gcc_version <= "2.91.57": |
| 304 | + if ('gcc' in self.cc and self.gcc_version <= "2.91.57"): |
298 | 305 | entry_point = '--entry _DllMain@12'
|
299 | 306 | else:
|
300 | 307 | entry_point = ''
|
301 | 308 |
|
302 |
| - if is_cygwingcc(): |
| 309 | + if is_cygwincc(self.cc): |
303 | 310 | raise CCompilerError(
|
304 | 311 | 'Cygwin gcc cannot be used with --compiler=mingw32')
|
305 | 312 |
|
306 |
| - self.set_executables(compiler='gcc -O2 -Wall', |
307 |
| - compiler_so='gcc -mdll -O2 -Wall', |
308 |
| - compiler_cxx='g++ -O2 -Wall', |
309 |
| - linker_exe='gcc', |
| 313 | + self.set_executables(compiler='%s -O2 -Wall' % self.cc, |
| 314 | + compiler_so='%s -mdll -O2 -Wall' % self.cc, |
| 315 | + compiler_cxx='%s -O2 -Wall' % self.cxx, |
| 316 | + linker_exe='%s' % self.cc, |
310 | 317 | linker_so='%s %s %s'
|
311 | 318 | % (self.linker_dll, shared_option,
|
312 | 319 | entry_point))
|
@@ -357,6 +364,10 @@ def check_config_h():
|
357 | 364 | if "GCC" in sys.version:
|
358 | 365 | return CONFIG_H_OK, "sys.version mentions 'GCC'"
|
359 | 366 |
|
| 367 | + # Clang would also work |
| 368 | + if "Clang" in sys.version: |
| 369 | + return CONFIG_H_OK, "sys.version mentions 'Clang'" |
| 370 | + |
360 | 371 | # let's see if __GNUC__ is mentioned in python.h
|
361 | 372 | fn = sysconfig.get_config_h_filename()
|
362 | 373 | try:
|
@@ -413,7 +424,7 @@ def get_versions():
|
413 | 424 | commands = [gcc+' -dumpversion', ld+' -v', dllwrap+' --version']
|
414 | 425 | return tuple([_find_exe_version(cmd) for cmd in commands])
|
415 | 426 |
|
416 |
| -def is_cygwingcc(): |
417 |
| - '''Try to determine if the gcc that would be used is from cygwin.''' |
418 |
| - out_string = check_output(['gcc', '-dumpmachine']) |
| 427 | +def is_cygwincc(cc): |
| 428 | + '''Try to determine if the compiler that would be used is from cygwin.''' |
| 429 | + out_string = check_output([cc, '-dumpmachine']) |
419 | 430 | return out_string.strip().endswith(b'cygwin')
|
0 commit comments