home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / python2.4 / distutils / unixccompiler.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2007-04-29  |  8.0 KB  |  277 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''distutils.unixccompiler
  5.  
  6. Contains the UnixCCompiler class, a subclass of CCompiler that handles
  7. the "typical" Unix-style command-line C compiler:
  8.   * macros defined with -Dname[=value]
  9.   * macros undefined with -Uname
  10.   * include search directories specified with -Idir
  11.   * libraries specified with -lllib
  12.   * library search directories specified with -Ldir
  13.   * compile handled by \'cc\' (or similar) executable with -c option:
  14.     compiles .c to .o
  15.   * link static library handled by \'ar\' command (possibly with \'ranlib\')
  16.   * link shared library handled by \'cc -shared\'
  17. '''
  18. __revision__ = '$Id: unixccompiler.py 52231 2006-10-08 17:41:25Z ronald.oussoren $'
  19. import os
  20. import sys
  21. from types import StringType, NoneType
  22. from copy import copy
  23. from distutils import sysconfig
  24. from distutils.dep_util import newer
  25. from distutils.ccompiler import CCompiler, gen_preprocess_options, gen_lib_options
  26. from distutils.errors import DistutilsExecError, CompileError, LibError, LinkError
  27. from distutils import log
  28.  
  29. def _darwin_compiler_fixup(compiler_so, cc_args):
  30.     """
  31.     This function will strip '-isysroot PATH' and '-arch ARCH' from the
  32.     compile flag if the user has specified one of them in extra_compile_flags.
  33.  
  34.     This is needed because '-arch ARCH' adds another architecture to the
  35.     build, without a way to remove an architecture. Furthermore GCC will
  36.     barf if multiple '-isysroot' arguments are present.
  37.     """
  38.     stripArch = stripSysroot = 0
  39.     compiler_so = list(compiler_so)
  40.     kernel_version = os.uname()[2]
  41.     major_version = int(kernel_version.split('.')[0])
  42.     if major_version < 8:
  43.         stripArch = stripSysroot = True
  44.     else:
  45.         stripArch = '-arch' in cc_args
  46.         stripSysroot = '-isysroot' in cc_args
  47.     if stripArch:
  48.         while None:
  49.             
  50.             try:
  51.                 index = compiler_so.index('-arch')
  52.                 del compiler_so[index:index + 2]
  53.             continue
  54.             except ValueError:
  55.                 break
  56.                 continue
  57.             
  58.  
  59.     
  60.     if stripSysroot:
  61.         
  62.         try:
  63.             index = compiler_so.index('-isysroot')
  64.             del compiler_so[index:index + 2]
  65.         except ValueError:
  66.             pass
  67.         except:
  68.             None<EXCEPTION MATCH>ValueError
  69.         
  70.  
  71.     None<EXCEPTION MATCH>ValueError
  72.     return compiler_so
  73.  
  74.  
  75. class UnixCCompiler(CCompiler):
  76.     compiler_type = 'unix'
  77.     executables = {
  78.         'preprocessor': None,
  79.         'compiler': [
  80.             'cc'],
  81.         'compiler_so': [
  82.             'cc'],
  83.         'compiler_cxx': [
  84.             'cc'],
  85.         'linker_so': [
  86.             'cc',
  87.             '-shared'],
  88.         'linker_exe': [
  89.             'cc'],
  90.         'archiver': [
  91.             'ar',
  92.             '-cr'],
  93.         'ranlib': None }
  94.     if sys.platform[:6] == 'darwin':
  95.         executables['ranlib'] = [
  96.             'ranlib']
  97.     
  98.     src_extensions = [
  99.         '.c',
  100.         '.C',
  101.         '.cc',
  102.         '.cxx',
  103.         '.cpp',
  104.         '.m']
  105.     obj_extension = '.o'
  106.     static_lib_extension = '.a'
  107.     shared_lib_extension = '.so'
  108.     dylib_lib_extension = '.dylib'
  109.     static_lib_format = shared_lib_format = dylib_lib_format = 'lib%s%s'
  110.     if sys.platform == 'cygwin':
  111.         exe_extension = '.exe'
  112.     
  113.     
  114.     def preprocess(self, source, output_file = None, macros = None, include_dirs = None, extra_preargs = None, extra_postargs = None):
  115.         (ignore, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
  116.         pp_opts = gen_preprocess_options(macros, include_dirs)
  117.         pp_args = self.preprocessor + pp_opts
  118.         if output_file:
  119.             pp_args.extend([
  120.                 '-o',
  121.                 output_file])
  122.         
  123.         if extra_preargs:
  124.             pp_args[:0] = extra_preargs
  125.         
  126.         if extra_postargs:
  127.             pp_args.extend(extra_postargs)
  128.         
  129.         pp_args.append(source)
  130.         if self.force and output_file is None or newer(source, output_file):
  131.             if output_file:
  132.                 self.mkpath(os.path.dirname(output_file))
  133.             
  134.             
  135.             try:
  136.                 self.spawn(pp_args)
  137.             except DistutilsExecError:
  138.                 msg = None
  139.                 raise CompileError, msg
  140.             except:
  141.                 None<EXCEPTION MATCH>DistutilsExecError
  142.             
  143.  
  144.         None<EXCEPTION MATCH>DistutilsExecError
  145.  
  146.     
  147.     def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
  148.         compiler_so = self.compiler_so
  149.         if sys.platform == 'darwin':
  150.             compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs)
  151.         
  152.         
  153.         try:
  154.             self.spawn(compiler_so + cc_args + [
  155.                 src,
  156.                 '-o',
  157.                 obj] + extra_postargs)
  158.         except DistutilsExecError:
  159.             msg = None
  160.             raise CompileError, msg
  161.  
  162.  
  163.     
  164.     def create_static_lib(self, objects, output_libname, output_dir = None, debug = 0, target_lang = None):
  165.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  166.         output_filename = self.library_filename(output_libname, output_dir = output_dir)
  167.         if self._need_link(objects, output_filename):
  168.             self.mkpath(os.path.dirname(output_filename))
  169.             self.spawn(self.archiver + [
  170.                 output_filename] + objects + self.objects)
  171.             if self.ranlib:
  172.                 
  173.                 try:
  174.                     self.spawn(self.ranlib + [
  175.                         output_filename])
  176.                 except DistutilsExecError:
  177.                     msg = None
  178.                     raise LibError, msg
  179.                 except:
  180.                     None<EXCEPTION MATCH>DistutilsExecError
  181.                 
  182.  
  183.             None<EXCEPTION MATCH>DistutilsExecError
  184.         else:
  185.             log.debug('skipping %s (up-to-date)', output_filename)
  186.  
  187.     
  188.     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):
  189.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  190.         (libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
  191.         library_dirs = _[1]
  192.         runtime_library_dirs = _[1]
  193.         lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs, libraries)
  194.         if self._need_link(objects, output_filename):
  195.             ld_args = objects + self.objects + lib_opts + [
  196.                 '-o',
  197.                 output_filename]
  198.             if debug:
  199.                 ld_args[:0] = [
  200.                     '-g']
  201.             
  202.             if extra_preargs:
  203.                 ld_args[:0] = extra_preargs
  204.             
  205.             if extra_postargs:
  206.                 ld_args.extend(extra_postargs)
  207.             
  208.             self.mkpath(os.path.dirname(output_filename))
  209.             
  210.             try:
  211.                 if target_desc == CCompiler.EXECUTABLE:
  212.                     linker = self.linker_exe[:]
  213.                 else:
  214.                     linker = self.linker_so[:]
  215.                 if target_lang == 'c++' and self.compiler_cxx:
  216.                     linker[0] = self.compiler_cxx[0]
  217.                 
  218.                 if sys.platform == 'darwin':
  219.                     linker = _darwin_compiler_fixup(linker, ld_args)
  220.                 
  221.                 self.spawn(linker + ld_args)
  222.             except DistutilsExecError:
  223.                 msg = None
  224.                 raise LinkError, msg
  225.             except:
  226.                 None<EXCEPTION MATCH>DistutilsExecError
  227.             
  228.  
  229.         None<EXCEPTION MATCH>DistutilsExecError
  230.         log.debug('skipping %s (up-to-date)', output_filename)
  231.  
  232.     
  233.     def library_dir_option(self, dir):
  234.         return '-L' + dir
  235.  
  236.     
  237.     def runtime_library_dir_option(self, dir):
  238.         compiler = os.path.basename(sysconfig.get_config_var('CC'))
  239.         if sys.platform[:6] == 'darwin':
  240.             return '-L' + dir
  241.         elif sys.platform[:5] == 'hp-ux':
  242.             return '+s -L' + dir
  243.         elif sys.platform[:7] == 'irix646' or sys.platform[:6] == 'osf1V5':
  244.             return [
  245.                 '-rpath',
  246.                 dir]
  247.         elif compiler[:3] == 'gcc' or compiler[:3] == 'g++':
  248.             return '-Wl,-R' + dir
  249.         else:
  250.             return '-R' + dir
  251.  
  252.     
  253.     def library_option(self, lib):
  254.         return '-l' + lib
  255.  
  256.     
  257.     def find_library_file(self, dirs, lib, debug = 0):
  258.         shared_f = self.library_filename(lib, lib_type = 'shared')
  259.         dylib_f = self.library_filename(lib, lib_type = 'dylib')
  260.         static_f = self.library_filename(lib, lib_type = 'static')
  261.         for dir in dirs:
  262.             shared = os.path.join(dir, shared_f)
  263.             dylib = os.path.join(dir, dylib_f)
  264.             static = os.path.join(dir, static_f)
  265.             if os.path.exists(dylib):
  266.                 return dylib
  267.                 continue
  268.             if os.path.exists(shared):
  269.                 return shared
  270.                 continue
  271.             if os.path.exists(static):
  272.                 return static
  273.                 continue
  274.         
  275.  
  276.  
  277.