blob: a9620076015eb3e9496cc2917c3e475c3cc35f22 [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
Jason Tishler21664d82003-04-14 12:51:26 +000036# - using gcc -mdll instead dllwrap doesn't work without -static because
37# it tries to link against dlls instead their import libraries. (If
38# it finds the dll first.)
39# 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
41# in the dlls.
Fred Drakeb94b8492001-12-06 20:51:35 +000042# *** only the version of June 2000 shows these problems
Jason Tishler21664d82003-04-14 12:51:26 +000043# * cygwin gcc 3.2/ld 2.13.90 works
44# (ld supports -shared)
45# * mingw gcc 3.2/ld 2.13 works
46# (ld supports -shared)
Greg Wardbf5c7092000-08-02 01:31:56 +000047
Andrew M. Kuchlingd448f662002-11-19 13:12:28 +000048# This module should be kept compatible with Python 1.5.2.
49
Greg Ward7c6395a2000-06-21 03:33:03 +000050__revision__ = "$Id$"
51
Greg Wardb1dceae2000-08-13 00:43:56 +000052import os,sys,copy
Greg Ward42406482000-09-27 02:08:14 +000053from distutils.ccompiler import gen_preprocess_options, gen_lib_options
Greg Ward7c6395a2000-06-21 03:33:03 +000054from distutils.unixccompiler import UnixCCompiler
Greg Wardbf5c7092000-08-02 01:31:56 +000055from distutils.file_util import write_file
Greg Ward42406482000-09-27 02:08:14 +000056from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
Jeremy Hyltoncd8a1142002-06-04 20:14:43 +000057from distutils import log
Greg Ward7c6395a2000-06-21 03:33:03 +000058
Greg Ward7c6395a2000-06-21 03:33:03 +000059class CygwinCCompiler (UnixCCompiler):
60
61 compiler_type = 'cygwin'
Greg Wardb1dceae2000-08-13 00:43:56 +000062 obj_extension = ".o"
63 static_lib_extension = ".a"
64 shared_lib_extension = ".dll"
65 static_lib_format = "lib%s%s"
66 shared_lib_format = "%s%s"
67 exe_extension = ".exe"
Fred Drakeb94b8492001-12-06 20:51:35 +000068
Jeremy Hylton1bba31d2002-06-13 17:28:18 +000069 def __init__ (self, verbose=0, dry_run=0, force=0):
Greg Ward7c6395a2000-06-21 03:33:03 +000070
71 UnixCCompiler.__init__ (self, verbose, dry_run, force)
72
Greg Warde8e9d112000-08-13 01:18:55 +000073 (status, details) = check_config_h()
74 self.debug_print("Python's GCC status: %s (details: %s)" %
75 (status, details))
76 if status is not CONFIG_H_OK:
Greg Wardbf5c7092000-08-02 01:31:56 +000077 self.warn(
Tim Peters182b5ac2004-07-18 06:16:08 +000078 "Python's pyconfig.h doesn't seem to support your compiler. "
Jeremy Hylton1bba31d2002-06-13 17:28:18 +000079 "Reason: %s. "
80 "Compiling may fail because of undefined preprocessor macros."
81 % details)
Fred Drakeb94b8492001-12-06 20:51:35 +000082
Jeremy Hylton1bba31d2002-06-13 17:28:18 +000083 self.gcc_version, self.ld_version, self.dllwrap_version = \
Greg Wardbf5c7092000-08-02 01:31:56 +000084 get_versions()
Greg Wardb1dceae2000-08-13 00:43:56 +000085 self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" %
Fred Drakeb94b8492001-12-06 20:51:35 +000086 (self.gcc_version,
87 self.ld_version,
Greg Wardbf5c7092000-08-02 01:31:56 +000088 self.dllwrap_version) )
89
Jason Tishler21664d82003-04-14 12:51:26 +000090 # ld_version >= "2.10.90" and < "2.13" should also be able to use
Greg Wardbf5c7092000-08-02 01:31:56 +000091 # gcc -mdll instead of dllwrap
Fred Drakeb94b8492001-12-06 20:51:35 +000092 # Older dllwraps had own version numbers, newer ones use the
Greg Wardbf5c7092000-08-02 01:31:56 +000093 # same as the rest of binutils ( also ld )
94 # dllwrap 2.10.90 is buggy
Fred Drakeb94b8492001-12-06 20:51:35 +000095 if self.ld_version >= "2.10.90":
Greg Ward42406482000-09-27 02:08:14 +000096 self.linker_dll = "gcc"
Greg Wardbf5c7092000-08-02 01:31:56 +000097 else:
Greg Ward42406482000-09-27 02:08:14 +000098 self.linker_dll = "dllwrap"
Greg Wardbf5c7092000-08-02 01:31:56 +000099
Jason Tishler21664d82003-04-14 12:51:26 +0000100 # ld_version >= "2.13" support -shared so use it instead of
101 # -mdll -static
102 if self.ld_version >= "2.13":
103 shared_option = "-shared"
104 else:
105 shared_option = "-mdll -static"
106
Greg Wardf34506a2000-06-29 22:57:55 +0000107 # Hard-code GCC because that's what this is all about.
108 # XXX optimization, warnings etc. should be customizable.
Greg Wardbf5c7092000-08-02 01:31:56 +0000109 self.set_executables(compiler='gcc -mcygwin -O -Wall',
110 compiler_so='gcc -mcygwin -mdll -O -Wall',
Hye-Shik Chang2400e932004-06-05 18:37:53 +0000111 compiler_cxx='g++ -mcygwin -O -Wall',
Greg Wardbf5c7092000-08-02 01:31:56 +0000112 linker_exe='gcc -mcygwin',
Jason Tishler21664d82003-04-14 12:51:26 +0000113 linker_so=('%s -mcygwin %s' %
114 (self.linker_dll, shared_option)))
Greg Ward7c6395a2000-06-21 03:33:03 +0000115
Fred Drakeb94b8492001-12-06 20:51:35 +0000116 # cygwin and mingw32 need different sets of libraries
Greg Wardbf5c7092000-08-02 01:31:56 +0000117 if self.gcc_version == "2.91.57":
118 # cygwin shouldn't need msvcrt, but without the dlls will crash
119 # (gcc version 2.91.57) -- perhaps something about initialization
120 self.dll_libraries=["msvcrt"]
Fred Drakeb94b8492001-12-06 20:51:35 +0000121 self.warn(
Greg Wardbf5c7092000-08-02 01:31:56 +0000122 "Consider upgrading to a newer version of gcc")
123 else:
124 self.dll_libraries=[]
Fred Drakeb94b8492001-12-06 20:51:35 +0000125
Greg Ward7c6395a2000-06-21 03:33:03 +0000126 # __init__ ()
127
Greg Ward42406482000-09-27 02:08:14 +0000128
Jeremy Hylton1b046e42002-06-18 18:48:55 +0000129 def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
130 if ext == '.rc' or ext == '.res':
131 # gcc needs '.res' and '.rc' compiled to object files !!!
132 try:
133 self.spawn(["windres", "-i", src, "-o", obj])
134 except DistutilsExecError, msg:
135 raise CompileError, msg
136 else: # for other files use the C-compiler
137 try:
138 self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
139 extra_postargs)
140 except DistutilsExecError, msg:
141 raise CompileError, msg
Greg Ward42406482000-09-27 02:08:14 +0000142
Greg Ward42406482000-09-27 02:08:14 +0000143 def link (self,
144 target_desc,
145 objects,
146 output_filename,
147 output_dir=None,
148 libraries=None,
149 library_dirs=None,
150 runtime_library_dirs=None,
151 export_symbols=None,
152 debug=0,
153 extra_preargs=None,
154 extra_postargs=None,
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000155 build_temp=None,
156 target_lang=None):
Fred Drakeb94b8492001-12-06 20:51:35 +0000157
Greg Wardb1dceae2000-08-13 00:43:56 +0000158 # use separate copies, so we can modify the lists
159 extra_preargs = copy.copy(extra_preargs or [])
160 libraries = copy.copy(libraries or [])
Greg Ward42406482000-09-27 02:08:14 +0000161 objects = copy.copy(objects or [])
Fred Drakeb94b8492001-12-06 20:51:35 +0000162
Greg Wardbf5c7092000-08-02 01:31:56 +0000163 # Additional libraries
Greg Wardf34506a2000-06-29 22:57:55 +0000164 libraries.extend(self.dll_libraries)
Greg Wardbf5c7092000-08-02 01:31:56 +0000165
Greg Ward42406482000-09-27 02:08:14 +0000166 # handle export symbols by creating a def-file
167 # with executables this only works with gcc/ld as linker
168 if ((export_symbols is not None) and
169 (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
170 # (The linker doesn't do anything if output is up-to-date.
171 # So it would probably better to check if we really need this,
Fred Drakeb94b8492001-12-06 20:51:35 +0000172 # but for this we had to insert some unchanged parts of
173 # UnixCCompiler, and this is not what we want.)
Greg Ward42406482000-09-27 02:08:14 +0000174
Fred Drakeb94b8492001-12-06 20:51:35 +0000175 # we want to put some files in the same directory as the
Greg Ward42406482000-09-27 02:08:14 +0000176 # object files are, build_temp doesn't help much
177 # where are the object files
178 temp_dir = os.path.dirname(objects[0])
179 # name of dll to give the helper files the same base name
180 (dll_name, dll_extension) = os.path.splitext(
181 os.path.basename(output_filename))
182
183 # generate the filenames for these files
Greg Wardbf5c7092000-08-02 01:31:56 +0000184 def_file = os.path.join(temp_dir, dll_name + ".def")
Greg Ward42406482000-09-27 02:08:14 +0000185 lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a")
Fred Drakeb94b8492001-12-06 20:51:35 +0000186
Greg Ward42406482000-09-27 02:08:14 +0000187 # Generate .def file
Greg Wardbf5c7092000-08-02 01:31:56 +0000188 contents = [
189 "LIBRARY %s" % os.path.basename(output_filename),
190 "EXPORTS"]
Greg Ward7c6395a2000-06-21 03:33:03 +0000191 for sym in export_symbols:
Greg Wardbf5c7092000-08-02 01:31:56 +0000192 contents.append(sym)
193 self.execute(write_file, (def_file, contents),
194 "writing %s" % def_file)
195
Greg Ward42406482000-09-27 02:08:14 +0000196 # next add options for def-file and to creating import libraries
197
198 # dllwrap uses different options than gcc/ld
199 if self.linker_dll == "dllwrap":
Jeremy Hyltona2f99892002-06-04 20:26:44 +0000200 extra_preargs.extend(["--output-lib", lib_file])
Greg Wardbf5c7092000-08-02 01:31:56 +0000201 # for dllwrap we have to use a special option
Greg Ward42406482000-09-27 02:08:14 +0000202 extra_preargs.extend(["--def", def_file])
203 # we use gcc/ld here and can be sure ld is >= 2.9.10
204 else:
205 # doesn't work: bfd_close build\...\libfoo.a: Invalid operation
206 #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file])
Jeremy Hyltona2f99892002-06-04 20:26:44 +0000207 # for gcc/ld the def-file is specified as any object files
Greg Ward42406482000-09-27 02:08:14 +0000208 objects.append(def_file)
209
210 #end: if ((export_symbols is not None) and
Fred Drake132dce22000-12-12 23:11:42 +0000211 # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
Fred Drakeb94b8492001-12-06 20:51:35 +0000212
Greg Wardf34506a2000-06-29 22:57:55 +0000213 # who wants symbols and a many times larger output file
Fred Drakeb94b8492001-12-06 20:51:35 +0000214 # should explicitly switch the debug mode on
Greg Wardbf5c7092000-08-02 01:31:56 +0000215 # otherwise we let dllwrap/ld strip the output file
Fred Drakeb94b8492001-12-06 20:51:35 +0000216 # (On my machine: 10KB < stripped_file < ??100KB
Greg Ward42406482000-09-27 02:08:14 +0000217 # unstripped_file = stripped_file + XXX KB
Fred Drakeb94b8492001-12-06 20:51:35 +0000218 # ( XXX=254 for a typical python extension))
219 if not debug:
220 extra_preargs.append("-s")
221
Greg Ward42406482000-09-27 02:08:14 +0000222 UnixCCompiler.link(self,
223 target_desc,
224 objects,
225 output_filename,
226 output_dir,
227 libraries,
228 library_dirs,
229 runtime_library_dirs,
230 None, # export_symbols, we do this in our def-file
231 debug,
232 extra_preargs,
233 extra_postargs,
Gustavo Niemeyer6b016852002-11-05 16:12:02 +0000234 build_temp,
235 target_lang)
Fred Drakeb94b8492001-12-06 20:51:35 +0000236
Greg Ward42406482000-09-27 02:08:14 +0000237 # link ()
238
239 # -- Miscellaneous methods -----------------------------------------
240
241 # overwrite the one from CCompiler to support rc and res-files
242 def object_filenames (self,
243 source_filenames,
244 strip_dir=0,
245 output_dir=''):
246 if output_dir is None: output_dir = ''
247 obj_names = []
248 for src_name in source_filenames:
249 # use normcase to make sure '.rc' is really '.rc' and not '.RC'
250 (base, ext) = os.path.splitext (os.path.normcase(src_name))
251 if ext not in (self.src_extensions + ['.rc','.res']):
252 raise UnknownFileError, \
253 "unknown file type '%s' (from '%s')" % \
254 (ext, src_name)
255 if strip_dir:
256 base = os.path.basename (base)
257 if ext == '.res' or ext == '.rc':
258 # these need to be compiled to object files
Fred Drakeb94b8492001-12-06 20:51:35 +0000259 obj_names.append (os.path.join (output_dir,
Greg Ward42406482000-09-27 02:08:14 +0000260 base + ext + self.obj_extension))
261 else:
262 obj_names.append (os.path.join (output_dir,
263 base + self.obj_extension))
264 return obj_names
265
266 # object_filenames ()
Greg Ward7c6395a2000-06-21 03:33:03 +0000267
268# class CygwinCCompiler
269
Greg Wardf34506a2000-06-29 22:57:55 +0000270
Greg Ward7c6395a2000-06-21 03:33:03 +0000271# the same as cygwin plus some additional parameters
272class Mingw32CCompiler (CygwinCCompiler):
273
274 compiler_type = 'mingw32'
275
276 def __init__ (self,
277 verbose=0,
278 dry_run=0,
279 force=0):
280
281 CygwinCCompiler.__init__ (self, verbose, dry_run, force)
Fred Drakeb94b8492001-12-06 20:51:35 +0000282
Jason Tishler21664d82003-04-14 12:51:26 +0000283 # ld_version >= "2.13" support -shared so use it instead of
284 # -mdll -static
285 if self.ld_version >= "2.13":
286 shared_option = "-shared"
287 else:
288 shared_option = "-mdll -static"
289
Greg Wardbf5c7092000-08-02 01:31:56 +0000290 # A real mingw32 doesn't need to specify a different entry point,
291 # but cygwin 2.91.57 in no-cygwin-mode needs it.
292 if self.gcc_version <= "2.91.57":
293 entry_point = '--entry _DllMain@12'
294 else:
295 entry_point = ''
Greg Ward7c6395a2000-06-21 03:33:03 +0000296
Greg Wardf34506a2000-06-29 22:57:55 +0000297 self.set_executables(compiler='gcc -mno-cygwin -O -Wall',
Greg Wardbf5c7092000-08-02 01:31:56 +0000298 compiler_so='gcc -mno-cygwin -mdll -O -Wall',
Hye-Shik Chang2400e932004-06-05 18:37:53 +0000299 compiler_cxx='g++ -mno-cygwin -O -Wall',
Greg Wardf34506a2000-06-29 22:57:55 +0000300 linker_exe='gcc -mno-cygwin',
Jason Tishler21664d82003-04-14 12:51:26 +0000301 linker_so='%s -mno-cygwin %s %s'
302 % (self.linker_dll, shared_option,
303 entry_point))
Greg Wardbf5c7092000-08-02 01:31:56 +0000304 # Maybe we should also append -mthreads, but then the finished
305 # dlls need another dll (mingwm10.dll see Mingw32 docs)
Fred Drakeb94b8492001-12-06 20:51:35 +0000306 # (-mthreads: Support thread-safe exception handling on `Mingw32')
307
308 # no additional libraries needed
Greg Wardbf5c7092000-08-02 01:31:56 +0000309 self.dll_libraries=[]
Fred Drakeb94b8492001-12-06 20:51:35 +0000310
Greg Ward7c6395a2000-06-21 03:33:03 +0000311 # __init__ ()
Greg Wardbf5c7092000-08-02 01:31:56 +0000312
Greg Ward7c6395a2000-06-21 03:33:03 +0000313# class Mingw32CCompiler
Greg Wardbf5c7092000-08-02 01:31:56 +0000314
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000315# Because these compilers aren't configured in Python's pyconfig.h file by
Greg Wardbf5c7092000-08-02 01:31:56 +0000316# default, we should at least warn the user if he is using a unmodified
317# version.
318
Greg Warde8e9d112000-08-13 01:18:55 +0000319CONFIG_H_OK = "ok"
320CONFIG_H_NOTOK = "not ok"
321CONFIG_H_UNCERTAIN = "uncertain"
322
Greg Wardbf5c7092000-08-02 01:31:56 +0000323def check_config_h():
Greg Warde8e9d112000-08-13 01:18:55 +0000324
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000325 """Check if the current Python installation (specifically, pyconfig.h)
Greg Warde8e9d112000-08-13 01:18:55 +0000326 appears amenable to building extensions with GCC. Returns a tuple
327 (status, details), where 'status' is one of the following constants:
328 CONFIG_H_OK
329 all is well, go ahead and compile
330 CONFIG_H_NOTOK
331 doesn't look good
332 CONFIG_H_UNCERTAIN
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000333 not sure -- unable to read pyconfig.h
Greg Warde8e9d112000-08-13 01:18:55 +0000334 'details' is a human-readable string explaining the situation.
335
336 Note there are two ways to conclude "OK": either 'sys.version' contains
337 the string "GCC" (implying that this Python was built with GCC), or the
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000338 installed "pyconfig.h" contains the string "__GNUC__".
Greg Wardbf5c7092000-08-02 01:31:56 +0000339 """
Greg Warde8e9d112000-08-13 01:18:55 +0000340
341 # XXX since this function also checks sys.version, it's not strictly a
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000342 # "pyconfig.h" check -- should probably be renamed...
Greg Wardbf5c7092000-08-02 01:31:56 +0000343
344 from distutils import sysconfig
Andrew M. Kuchling6e9c0ba2001-03-22 03:50:09 +0000345 import string
Greg Wardbf5c7092000-08-02 01:31:56 +0000346 # if sys.version contains GCC then python was compiled with
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000347 # GCC, and the pyconfig.h file should be OK
Andrew M. Kuchlingac20f772001-03-22 03:48:31 +0000348 if string.find(sys.version,"GCC") >= 0:
Greg Warde8e9d112000-08-13 01:18:55 +0000349 return (CONFIG_H_OK, "sys.version mentions 'GCC'")
Fred Drakeb94b8492001-12-06 20:51:35 +0000350
Greg Warde8e9d112000-08-13 01:18:55 +0000351 fn = sysconfig.get_config_h_filename()
Greg Wardbf5c7092000-08-02 01:31:56 +0000352 try:
353 # It would probably better to read single lines to search.
Fred Drakeb94b8492001-12-06 20:51:35 +0000354 # But we do this only once, and it is fast enough
Greg Warde8e9d112000-08-13 01:18:55 +0000355 f = open(fn)
356 s = f.read()
Greg Wardbf5c7092000-08-02 01:31:56 +0000357 f.close()
Fred Drakeb94b8492001-12-06 20:51:35 +0000358
Greg Warde8e9d112000-08-13 01:18:55 +0000359 except IOError, exc:
Greg Wardbf5c7092000-08-02 01:31:56 +0000360 # if we can't read this file, we cannot say it is wrong
361 # the compiler will complain later about this file as missing
Greg Warde8e9d112000-08-13 01:18:55 +0000362 return (CONFIG_H_UNCERTAIN,
363 "couldn't read '%s': %s" % (fn, exc.strerror))
364
365 else:
Martin v. Löwis4f1cd8b2001-07-26 13:41:06 +0000366 # "pyconfig.h" contains an "#ifdef __GNUC__" or something similar
Andrew M. Kuchlingac20f772001-03-22 03:48:31 +0000367 if string.find(s,"__GNUC__") >= 0:
Greg Warde8e9d112000-08-13 01:18:55 +0000368 return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
369 else:
370 return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
371
372
Greg Wardbf5c7092000-08-02 01:31:56 +0000373
374def get_versions():
375 """ Try to find out the versions of gcc, ld and dllwrap.
376 If not possible it returns None for it.
377 """
378 from distutils.version import StrictVersion
379 from distutils.spawn import find_executable
380 import re
Fred Drakeb94b8492001-12-06 20:51:35 +0000381
Greg Wardbf5c7092000-08-02 01:31:56 +0000382 gcc_exe = find_executable('gcc')
383 if gcc_exe:
384 out = os.popen(gcc_exe + ' -dumpversion','r')
385 out_string = out.read()
386 out.close()
Jason Tishlerdcae0dc2003-04-09 20:13:59 +0000387 result = re.search('(\d+\.\d+(\.\d+)*)',out_string)
Greg Wardbf5c7092000-08-02 01:31:56 +0000388 if result:
389 gcc_version = StrictVersion(result.group(1))
390 else:
391 gcc_version = None
392 else:
393 gcc_version = None
394 ld_exe = find_executable('ld')
395 if ld_exe:
396 out = os.popen(ld_exe + ' -v','r')
397 out_string = out.read()
398 out.close()
Jason Tishlerdcae0dc2003-04-09 20:13:59 +0000399 result = re.search('(\d+\.\d+(\.\d+)*)',out_string)
Greg Wardbf5c7092000-08-02 01:31:56 +0000400 if result:
401 ld_version = StrictVersion(result.group(1))
402 else:
403 ld_version = None
404 else:
405 ld_version = None
406 dllwrap_exe = find_executable('dllwrap')
407 if dllwrap_exe:
408 out = os.popen(dllwrap_exe + ' --version','r')
409 out_string = out.read()
410 out.close()
Jason Tishlerdcae0dc2003-04-09 20:13:59 +0000411 result = re.search(' (\d+\.\d+(\.\d+)*)',out_string)
Greg Wardbf5c7092000-08-02 01:31:56 +0000412 if result:
413 dllwrap_version = StrictVersion(result.group(1))
414 else:
415 dllwrap_version = None
416 else:
417 dllwrap_version = None
418 return (gcc_version, ld_version, dllwrap_version)