| 1 | n/a | """distutils.cygwinccompiler |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | Provides the CygwinCCompiler class, a subclass of UnixCCompiler that |
|---|
| 4 | n/a | handles the Cygwin port of the GNU C compiler to Windows. It also contains |
|---|
| 5 | n/a | the Mingw32CCompiler class which handles the mingw32 port of GCC (same as |
|---|
| 6 | n/a | cygwin in no-cygwin mode). |
|---|
| 7 | n/a | """ |
|---|
| 8 | n/a | |
|---|
| 9 | n/a | # problems: |
|---|
| 10 | n/a | # |
|---|
| 11 | n/a | # * if you use a msvc compiled python version (1.5.2) |
|---|
| 12 | n/a | # 1. you have to insert a __GNUC__ section in its config.h |
|---|
| 13 | n/a | # 2. you have to generate an import library for its dll |
|---|
| 14 | n/a | # - create a def-file for python??.dll |
|---|
| 15 | n/a | # - create an import library using |
|---|
| 16 | n/a | # dlltool --dllname python15.dll --def python15.def \ |
|---|
| 17 | n/a | # --output-lib libpython15.a |
|---|
| 18 | n/a | # |
|---|
| 19 | n/a | # see also http://starship.python.net/crew/kernr/mingw32/Notes.html |
|---|
| 20 | n/a | # |
|---|
| 21 | n/a | # * We put export_symbols in a def-file, and don't use |
|---|
| 22 | n/a | # --export-all-symbols because it doesn't worked reliable in some |
|---|
| 23 | n/a | # tested configurations. And because other windows compilers also |
|---|
| 24 | n/a | # need their symbols specified this no serious problem. |
|---|
| 25 | n/a | # |
|---|
| 26 | n/a | # tested configurations: |
|---|
| 27 | n/a | # |
|---|
| 28 | n/a | # * cygwin gcc 2.91.57/ld 2.9.4/dllwrap 0.2.4 works |
|---|
| 29 | n/a | # (after patching python's config.h and for C++ some other include files) |
|---|
| 30 | n/a | # see also http://starship.python.net/crew/kernr/mingw32/Notes.html |
|---|
| 31 | n/a | # * mingw32 gcc 2.95.2/ld 2.9.4/dllwrap 0.2.4 works |
|---|
| 32 | n/a | # (ld doesn't support -shared, so we use dllwrap) |
|---|
| 33 | n/a | # * cygwin gcc 2.95.2/ld 2.10.90/dllwrap 2.10.90 works now |
|---|
| 34 | n/a | # - its dllwrap doesn't work, there is a bug in binutils 2.10.90 |
|---|
| 35 | n/a | # see also http://sources.redhat.com/ml/cygwin/2000-06/msg01274.html |
|---|
| 36 | n/a | # - using gcc -mdll instead dllwrap doesn't work without -static because |
|---|
| 37 | n/a | # it tries to link against dlls instead their import libraries. (If |
|---|
| 38 | n/a | # it finds the dll first.) |
|---|
| 39 | n/a | # By specifying -static we force ld to link against the import libraries, |
|---|
| 40 | n/a | # this is windows standard and there are normally not the necessary symbols |
|---|
| 41 | n/a | # in the dlls. |
|---|
| 42 | n/a | # *** only the version of June 2000 shows these problems |
|---|
| 43 | n/a | # * cygwin gcc 3.2/ld 2.13.90 works |
|---|
| 44 | n/a | # (ld supports -shared) |
|---|
| 45 | n/a | # * mingw gcc 3.2/ld 2.13 works |
|---|
| 46 | n/a | # (ld supports -shared) |
|---|
| 47 | n/a | |
|---|
| 48 | n/a | import os |
|---|
| 49 | n/a | import sys |
|---|
| 50 | n/a | import copy |
|---|
| 51 | n/a | from subprocess import Popen, PIPE, check_output |
|---|
| 52 | n/a | import re |
|---|
| 53 | n/a | |
|---|
| 54 | n/a | from distutils.ccompiler import gen_preprocess_options, gen_lib_options |
|---|
| 55 | n/a | from distutils.unixccompiler import UnixCCompiler |
|---|
| 56 | n/a | from distutils.file_util import write_file |
|---|
| 57 | n/a | from distutils.errors import (DistutilsExecError, CCompilerError, |
|---|
| 58 | n/a | CompileError, UnknownFileError) |
|---|
| 59 | n/a | from distutils import log |
|---|
| 60 | n/a | from distutils.version import LooseVersion |
|---|
| 61 | n/a | from distutils.spawn import find_executable |
|---|
| 62 | n/a | |
|---|
| 63 | n/a | def get_msvcr(): |
|---|
| 64 | n/a | """Include the appropriate MSVC runtime library if Python was built |
|---|
| 65 | n/a | with MSVC 7.0 or later. |
|---|
| 66 | n/a | """ |
|---|
| 67 | n/a | msc_pos = sys.version.find('MSC v.') |
|---|
| 68 | n/a | if msc_pos != -1: |
|---|
| 69 | n/a | msc_ver = sys.version[msc_pos+6:msc_pos+10] |
|---|
| 70 | n/a | if msc_ver == '1300': |
|---|
| 71 | n/a | # MSVC 7.0 |
|---|
| 72 | n/a | return ['msvcr70'] |
|---|
| 73 | n/a | elif msc_ver == '1310': |
|---|
| 74 | n/a | # MSVC 7.1 |
|---|
| 75 | n/a | return ['msvcr71'] |
|---|
| 76 | n/a | elif msc_ver == '1400': |
|---|
| 77 | n/a | # VS2005 / MSVC 8.0 |
|---|
| 78 | n/a | return ['msvcr80'] |
|---|
| 79 | n/a | elif msc_ver == '1500': |
|---|
| 80 | n/a | # VS2008 / MSVC 9.0 |
|---|
| 81 | n/a | return ['msvcr90'] |
|---|
| 82 | n/a | elif msc_ver == '1600': |
|---|
| 83 | n/a | # VS2010 / MSVC 10.0 |
|---|
| 84 | n/a | return ['msvcr100'] |
|---|
| 85 | n/a | else: |
|---|
| 86 | n/a | raise ValueError("Unknown MS Compiler version %s " % msc_ver) |
|---|
| 87 | n/a | |
|---|
| 88 | n/a | |
|---|
| 89 | n/a | class CygwinCCompiler(UnixCCompiler): |
|---|
| 90 | n/a | """ Handles the Cygwin port of the GNU C compiler to Windows. |
|---|
| 91 | n/a | """ |
|---|
| 92 | n/a | compiler_type = 'cygwin' |
|---|
| 93 | n/a | obj_extension = ".o" |
|---|
| 94 | n/a | static_lib_extension = ".a" |
|---|
| 95 | n/a | shared_lib_extension = ".dll" |
|---|
| 96 | n/a | static_lib_format = "lib%s%s" |
|---|
| 97 | n/a | shared_lib_format = "%s%s" |
|---|
| 98 | n/a | exe_extension = ".exe" |
|---|
| 99 | n/a | |
|---|
| 100 | n/a | def __init__(self, verbose=0, dry_run=0, force=0): |
|---|
| 101 | n/a | |
|---|
| 102 | n/a | UnixCCompiler.__init__(self, verbose, dry_run, force) |
|---|
| 103 | n/a | |
|---|
| 104 | n/a | status, details = check_config_h() |
|---|
| 105 | n/a | self.debug_print("Python's GCC status: %s (details: %s)" % |
|---|
| 106 | n/a | (status, details)) |
|---|
| 107 | n/a | if status is not CONFIG_H_OK: |
|---|
| 108 | n/a | self.warn( |
|---|
| 109 | n/a | "Python's pyconfig.h doesn't seem to support your compiler. " |
|---|
| 110 | n/a | "Reason: %s. " |
|---|
| 111 | n/a | "Compiling may fail because of undefined preprocessor macros." |
|---|
| 112 | n/a | % details) |
|---|
| 113 | n/a | |
|---|
| 114 | n/a | self.gcc_version, self.ld_version, self.dllwrap_version = \ |
|---|
| 115 | n/a | get_versions() |
|---|
| 116 | n/a | self.debug_print(self.compiler_type + ": gcc %s, ld %s, dllwrap %s\n" % |
|---|
| 117 | n/a | (self.gcc_version, |
|---|
| 118 | n/a | self.ld_version, |
|---|
| 119 | n/a | self.dllwrap_version) ) |
|---|
| 120 | n/a | |
|---|
| 121 | n/a | # ld_version >= "2.10.90" and < "2.13" should also be able to use |
|---|
| 122 | n/a | # gcc -mdll instead of dllwrap |
|---|
| 123 | n/a | # Older dllwraps had own version numbers, newer ones use the |
|---|
| 124 | n/a | # same as the rest of binutils ( also ld ) |
|---|
| 125 | n/a | # dllwrap 2.10.90 is buggy |
|---|
| 126 | n/a | if self.ld_version >= "2.10.90": |
|---|
| 127 | n/a | self.linker_dll = "gcc" |
|---|
| 128 | n/a | else: |
|---|
| 129 | n/a | self.linker_dll = "dllwrap" |
|---|
| 130 | n/a | |
|---|
| 131 | n/a | # ld_version >= "2.13" support -shared so use it instead of |
|---|
| 132 | n/a | # -mdll -static |
|---|
| 133 | n/a | if self.ld_version >= "2.13": |
|---|
| 134 | n/a | shared_option = "-shared" |
|---|
| 135 | n/a | else: |
|---|
| 136 | n/a | shared_option = "-mdll -static" |
|---|
| 137 | n/a | |
|---|
| 138 | n/a | # Hard-code GCC because that's what this is all about. |
|---|
| 139 | n/a | # XXX optimization, warnings etc. should be customizable. |
|---|
| 140 | n/a | self.set_executables(compiler='gcc -mcygwin -O -Wall', |
|---|
| 141 | n/a | compiler_so='gcc -mcygwin -mdll -O -Wall', |
|---|
| 142 | n/a | compiler_cxx='g++ -mcygwin -O -Wall', |
|---|
| 143 | n/a | linker_exe='gcc -mcygwin', |
|---|
| 144 | n/a | linker_so=('%s -mcygwin %s' % |
|---|
| 145 | n/a | (self.linker_dll, shared_option))) |
|---|
| 146 | n/a | |
|---|
| 147 | n/a | # cygwin and mingw32 need different sets of libraries |
|---|
| 148 | n/a | if self.gcc_version == "2.91.57": |
|---|
| 149 | n/a | # cygwin shouldn't need msvcrt, but without the dlls will crash |
|---|
| 150 | n/a | # (gcc version 2.91.57) -- perhaps something about initialization |
|---|
| 151 | n/a | self.dll_libraries=["msvcrt"] |
|---|
| 152 | n/a | self.warn( |
|---|
| 153 | n/a | "Consider upgrading to a newer version of gcc") |
|---|
| 154 | n/a | else: |
|---|
| 155 | n/a | # Include the appropriate MSVC runtime library if Python was built |
|---|
| 156 | n/a | # with MSVC 7.0 or later. |
|---|
| 157 | n/a | self.dll_libraries = get_msvcr() |
|---|
| 158 | n/a | |
|---|
| 159 | n/a | def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): |
|---|
| 160 | n/a | """Compiles the source by spawning GCC and windres if needed.""" |
|---|
| 161 | n/a | if ext == '.rc' or ext == '.res': |
|---|
| 162 | n/a | # gcc needs '.res' and '.rc' compiled to object files !!! |
|---|
| 163 | n/a | try: |
|---|
| 164 | n/a | self.spawn(["windres", "-i", src, "-o", obj]) |
|---|
| 165 | n/a | except DistutilsExecError as msg: |
|---|
| 166 | n/a | raise CompileError(msg) |
|---|
| 167 | n/a | else: # for other files use the C-compiler |
|---|
| 168 | n/a | try: |
|---|
| 169 | n/a | self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + |
|---|
| 170 | n/a | extra_postargs) |
|---|
| 171 | n/a | except DistutilsExecError as msg: |
|---|
| 172 | n/a | raise CompileError(msg) |
|---|
| 173 | n/a | |
|---|
| 174 | n/a | def link(self, target_desc, objects, output_filename, output_dir=None, |
|---|
| 175 | n/a | libraries=None, library_dirs=None, runtime_library_dirs=None, |
|---|
| 176 | n/a | export_symbols=None, debug=0, extra_preargs=None, |
|---|
| 177 | n/a | extra_postargs=None, build_temp=None, target_lang=None): |
|---|
| 178 | n/a | """Link the objects.""" |
|---|
| 179 | n/a | # use separate copies, so we can modify the lists |
|---|
| 180 | n/a | extra_preargs = copy.copy(extra_preargs or []) |
|---|
| 181 | n/a | libraries = copy.copy(libraries or []) |
|---|
| 182 | n/a | objects = copy.copy(objects or []) |
|---|
| 183 | n/a | |
|---|
| 184 | n/a | # Additional libraries |
|---|
| 185 | n/a | libraries.extend(self.dll_libraries) |
|---|
| 186 | n/a | |
|---|
| 187 | n/a | # handle export symbols by creating a def-file |
|---|
| 188 | n/a | # with executables this only works with gcc/ld as linker |
|---|
| 189 | n/a | if ((export_symbols is not None) and |
|---|
| 190 | n/a | (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")): |
|---|
| 191 | n/a | # (The linker doesn't do anything if output is up-to-date. |
|---|
| 192 | n/a | # So it would probably better to check if we really need this, |
|---|
| 193 | n/a | # but for this we had to insert some unchanged parts of |
|---|
| 194 | n/a | # UnixCCompiler, and this is not what we want.) |
|---|
| 195 | n/a | |
|---|
| 196 | n/a | # we want to put some files in the same directory as the |
|---|
| 197 | n/a | # object files are, build_temp doesn't help much |
|---|
| 198 | n/a | # where are the object files |
|---|
| 199 | n/a | temp_dir = os.path.dirname(objects[0]) |
|---|
| 200 | n/a | # name of dll to give the helper files the same base name |
|---|
| 201 | n/a | (dll_name, dll_extension) = os.path.splitext( |
|---|
| 202 | n/a | os.path.basename(output_filename)) |
|---|
| 203 | n/a | |
|---|
| 204 | n/a | # generate the filenames for these files |
|---|
| 205 | n/a | def_file = os.path.join(temp_dir, dll_name + ".def") |
|---|
| 206 | n/a | lib_file = os.path.join(temp_dir, 'lib' + dll_name + ".a") |
|---|
| 207 | n/a | |
|---|
| 208 | n/a | # Generate .def file |
|---|
| 209 | n/a | contents = [ |
|---|
| 210 | n/a | "LIBRARY %s" % os.path.basename(output_filename), |
|---|
| 211 | n/a | "EXPORTS"] |
|---|
| 212 | n/a | for sym in export_symbols: |
|---|
| 213 | n/a | contents.append(sym) |
|---|
| 214 | n/a | self.execute(write_file, (def_file, contents), |
|---|
| 215 | n/a | "writing %s" % def_file) |
|---|
| 216 | n/a | |
|---|
| 217 | n/a | # next add options for def-file and to creating import libraries |
|---|
| 218 | n/a | |
|---|
| 219 | n/a | # dllwrap uses different options than gcc/ld |
|---|
| 220 | n/a | if self.linker_dll == "dllwrap": |
|---|
| 221 | n/a | extra_preargs.extend(["--output-lib", lib_file]) |
|---|
| 222 | n/a | # for dllwrap we have to use a special option |
|---|
| 223 | n/a | extra_preargs.extend(["--def", def_file]) |
|---|
| 224 | n/a | # we use gcc/ld here and can be sure ld is >= 2.9.10 |
|---|
| 225 | n/a | else: |
|---|
| 226 | n/a | # doesn't work: bfd_close build\...\libfoo.a: Invalid operation |
|---|
| 227 | n/a | #extra_preargs.extend(["-Wl,--out-implib,%s" % lib_file]) |
|---|
| 228 | n/a | # for gcc/ld the def-file is specified as any object files |
|---|
| 229 | n/a | objects.append(def_file) |
|---|
| 230 | n/a | |
|---|
| 231 | n/a | #end: if ((export_symbols is not None) and |
|---|
| 232 | n/a | # (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")): |
|---|
| 233 | n/a | |
|---|
| 234 | n/a | # who wants symbols and a many times larger output file |
|---|
| 235 | n/a | # should explicitly switch the debug mode on |
|---|
| 236 | n/a | # otherwise we let dllwrap/ld strip the output file |
|---|
| 237 | n/a | # (On my machine: 10KB < stripped_file < ??100KB |
|---|
| 238 | n/a | # unstripped_file = stripped_file + XXX KB |
|---|
| 239 | n/a | # ( XXX=254 for a typical python extension)) |
|---|
| 240 | n/a | if not debug: |
|---|
| 241 | n/a | extra_preargs.append("-s") |
|---|
| 242 | n/a | |
|---|
| 243 | n/a | UnixCCompiler.link(self, target_desc, objects, output_filename, |
|---|
| 244 | n/a | output_dir, libraries, library_dirs, |
|---|
| 245 | n/a | runtime_library_dirs, |
|---|
| 246 | n/a | None, # export_symbols, we do this in our def-file |
|---|
| 247 | n/a | debug, extra_preargs, extra_postargs, build_temp, |
|---|
| 248 | n/a | target_lang) |
|---|
| 249 | n/a | |
|---|
| 250 | n/a | # -- Miscellaneous methods ----------------------------------------- |
|---|
| 251 | n/a | |
|---|
| 252 | n/a | def object_filenames(self, source_filenames, strip_dir=0, output_dir=''): |
|---|
| 253 | n/a | """Adds supports for rc and res files.""" |
|---|
| 254 | n/a | if output_dir is None: |
|---|
| 255 | n/a | output_dir = '' |
|---|
| 256 | n/a | obj_names = [] |
|---|
| 257 | n/a | for src_name in source_filenames: |
|---|
| 258 | n/a | # use normcase to make sure '.rc' is really '.rc' and not '.RC' |
|---|
| 259 | n/a | base, ext = os.path.splitext(os.path.normcase(src_name)) |
|---|
| 260 | n/a | if ext not in (self.src_extensions + ['.rc','.res']): |
|---|
| 261 | n/a | raise UnknownFileError("unknown file type '%s' (from '%s')" % \ |
|---|
| 262 | n/a | (ext, src_name)) |
|---|
| 263 | n/a | if strip_dir: |
|---|
| 264 | n/a | base = os.path.basename (base) |
|---|
| 265 | n/a | if ext in ('.res', '.rc'): |
|---|
| 266 | n/a | # these need to be compiled to object files |
|---|
| 267 | n/a | obj_names.append (os.path.join(output_dir, |
|---|
| 268 | n/a | base + ext + self.obj_extension)) |
|---|
| 269 | n/a | else: |
|---|
| 270 | n/a | obj_names.append (os.path.join(output_dir, |
|---|
| 271 | n/a | base + self.obj_extension)) |
|---|
| 272 | n/a | return obj_names |
|---|
| 273 | n/a | |
|---|
| 274 | n/a | # the same as cygwin plus some additional parameters |
|---|
| 275 | n/a | class Mingw32CCompiler(CygwinCCompiler): |
|---|
| 276 | n/a | """ Handles the Mingw32 port of the GNU C compiler to Windows. |
|---|
| 277 | n/a | """ |
|---|
| 278 | n/a | compiler_type = 'mingw32' |
|---|
| 279 | n/a | |
|---|
| 280 | n/a | def __init__(self, verbose=0, dry_run=0, force=0): |
|---|
| 281 | n/a | |
|---|
| 282 | n/a | CygwinCCompiler.__init__ (self, verbose, dry_run, force) |
|---|
| 283 | n/a | |
|---|
| 284 | n/a | # ld_version >= "2.13" support -shared so use it instead of |
|---|
| 285 | n/a | # -mdll -static |
|---|
| 286 | n/a | if self.ld_version >= "2.13": |
|---|
| 287 | n/a | shared_option = "-shared" |
|---|
| 288 | n/a | else: |
|---|
| 289 | n/a | shared_option = "-mdll -static" |
|---|
| 290 | n/a | |
|---|
| 291 | n/a | # A real mingw32 doesn't need to specify a different entry point, |
|---|
| 292 | n/a | # but cygwin 2.91.57 in no-cygwin-mode needs it. |
|---|
| 293 | n/a | if self.gcc_version <= "2.91.57": |
|---|
| 294 | n/a | entry_point = '--entry _DllMain@12' |
|---|
| 295 | n/a | else: |
|---|
| 296 | n/a | entry_point = '' |
|---|
| 297 | n/a | |
|---|
| 298 | n/a | if is_cygwingcc(): |
|---|
| 299 | n/a | raise CCompilerError( |
|---|
| 300 | n/a | 'Cygwin gcc cannot be used with --compiler=mingw32') |
|---|
| 301 | n/a | |
|---|
| 302 | n/a | self.set_executables(compiler='gcc -O -Wall', |
|---|
| 303 | n/a | compiler_so='gcc -mdll -O -Wall', |
|---|
| 304 | n/a | compiler_cxx='g++ -O -Wall', |
|---|
| 305 | n/a | linker_exe='gcc', |
|---|
| 306 | n/a | linker_so='%s %s %s' |
|---|
| 307 | n/a | % (self.linker_dll, shared_option, |
|---|
| 308 | n/a | entry_point)) |
|---|
| 309 | n/a | # Maybe we should also append -mthreads, but then the finished |
|---|
| 310 | n/a | # dlls need another dll (mingwm10.dll see Mingw32 docs) |
|---|
| 311 | n/a | # (-mthreads: Support thread-safe exception handling on `Mingw32') |
|---|
| 312 | n/a | |
|---|
| 313 | n/a | # no additional libraries needed |
|---|
| 314 | n/a | self.dll_libraries=[] |
|---|
| 315 | n/a | |
|---|
| 316 | n/a | # Include the appropriate MSVC runtime library if Python was built |
|---|
| 317 | n/a | # with MSVC 7.0 or later. |
|---|
| 318 | n/a | self.dll_libraries = get_msvcr() |
|---|
| 319 | n/a | |
|---|
| 320 | n/a | # Because these compilers aren't configured in Python's pyconfig.h file by |
|---|
| 321 | n/a | # default, we should at least warn the user if he is using an unmodified |
|---|
| 322 | n/a | # version. |
|---|
| 323 | n/a | |
|---|
| 324 | n/a | CONFIG_H_OK = "ok" |
|---|
| 325 | n/a | CONFIG_H_NOTOK = "not ok" |
|---|
| 326 | n/a | CONFIG_H_UNCERTAIN = "uncertain" |
|---|
| 327 | n/a | |
|---|
| 328 | n/a | def check_config_h(): |
|---|
| 329 | n/a | """Check if the current Python installation appears amenable to building |
|---|
| 330 | n/a | extensions with GCC. |
|---|
| 331 | n/a | |
|---|
| 332 | n/a | Returns a tuple (status, details), where 'status' is one of the following |
|---|
| 333 | n/a | constants: |
|---|
| 334 | n/a | |
|---|
| 335 | n/a | - CONFIG_H_OK: all is well, go ahead and compile |
|---|
| 336 | n/a | - CONFIG_H_NOTOK: doesn't look good |
|---|
| 337 | n/a | - CONFIG_H_UNCERTAIN: not sure -- unable to read pyconfig.h |
|---|
| 338 | n/a | |
|---|
| 339 | n/a | 'details' is a human-readable string explaining the situation. |
|---|
| 340 | n/a | |
|---|
| 341 | n/a | Note there are two ways to conclude "OK": either 'sys.version' contains |
|---|
| 342 | n/a | the string "GCC" (implying that this Python was built with GCC), or the |
|---|
| 343 | n/a | installed "pyconfig.h" contains the string "__GNUC__". |
|---|
| 344 | n/a | """ |
|---|
| 345 | n/a | |
|---|
| 346 | n/a | # XXX since this function also checks sys.version, it's not strictly a |
|---|
| 347 | n/a | # "pyconfig.h" check -- should probably be renamed... |
|---|
| 348 | n/a | |
|---|
| 349 | n/a | from distutils import sysconfig |
|---|
| 350 | n/a | |
|---|
| 351 | n/a | # if sys.version contains GCC then python was compiled with GCC, and the |
|---|
| 352 | n/a | # pyconfig.h file should be OK |
|---|
| 353 | n/a | if "GCC" in sys.version: |
|---|
| 354 | n/a | return CONFIG_H_OK, "sys.version mentions 'GCC'" |
|---|
| 355 | n/a | |
|---|
| 356 | n/a | # let's see if __GNUC__ is mentioned in python.h |
|---|
| 357 | n/a | fn = sysconfig.get_config_h_filename() |
|---|
| 358 | n/a | try: |
|---|
| 359 | n/a | config_h = open(fn) |
|---|
| 360 | n/a | try: |
|---|
| 361 | n/a | if "__GNUC__" in config_h.read(): |
|---|
| 362 | n/a | return CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn |
|---|
| 363 | n/a | else: |
|---|
| 364 | n/a | return CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn |
|---|
| 365 | n/a | finally: |
|---|
| 366 | n/a | config_h.close() |
|---|
| 367 | n/a | except OSError as exc: |
|---|
| 368 | n/a | return (CONFIG_H_UNCERTAIN, |
|---|
| 369 | n/a | "couldn't read '%s': %s" % (fn, exc.strerror)) |
|---|
| 370 | n/a | |
|---|
| 371 | n/a | RE_VERSION = re.compile(br'(\d+\.\d+(\.\d+)*)') |
|---|
| 372 | n/a | |
|---|
| 373 | n/a | def _find_exe_version(cmd): |
|---|
| 374 | n/a | """Find the version of an executable by running `cmd` in the shell. |
|---|
| 375 | n/a | |
|---|
| 376 | n/a | If the command is not found, or the output does not match |
|---|
| 377 | n/a | `RE_VERSION`, returns None. |
|---|
| 378 | n/a | """ |
|---|
| 379 | n/a | executable = cmd.split()[0] |
|---|
| 380 | n/a | if find_executable(executable) is None: |
|---|
| 381 | n/a | return None |
|---|
| 382 | n/a | out = Popen(cmd, shell=True, stdout=PIPE).stdout |
|---|
| 383 | n/a | try: |
|---|
| 384 | n/a | out_string = out.read() |
|---|
| 385 | n/a | finally: |
|---|
| 386 | n/a | out.close() |
|---|
| 387 | n/a | result = RE_VERSION.search(out_string) |
|---|
| 388 | n/a | if result is None: |
|---|
| 389 | n/a | return None |
|---|
| 390 | n/a | # LooseVersion works with strings |
|---|
| 391 | n/a | # so we need to decode our bytes |
|---|
| 392 | n/a | return LooseVersion(result.group(1).decode()) |
|---|
| 393 | n/a | |
|---|
| 394 | n/a | def get_versions(): |
|---|
| 395 | n/a | """ Try to find out the versions of gcc, ld and dllwrap. |
|---|
| 396 | n/a | |
|---|
| 397 | n/a | If not possible it returns None for it. |
|---|
| 398 | n/a | """ |
|---|
| 399 | n/a | commands = ['gcc -dumpversion', 'ld -v', 'dllwrap --version'] |
|---|
| 400 | n/a | return tuple([_find_exe_version(cmd) for cmd in commands]) |
|---|
| 401 | n/a | |
|---|
| 402 | n/a | def is_cygwingcc(): |
|---|
| 403 | n/a | '''Try to determine if the gcc that would be used is from cygwin.''' |
|---|
| 404 | n/a | out_string = check_output(['gcc', '-dumpmachine']) |
|---|
| 405 | n/a | return out_string.strip().endswith(b'cygwin') |
|---|