NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

emxccompiler.py (6104B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\emxccompiler.py
      2 __revision__ = '$Id: emxccompiler.py 87602 2011-01-01 04:24:26Z richard.tew $'
      3 import os, sys, copy
      4 from distutils.ccompiler import gen_preprocess_options, gen_lib_options
      5 from distutils.unixccompiler import UnixCCompiler
      6 from distutils.file_util import write_file
      7 from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
      8 from distutils import log
      9 
     10 class EMXCCompiler(UnixCCompiler):
     11     compiler_type = 'emx'
     12     obj_extension = '.obj'
     13     static_lib_extension = '.lib'
     14     shared_lib_extension = '.dll'
     15     static_lib_format = '%s%s'
     16     shared_lib_format = '%s%s'
     17     res_extension = '.res'
     18     exe_extension = '.exe'
     19 
     20     def __init__(self, verbose = 0, dry_run = 0, force = 0):
     21         UnixCCompiler.__init__(self, verbose, dry_run, force)
     22         status, details = check_config_h()
     23         self.debug_print("Python's GCC status: %s (details: %s)" % (status, details))
     24         if status is not CONFIG_H_OK:
     25             self.warn("Python's pyconfig.h doesn't seem to support your compiler.  " + 'Reason: %s.' % details + 'Compiling may fail because of undefined preprocessor macros.')
     26         self.gcc_version, self.ld_version = get_versions()
     27         self.debug_print(self.compiler_type + ': gcc %s, ld %s\n' % (self.gcc_version, self.ld_version))
     28         self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall', linker_exe='gcc -Zomf -Zmt -Zcrtdll', linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')
     29         self.dll_libraries = ['gcc']
     30 
     31     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
     32         if ext == '.rc':
     33             try:
     34                 self.spawn(['rc', '-r', src])
     35             except DistutilsExecError as msg:
     36                 raise CompileError, msg
     37 
     38         else:
     39             try:
     40                 self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
     41             except DistutilsExecError as msg:
     42                 raise CompileError, msg
     43 
     44     def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
     45         extra_preargs = copy.copy(extra_preargs or [])
     46         libraries = copy.copy(libraries or [])
     47         objects = copy.copy(objects or [])
     48         libraries.extend(self.dll_libraries)
     49         if export_symbols is not None and target_desc != self.EXECUTABLE:
     50             temp_dir = os.path.dirname(objects[0])
     51             dll_name, dll_extension = os.path.splitext(os.path.basename(output_filename))
     52             def_file = os.path.join(temp_dir, dll_name + '.def')
     53             contents = ['LIBRARY %s INITINSTANCE TERMINSTANCE' % os.path.splitext(os.path.basename(output_filename))[0], 'DATA MULTIPLE NONSHARED', 'EXPORTS']
     54             for sym in export_symbols:
     55                 contents.append('  "%s"' % sym)
     56 
     57             self.execute(write_file, (def_file, contents), 'writing %s' % def_file)
     58             objects.append(def_file)
     59         if not debug:
     60             extra_preargs.append('-s')
     61         UnixCCompiler.link(self, target_desc, objects, output_filename, output_dir, libraries, library_dirs, runtime_library_dirs, None, debug, extra_preargs, extra_postargs, build_temp, target_lang)
     62 
     63     def object_filenames(self, source_filenames, strip_dir = 0, output_dir = ''):
     64         if output_dir is None:
     65             output_dir = ''
     66         obj_names = []
     67         for src_name in source_filenames:
     68             base, ext = os.path.splitext(os.path.normcase(src_name))
     69             if ext not in self.src_extensions + ['.rc']:
     70                 raise UnknownFileError, "unknown file type '%s' (from '%s')" % (ext, src_name)
     71             if strip_dir:
     72                 base = os.path.basename(base)
     73             if ext == '.rc':
     74                 obj_names.append(os.path.join(output_dir, base + self.res_extension))
     75             else:
     76                 obj_names.append(os.path.join(output_dir, base + self.obj_extension))
     77 
     78         return obj_names
     79 
     80     def find_library_file(self, dirs, lib, debug = 0):
     81         shortlib = '%s.lib' % lib
     82         longlib = 'lib%s.lib' % lib
     83         try:
     84             emx_dirs = os.environ['LIBRARY_PATH'].split(';')
     85         except KeyError:
     86             emx_dirs = []
     87 
     88         for dir in dirs + emx_dirs:
     89             shortlibp = os.path.join(dir, shortlib)
     90             longlibp = os.path.join(dir, longlib)
     91             if os.path.exists(shortlibp):
     92                 return shortlibp
     93             if os.path.exists(longlibp):
     94                 return longlibp
     95 
     96 
     97 CONFIG_H_OK = 'ok'
     98 CONFIG_H_NOTOK = 'not ok'
     99 CONFIG_H_UNCERTAIN = 'uncertain'
    100 
    101 def check_config_h():
    102     from distutils import sysconfig
    103     import string
    104     if string.find(sys.version, 'GCC') >= 0:
    105         return (CONFIG_H_OK, "sys.version mentions 'GCC'")
    106     fn = sysconfig.get_config_h_filename()
    107     try:
    108         f = open(fn)
    109         try:
    110             s = f.read()
    111         finally:
    112             f.close()
    113 
    114     except IOError as exc:
    115         return (CONFIG_H_UNCERTAIN, "couldn't read '%s': %s" % (fn, exc.strerror))
    116 
    117     if string.find(s, '__GNUC__') >= 0:
    118         return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
    119     else:
    120         return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
    121 
    122 
    123 def get_versions():
    124     from distutils.version import StrictVersion
    125     from distutils.spawn import find_executable
    126     import re
    127     gcc_exe = find_executable('gcc')
    128     if gcc_exe:
    129         out = os.popen(gcc_exe + ' -dumpversion', 'r')
    130         try:
    131             out_string = out.read()
    132         finally:
    133             out.close()
    134 
    135         result = re.search('(\\d+\\.\\d+\\.\\d+)', out_string)
    136         if result:
    137             gcc_version = StrictVersion(result.group(1))
    138         else:
    139             gcc_version = None
    140     else:
    141         gcc_version = None
    142     ld_version = None
    143     return (gcc_version, ld_version)