50
50
import os
51
51
import sys
52
52
import copy
53
- import re
54
53
55
54
from distutils .unixccompiler import UnixCCompiler
56
55
from distutils .file_util import write_file
57
56
from distutils .errors import (DistutilsExecError , CCompilerError ,
58
57
CompileError , UnknownFileError )
59
- from distutils .version import LooseVersion
60
58
from distutils .spawn import find_executable
61
- from subprocess import Popen , PIPE , check_output
59
+ from subprocess import Popen , check_output
62
60
63
61
def get_msvcr ():
64
62
"""Include the appropriate MSVC runtime library if Python was built
@@ -115,33 +113,8 @@ def __init__(self, verbose=0, dry_run=0, force=0):
115
113
self .cc = os .environ .get ('CC' , 'gcc' )
116
114
self .cxx = os .environ .get ('CXX' , 'g++' )
117
115
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"
135
-
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
144
- shared_option = "-shared"
116
+ self .linker_dll = self .cc
117
+ shared_option = "-shared"
145
118
146
119
self .set_executables (compiler = '%s -mcygwin -O -Wall' % self .cc ,
147
120
compiler_so = '%s -mcygwin -mdll -O -Wall' % self .cc ,
@@ -150,17 +123,9 @@ def __init__(self, verbose=0, dry_run=0, force=0):
150
123
linker_so = ('%s -mcygwin %s' %
151
124
(self .linker_dll , shared_option )))
152
125
153
- # cygwin and mingw32 need different sets of libraries
154
- if ('gcc' in self .cc and self .gcc_version == "2.91.57" ):
155
- # cygwin shouldn't need msvcrt, but without the dlls will crash
156
- # (gcc version 2.91.57) -- perhaps something about initialization
157
- self .dll_libraries = ["msvcrt" ]
158
- self .warn (
159
- "Consider upgrading to a newer version of gcc" )
160
- else :
161
- # Include the appropriate MSVC runtime library if Python was built
162
- # with MSVC 7.0 or later.
163
- self .dll_libraries = get_msvcr ()
126
+ # Include the appropriate MSVC runtime library if Python was built
127
+ # with MSVC 7.0 or later.
128
+ self .dll_libraries = get_msvcr ()
164
129
165
130
def _compile (self , obj , src , ext , cc_args , extra_postargs , pp_opts ):
166
131
"""Compiles the source by spawning GCC and windres if needed."""
@@ -244,24 +209,17 @@ def link(self, target_desc, objects, output_filename, output_dir=None,
244
209
245
210
# next add options for def-file and to creating import libraries
246
211
247
- # dllwrap uses different options than gcc/ld
248
- if self .linker_dll == "dllwrap" :
249
- extra_preargs .extend (["--output-lib" , lib_file ])
250
- # for dllwrap we have to use a special option
251
- extra_preargs .extend (["--def" , def_file ])
252
- # we use gcc/ld here and can be sure ld is >= 2.9.10
253
- else :
254
- # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
255
- #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
256
- # for gcc/ld the def-file is specified as any object files
257
- objects .append (def_file )
212
+ # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
213
+ #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
214
+ # for gcc/ld the def-file is specified as any object files
215
+ objects .append (def_file )
258
216
259
217
#end: if ((export_symbols is not None) and
260
218
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
261
219
262
220
# who wants symbols and a many times larger output file
263
221
# should explicitly switch the debug mode on
264
- # otherwise we let dllwrap/ ld strip the output file
222
+ # otherwise we let ld strip the output file
265
223
# (On my machine: 10KiB < stripped_file < ??100KiB
266
224
# unstripped_file = stripped_file + XXX KiB
267
225
# ( XXX=254 for a typical python extension))
@@ -314,19 +272,7 @@ def __init__(self, verbose=0, dry_run=0, force=0):
314
272
315
273
CygwinCCompiler .__init__ (self , verbose , dry_run , force )
316
274
317
- # ld_version >= "2.13" support -shared so use it instead of
318
- # -mdll -static
319
- if ('gcc' in self .cc and self .ld_version < "2.13" ):
320
- shared_option = "-mdll -static"
321
- else :
322
- shared_option = "-shared"
323
-
324
- # A real mingw32 doesn't need to specify a different entry point,
325
- # but cygwin 2.91.57 in no-cygwin-mode needs it.
326
- if ('gcc' in self .cc and self .gcc_version <= "2.91.57" ):
327
- entry_point = '--entry _DllMain@12'
328
- else :
329
- entry_point = ''
275
+ shared_option = "-shared"
330
276
331
277
if is_cygwincc (self .cc ):
332
278
raise CCompilerError (
@@ -336,9 +282,8 @@ def __init__(self, verbose=0, dry_run=0, force=0):
336
282
compiler_so = '%s -mdll -O2 -Wall' % self .cc ,
337
283
compiler_cxx = '%s -O2 -Wall' % self .cxx ,
338
284
linker_exe = '%s' % self .cc ,
339
- linker_so = '%s %s %s'
340
- % (self .linker_dll , shared_option ,
341
- entry_point ))
285
+ linker_so = '%s %s'
286
+ % (self .linker_dll , shared_option ))
342
287
# Maybe we should also append -mthreads, but then the finished
343
288
# dlls need another dll (mingwm10.dll see Mingw32 docs)
344
289
# (-mthreads: Support thread-safe exception handling on `Mingw32')
@@ -405,46 +350,6 @@ def check_config_h():
405
350
return (CONFIG_H_UNCERTAIN ,
406
351
"couldn't read '%s': %s" % (fn , exc .strerror ))
407
352
408
- RE_VERSION = re .compile (br'[\D\s]*(\d+\.\d+(\.\d+)*)[\D\s]*' )
409
-
410
- def _find_exe_version (cmd ):
411
- """Find the version of an executable by running `cmd` in the shell.
412
-
413
- If the command is not found, or the output does not match
414
- `RE_VERSION`, returns None.
415
- """
416
- executable = cmd .split ()[0 ]
417
- if find_executable (executable ) is None :
418
- return None
419
- from subprocess import Popen , PIPE
420
- out = Popen (cmd , shell = True , stdout = PIPE ).stdout
421
- try :
422
- out_string = out .read ()
423
- finally :
424
- out .close ()
425
- result = RE_VERSION .search (out_string )
426
- if result is None :
427
- return None
428
- # LooseVersion works with strings
429
- # so we need to decode our bytes
430
- return LooseVersion (result .group (1 ).decode ())
431
-
432
- def get_versions ():
433
- """ Try to find out the versions of gcc, ld and dllwrap.
434
-
435
- If not possible it returns None for it.
436
- """
437
- gcc = os .environ .get ('CC' ) or 'gcc'
438
- ld = 'ld'
439
- out = Popen (gcc + ' --print-prog-name ld' , shell = True , stdout = PIPE ).stdout
440
- try :
441
- ld = test = str (out .read (),encoding = 'utf-8' ).strip ()
442
- finally :
443
- out .close ()
444
- dllwrap = os .environ .get ('DLLWRAP' ) or 'dllwrap'
445
- # MinGW64 doesn't have i686-w64-mingw32-ld, so instead we ask gcc.
446
- commands = [gcc + ' -dumpversion' , ld + ' -v' , dllwrap + ' --version' ]
447
- return tuple ([_find_exe_version (cmd ) for cmd in commands ])
448
353
449
354
def is_cygwincc (cc ):
450
355
'''Try to determine if the compiler that would be used is from cygwin.'''
0 commit comments