blob: 3fb5bc9005547884240e3b22c17fd155b71b44a0 [file] [log] [blame]
Greg Ward7c6395a2000-06-21 03:33:03 +00001"""distutils.cygwinccompiler
2
Greg Wardf34506a2000-06-29 22:57:55 +00003Provides the CygwinCCompiler class, a subclass of UnixCCompiler that
4handles the Cygwin port of the GNU C compiler to Windows. It also contains
5the Mingw32CCompiler class which handles the mingw32 port of GCC (same as
6cygwin in no-cygwin mode).
Greg Ward7c6395a2000-06-21 03:33:03 +00007"""
8
Greg Wardbf5c7092000-08-02 01:31:56 +00009# problems:
10#
11# * if you use a msvc compiled python version (1.5.2)
12# 1. you have to insert a __GNUC__ section in its config.h
13# 2. you have to generate a import library for its dll
14# - create a def-file for python??.dll
15# - create a import library using
16# dlltool --dllname python15.dll --def python15.def \
17# --output-lib libpython15.a
18#
19# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
20#
Fred Drakeb94b8492001-12-06 20:51:35 +000021# * We put export_symbols in a def-file, and don't use
Greg Wardbf5c7092000-08-02 01:31:56 +000022# --export-all-symbols because it doesn't worked reliable in some
23# tested configurations. And because other windows compilers also
24# need their symbols specified this no serious problem.
25#
26# tested configurations:
Fred Drakeb94b8492001-12-06 20:51:35 +000027#
28# * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works
Greg Wardbf5c7092000-08-02 01:31:56 +000029# (after patching python's config.h and for C++ some other include files)
30# see also http://starship.python.net/crew/kernr/mingw32/Notes.html
Fred Drakeb94b8492001-12-06 20:51:35 +000031# * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works
32# (ld doesn't support -shared, so we use dllwrap)
Greg Wardbf5c7092000-08-02 01:31:56 +000033# * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now
34# - its dllwrap doesn't work, there is a bug in binutils 2.10.90
Greg Ward7483d682000-09-01 01:24:31 +000035# see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html
Fred Drakeb94b8492001-12-06 20:51:35 +000036# - using gcc -mdll instead dllwrap doesn't work without -static because
Greg Wardbf5c7092000-08-02 01:31:56 +000037# it tries to link against dlls instead their import libraries. (If
38# it finds the dll first.)
Fred Drakeb94b8492001-12-06 20:51:35 +000039# By specifying -static we force ld to link against the import libraries,
40# this is windows standard and there are normally not the necessary symbols
Greg Wardbf5c7092000-08-02 01:31:56 +000041# in the dlls.
Fred Drakeb94b8492001-12-06 20:51:35 +000042# *** only the version of June 2000 shows these problems
Greg Wardbf5c7092000-08-02 01:31:56 +000043
Greg Ward7c6395a2000-06-21 03:33:03 +000044# created 2000/05/05, Rene Liebscher
45
46__revision__ = "$Id$"
47
Greg Wardb1dceae2000-08-13 00:43:56 +000048import os,sys,copy
Greg Ward42406482000-09-27 02:08:14 +000049from distutils.ccompiler import gen_preprocess_options, gen_lib_options
Greg Ward7c6395a2000-06-21 03:33:03 +000050from distutils.unixccompiler import UnixCCompiler
Greg Wardbf5c7092000-08-02 01:31:56 +000051from distutils.file_util import write_file
Greg Ward42406482000-09-27 02:08:14 +000052from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000053from distutils import log
Greg Ward7c6395a2000-06-21 03:33:03 +000054
Greg Ward7c6395a2000-06-21 03:33:03 +000055class CygwinCCompiler (UnixCCompiler):
56
57 compiler_type = 'cygwin'
Greg Wardb1dceae2000-08-13 00:43:56 +000058 obj_extension = ".o"
59 static_lib_extension = ".a"
60 shared_lib_extension = ".dll"
61 static_lib_format = "lib%s%s"
62 shared_lib_format = "%s%s"
63 exe_extension = ".exe"
Fred Drakeb94b8492001-12-06 20:51:35 +000064
Greg Ward7c6395a2000-06-21 03:33:03 +000065 def __init__ (self,
66 verbose=0,
67 dry_run=0,
68 force=0):
69
70 UnixCCompiler.__init__ (self, verbose, dry_run, force)
71
Greg Warde8e9d112000-08-13 01:18:55 +000072 (status, details) = check_config_h()
73 self.debug_print("Python's GCC status: %s (details: %s)" %
74 (status, details))
75 if status is not CONFIG_H_OK:
Greg Wardbf5c7092000-08-02 01:31:56 +000076 self.warn(
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +000077 "Python's pyconfig.h doesn't seem to support your compiler. " +
Greg Warde8e9d112000-08-13 01:18:55 +000078 ("Reason: %s." % details) +
Greg Wardbf5c7092000-08-02 01:31:56 +000079 "Compiling may fail because of undefined preprocessor macros.")
Fred Drakeb94b8492001-12-06 20:51:35 +000080
Greg Wardbf5c7092000-08-02 01:31:56 +000081 (self.gcc_version, self.ld_version, self.dllwrap_version) = \
82 get_versions()
Greg Wardb1dceae2000-08-13 00:43:56 +000083 self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
Fred Drakeb94b8492001-12-06 20:51:35 +000084 (self.gcc_version,
85 self.ld_version,
Greg Wardbf5c7092000-08-02 01:31:56 +000086 self.dllwrap_version) )
87
Fred Drakeb94b8492001-12-06 20:51:35 +000088 # ld_version >= "2.10.90" should also be able to use
Greg Wardbf5c7092000-08-02 01:31:56 +000089 # gcc -mdll instead of dllwrap
Fred Drakeb94b8492001-12-06 20:51:35 +000090 # Older dllwraps had own version numbers, newer ones use the
Greg Wardbf5c7092000-08-02 01:31:56 +000091 # same as the rest of binutils ( also ld )
92 # dllwrap 2.10.90 is buggy
Fred Drakeb94b8492001-12-06 20:51:35 +000093 if self.ld_version >= "2.10.90":
Greg Ward42406482000-09-27 02:08:14 +000094 self.linker_dll = "gcc"
Greg Wardbf5c7092000-08-02 01:31:56 +000095 else:
Greg Ward42406482000-09-27 02:08:14 +000096 self.linker_dll = "dllwrap"
Greg Wardbf5c7092000-08-02 01:31:56 +000097
Greg Wardf34506a2000-06-29 22:57:55 +000098 # Hard-code GCC because that's what this is all about.
99 # XXX optimization, warnings etc. should be customizable.
Greg Wardbf5c7092000-08-02 01:31:56 +0000100 self.set_executables(compiler='gcc -mcygwin -O -Wall',
101 compiler_so='gcc -mcygwin -mdll -O -Wall',
102 linker_exe='gcc -mcygwin',
103 linker_so=('%s -mcygwin -mdll -static' %
Greg Ward42406482000-09-27 02:08:14 +0000104 self.linker_dll))
Greg Ward7c6395a2000-06-21 03:33:03 +0000105
Fred Drakeb94b8492001-12-06 20:51:35 +0000106 # cygwin and mingw32 need different sets of libraries
Greg Wardbf5c7092000-08-02 01:31:56 +0000107 if self.gcc_version == "2.91.57":
108 # cygwin shouldn't need msvcrt, but without the dlls will crash
109 # (gcc version 2.91.57) -- perhaps something about initialization
110 self.dll_libraries=["msvcrt"]
Fred Drakeb94b8492001-12-06 20:51:35 +0000111 self.warn(
Greg Wardbf5c7092000-08-02 01:31:56 +0000112 "Consider upgrading to a newer version of gcc")
113 else:
114 self.dll_libraries=[]
Fred Drakeb94b8492001-12-06 20:51:35 +0000115
Greg Ward7c6395a2000-06-21 03:33:03 +0000116 # __init__ ()
117
Greg Ward42406482000-09-27 02:08:14 +0000118 # not much different of the compile method in UnixCCompiler,
119 # but we have to insert some lines in the middle of it, so
120 # we put here a adapted version of it.
Fred Drakeb94b8492001-12-06 20:51:35 +0000121 # (If we would call compile() in the base class, it would do some
Greg Ward42406482000-09-27 02:08:14 +0000122 # initializations a second time, this is why all is done here.)
123 def compile (self,
124 sources,
125 output_dir=None,
126 macros=None,
127 include_dirs=None,
128 debug=0,
129 extra_preargs=None,
130 extra_postargs=None):
131
132 (output_dir, macros, include_dirs) = \
133 self._fix_compile_args (output_dir, macros, include_dirs)
134 (objects, skip_sources) = self._prep_compile (sources, output_dir)
135
136 # Figure out the options for the compiler command line.
137 pp_opts = gen_preprocess_options (macros, include_dirs)
138 cc_args = pp_opts + ['-c']
139 if debug:
140 cc_args[:0] = ['-g']
141 if extra_preargs:
142 cc_args[:0] = extra_preargs
143 if extra_postargs is None:
144 extra_postargs = []
145
146 # Compile all source files that weren't eliminated by
Fred Drakeb94b8492001-12-06 20:51:35 +0000147 # '_prep_compile()'.
Greg Ward42406482000-09-27 02:08:14 +0000148 for i in range (len (sources)):
149 src = sources[i] ; obj = objects[i]
150 ext = (os.path.splitext (src))[1]
151 if skip_sources[src]:
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +0000152 log.debug("skipping %s (%s up-to-date)", src, obj)
Greg Ward42406482000-09-27 02:08:14 +0000153 else:
154 self.mkpath (os.path.dirname (obj))
155 if ext == '.rc' or ext == '.res':
156 # gcc needs '.res' and '.rc' compiled to object files !!!
157 try:
158 self.spawn (["windres","-i",src,"-o",obj])
159 except DistutilsExecError, msg:
160 raise CompileError, msg
Fred Drakeb94b8492001-12-06 20:51:35 +0000161 else: # for other files use the C-compiler
Greg Ward42406482000-09-27 02:08:14 +0000162 try:
163 self.spawn (self.compiler_so + cc_args +
164 [src, '-o', obj] +
165 extra_postargs)
166 except DistutilsExecError, msg:
167 raise CompileError, msg
168
169 # Return *all* object filenames, not just the ones we just built.
170 return objects
171
172 # compile ()
173
174
175 def link (self,
176 target_desc,
177 objects,
178 output_filename,
179 output_dir=None,
180 libraries=None,
181 library_dirs=None,
182 runtime_library_dirs=None,
183 export_symbols=None,
184 debug=0,
185 extra_preargs=None,
186 extra_postargs=None,
187 build_temp=None):
Fred Drakeb94b8492001-12-06 20:51:35 +0000188
Greg Wardb1dceae2000-08-13 00:43:56 +0000189 # use separate copies, so we can modify the lists
190 extra_preargs = copy.copy(extra_preargs or [])
191 libraries = copy.copy(libraries or [])
Greg Ward42406482000-09-27 02:08:14 +0000192 objects = copy.copy(objects or [])
Fred Drakeb94b8492001-12-06 20:51:35 +0000193
Greg Wardbf5c7092000-08-02 01:31:56 +0000194 # Additional libraries
Greg Wardf34506a2000-06-29 22:57:55 +0000195 libraries.extend(self.dll_libraries)
Greg Wardbf5c7092000-08-02 01:31:56 +0000196
Greg Ward42406482000-09-27 02:08:14 +0000197 # handle export symbols by creating a def-file
198 # with executables this only works with gcc/ld as linker
199 if ((export_symbols is not None) and
200 (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
201 # (The linker doesn't do anything if output is up-to-date.
202 # So it would probably better to check if we really need this,
Fred Drakeb94b8492001-12-06 20:51:35 +0000203 # but for this we had to insert some unchanged parts of
204 # UnixCCompiler, and this is not what we want.)
Greg Ward42406482000-09-27 02:08:14 +0000205
Fred Drakeb94b8492001-12-06 20:51:35 +0000206 # we want to put some files in the same directory as the
Greg Ward42406482000-09-27 02:08:14 +0000207 # object files are, build_temp doesn't help much
208 # where are the object files
209 temp_dir = os.path.dirname(objects[0])
210 # name of dll to give the helper files the same base name
211 (dll_name, dll_extension) = os.path.splitext(
212 os.path.basename(output_filename))
213
214 # generate the filenames for these files
Greg Wardbf5c7092000-08-02 01:31:56 +0000215 def_file = os.path.join(temp_dir, dll_name + ".def")
Greg Ward42406482000-09-27 02:08:14 +0000216 exp_file = os.path.join(temp_dir, dll_name + ".exp")
217 lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
Fred Drakeb94b8492001-12-06 20:51:35 +0000218
Greg Ward42406482000-09-27 02:08:14 +0000219 # Generate .def file
Greg Wardbf5c7092000-08-02 01:31:56 +0000220 contents = [
221 "LIBRARY %s" % os.path.basename(output_filename),
222 "EXPORTS"]
Greg Ward7c6395a2000-06-21 03:33:03 +0000223 for sym in export_symbols:
Greg Wardbf5c7092000-08-02 01:31:56 +0000224 contents.append(sym)
225 self.execute(write_file, (def_file, contents),
226 "writing %s" % def_file)
227
Greg Ward42406482000-09-27 02:08:14 +0000228 # next add options for def-file and to creating import libraries
229
230 # dllwrap uses different options than gcc/ld
231 if self.linker_dll == "dllwrap":
232 extra_preargs.extend([#"--output-exp",exp_file,
233 "--output-lib",lib_file,
234 ])
Greg Wardbf5c7092000-08-02 01:31:56 +0000235 # for dllwrap we have to use a special option
Greg Ward42406482000-09-27 02:08:14 +0000236 extra_preargs.extend(["--def", def_file])
237 # we use gcc/ld here and can be sure ld is >= 2.9.10
238 else:
239 # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
240 #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
Fred Drakeb94b8492001-12-06 20:51:35 +0000241 # for gcc/ld the def-file is specified as any other object files
Greg Ward42406482000-09-27 02:08:14 +0000242 objects.append(def_file)
243
244 #end: if ((export_symbols is not None) and
Fred Drake132dce22000-12-12 23:11:42 +0000245 # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
Fred Drakeb94b8492001-12-06 20:51:35 +0000246
Greg Wardf34506a2000-06-29 22:57:55 +0000247 # who wants symbols and a many times larger output file
Fred Drakeb94b8492001-12-06 20:51:35 +0000248 # should explicitly switch the debug mode on
Greg Wardbf5c7092000-08-02 01:31:56 +0000249 # otherwise we let dllwrap/ld strip the output file
Fred Drakeb94b8492001-12-06 20:51:35 +0000250 # (On my machine: 10KB < stripped_file < ??100KB
Greg Ward42406482000-09-27 02:08:14 +0000251 # unstripped_file = stripped_file + XXX KB
Fred Drakeb94b8492001-12-06 20:51:35 +0000252 # ( XXX=254 for a typical python extension))
253 if not debug:
254 extra_preargs.append("-s")
255
Greg Ward42406482000-09-27 02:08:14 +0000256 UnixCCompiler.link(self,
257 target_desc,
258 objects,
259 output_filename,
260 output_dir,
261 libraries,
262 library_dirs,
263 runtime_library_dirs,
264 None, # export_symbols, we do this in our def-file
265 debug,
266 extra_preargs,
267 extra_postargs,
268 build_temp)
Fred Drakeb94b8492001-12-06 20:51:35 +0000269
Greg Ward42406482000-09-27 02:08:14 +0000270 # link ()
271
272 # -- Miscellaneous methods -----------------------------------------
273
274 # overwrite the one from CCompiler to support rc and res-files
275 def object_filenames (self,
276 source_filenames,
277 strip_dir=0,
278 output_dir=''):
279 if output_dir is None: output_dir = ''
280 obj_names = []
281 for src_name in source_filenames:
282 # use normcase to make sure '.rc' is really '.rc' and not '.RC'
283 (base, ext) = os.path.splitext (os.path.normcase(src_name))
284 if ext not in (self.src_extensions + ['.rc','.res']):
285 raise UnknownFileError, \
286 "unknown file type '%s' (from '%s')" % \
287 (ext, src_name)
288 if strip_dir:
289 base = os.path.basename (base)
290 if ext == '.res' or ext == '.rc':
291 # these need to be compiled to object files
Fred Drakeb94b8492001-12-06 20:51:35 +0000292 obj_names.append (os.path.join (output_dir,
Greg Ward42406482000-09-27 02:08:14 +0000293 base + ext + self.obj_extension))
294 else:
295 obj_names.append (os.path.join (output_dir,
296 base + self.obj_extension))
297 return obj_names
298
299 # object_filenames ()
Greg Ward7c6395a2000-06-21 03:33:03 +0000300
301# class CygwinCCompiler
302
Greg Wardf34506a2000-06-29 22:57:55 +0000303
Greg Ward7c6395a2000-06-21 03:33:03 +0000304# the same as cygwin plus some additional parameters
305class Mingw32CCompiler (CygwinCCompiler):
306
307 compiler_type = 'mingw32'
308
309 def __init__ (self,
310 verbose=0,
311 dry_run=0,
312 force=0):
313
314 CygwinCCompiler.__init__ (self, verbose, dry_run, force)
Fred Drakeb94b8492001-12-06 20:51:35 +0000315
Greg Wardbf5c7092000-08-02 01:31:56 +0000316 # A real mingw32 doesn't need to specify a different entry point,
317 # but cygwin 2.91.57 in no-cygwin-mode needs it.
318 if self.gcc_version <= "2.91.57":
319 entry_point = '--entry _DllMain@12'
320 else:
321 entry_point = ''
Greg Ward7c6395a2000-06-21 03:33:03 +0000322
Greg Wardf34506a2000-06-29 22:57:55 +0000323 self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
Greg Wardbf5c7092000-08-02 01:31:56 +0000324 compiler_so='gcc -mno-cygwin -mdll -O -Wall',
Greg Wardf34506a2000-06-29 22:57:55 +0000325 linker_exe='gcc -mno-cygwin',
Fred Drakeb94b8492001-12-06 20:51:35 +0000326 linker_so='%s -mno-cygwin -mdll -static %s'
Greg Ward42406482000-09-27 02:08:14 +0000327 % (self.linker_dll, entry_point))
Greg Wardbf5c7092000-08-02 01:31:56 +0000328 # Maybe we should also append -mthreads, but then the finished
329 # dlls need another dll (mingwm10.dll see Mingw32 docs)
Fred Drakeb94b8492001-12-06 20:51:35 +0000330 # (-mthreads: Support thread-safe exception handling on `Mingw32')
331
332 # no additional libraries needed
Greg Wardbf5c7092000-08-02 01:31:56 +0000333 self.dll_libraries=[]
Fred Drakeb94b8492001-12-06 20:51:35 +0000334
Greg Ward7c6395a2000-06-21 03:33:03 +0000335 # __init__ ()
Greg Wardbf5c7092000-08-02 01:31:56 +0000336
Greg Ward7c6395a2000-06-21 03:33:03 +0000337# class Mingw32CCompiler
Greg Wardbf5c7092000-08-02 01:31:56 +0000338
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000339# Because these compilers aren't configured in Python's pyconfig.h file by
Greg Wardbf5c7092000-08-02 01:31:56 +0000340# default, we should at least warn the user if he is using a unmodified
341# version.
342
Greg Warde8e9d112000-08-13 01:18:55 +0000343CONFIG_H_OK = "ok"
344CONFIG_H_NOTOK = "not ok"
345CONFIG_H_UNCERTAIN = "uncertain"
346
Greg Wardbf5c7092000-08-02 01:31:56 +0000347def check_config_h():
Greg Warde8e9d112000-08-13 01:18:55 +0000348
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000349 """Check if the current Python installation (specifically, pyconfig.h)
Greg Warde8e9d112000-08-13 01:18:55 +0000350 appears amenable to building extensions with GCC. Returns a tuple
351 (status, details), where 'status' is one of the following constants:
352 CONFIG_H_OK
353 all is well, go ahead and compile
354 CONFIG_H_NOTOK
355 doesn't look good
356 CONFIG_H_UNCERTAIN
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000357 not sure -- unable to read pyconfig.h
Greg Warde8e9d112000-08-13 01:18:55 +0000358 'details' is a human-readable string explaining the situation.
359
360 Note there are two ways to conclude "OK": either 'sys.version' contains
361 the string "GCC" (implying that this Python was built with GCC), or the
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000362 installed "pyconfig.h" contains the string "__GNUC__".
Greg Wardbf5c7092000-08-02 01:31:56 +0000363 """
Greg Warde8e9d112000-08-13 01:18:55 +0000364
365 # XXX since this function also checks sys.version, it's not strictly a
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000366 # "pyconfig.h" check -- should probably be renamed...
Greg Wardbf5c7092000-08-02 01:31:56 +0000367
368 from distutils import sysconfig
Andrew M. Kuchling6e9c0ba2001-03-22 03:50:09 +0000369 import string
Greg Wardbf5c7092000-08-02 01:31:56 +0000370 # if sys.version contains GCC then python was compiled with
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000371 # GCC, and the pyconfig.h file should be OK
Andrew M. Kuchlingac20f772001-03-22 03:48:31 +0000372 if string.find(sys.version,"GCC") >= 0:
Greg Warde8e9d112000-08-13 01:18:55 +0000373 return (CONFIG_H_OK, "sys.version mentions 'GCC'")
Fred Drakeb94b8492001-12-06 20:51:35 +0000374
Greg Warde8e9d112000-08-13 01:18:55 +0000375 fn = sysconfig.get_config_h_filename()
Greg Wardbf5c7092000-08-02 01:31:56 +0000376 try:
377 # It would probably better to read single lines to search.
Fred Drakeb94b8492001-12-06 20:51:35 +0000378 # But we do this only once, and it is fast enough
Greg Warde8e9d112000-08-13 01:18:55 +0000379 f = open(fn)
380 s = f.read()
Greg Wardbf5c7092000-08-02 01:31:56 +0000381 f.close()
Fred Drakeb94b8492001-12-06 20:51:35 +0000382
Greg Warde8e9d112000-08-13 01:18:55 +0000383 except IOError, exc:
Greg Wardbf5c7092000-08-02 01:31:56 +0000384 # if we can't read this file, we cannot say it is wrong
385 # the compiler will complain later about this file as missing
Greg Warde8e9d112000-08-13 01:18:55 +0000386 return (CONFIG_H_UNCERTAIN,
387 "couldn't read '%s': %s" % (fn, exc.strerror))
388
389 else:
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000390 # "pyconfig.h" contains an "#ifdef __GNUC__" or something similar
Andrew M. Kuchlingac20f772001-03-22 03:48:31 +0000391 if string.find(s,"__GNUC__") >= 0:
Greg Warde8e9d112000-08-13 01:18:55 +0000392 return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
393 else:
394 return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
395
396
Greg Wardbf5c7092000-08-02 01:31:56 +0000397
398def get_versions():
399 """ Try to find out the versions of gcc, ld and dllwrap.
400 If not possible it returns None for it.
401 """
402 from distutils.version import StrictVersion
403 from distutils.spawn import find_executable
404 import re
Fred Drakeb94b8492001-12-06 20:51:35 +0000405
Greg Wardbf5c7092000-08-02 01:31:56 +0000406 gcc_exe = find_executable('gcc')
407 if gcc_exe:
408 out = os.popen(gcc_exe + ' -dumpversion','r')
409 out_string = out.read()
410 out.close()
411 result = re.search('(\d+\.\d+\.\d+)',out_string)
412 if result:
413 gcc_version = StrictVersion(result.group(1))
414 else:
415 gcc_version = None
416 else:
417 gcc_version = None
418 ld_exe = find_executable('ld')
419 if ld_exe:
420 out = os.popen(ld_exe + ' -v','r')
421 out_string = out.read()
422 out.close()
423 result = re.search('(\d+\.\d+\.\d+)',out_string)
424 if result:
425 ld_version = StrictVersion(result.group(1))
426 else:
427 ld_version = None
428 else:
429 ld_version = None
430 dllwrap_exe = find_executable('dllwrap')
431 if dllwrap_exe:
432 out = os.popen(dllwrap_exe + ' --version','r')
433 out_string = out.read()
434 out.close()
435 result = re.search(' (\d+\.\d+\.\d+)',out_string)
436 if result:
437 dllwrap_version = StrictVersion(result.group(1))
438 else:
439 dllwrap_version = None
440 else:
441 dllwrap_version = None
442 return (gcc_version, ld_version, dllwrap_version)