home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / command / build_clib.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  6.4 KB  |  152 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """distutils.command.build_clib
  5.  
  6. Implements the Distutils 'build_clib' command, to build a C/C++ library
  7. that is included in the module distribution and needed by an extension
  8. module."""
  9. __revision__ = '$Id: build_clib.py 37828 2004-11-10 22:23:15Z loewis $'
  10. import os
  11. import string
  12. from types import *
  13. from distutils.core import Command
  14. from distutils.errors import *
  15. from distutils.sysconfig import customize_compiler
  16. from distutils import log
  17.  
  18. def show_compilers():
  19.     show_compilers = show_compilers
  20.     import distutils.ccompiler
  21.     show_compilers()
  22.  
  23.  
  24. class build_clib(Command):
  25.     description = 'build C/C++ libraries used by Python extensions'
  26.     user_options = [
  27.         ('build-clib', 'b', 'directory to build C/C++ libraries to'),
  28.         ('build-temp', 't', 'directory to put temporary build by-products'),
  29.         ('debug', 'g', 'compile with debugging information'),
  30.         ('force', 'f', 'forcibly build everything (ignore file timestamps)'),
  31.         ('compiler=', 'c', 'specify the compiler type')]
  32.     boolean_options = [
  33.         'debug',
  34.         'force']
  35.     help_options = [
  36.         ('help-compiler', None, 'list available compilers', show_compilers)]
  37.     
  38.     def initialize_options(self):
  39.         self.build_clib = None
  40.         self.build_temp = None
  41.         self.libraries = None
  42.         self.include_dirs = None
  43.         self.define = None
  44.         self.undef = None
  45.         self.debug = None
  46.         self.force = 0
  47.         self.compiler = None
  48.  
  49.     
  50.     def finalize_options(self):
  51.         self.set_undefined_options('build', ('build_temp', 'build_clib'), ('build_temp', 'build_temp'), ('compiler', 'compiler'), ('debug', 'debug'), ('force', 'force'))
  52.         self.libraries = self.distribution.libraries
  53.         if self.libraries:
  54.             self.check_library_list(self.libraries)
  55.         
  56.         if self.include_dirs is None:
  57.             if not self.distribution.include_dirs:
  58.                 pass
  59.             self.include_dirs = []
  60.         
  61.         if type(self.include_dirs) is StringType:
  62.             self.include_dirs = string.split(self.include_dirs, os.pathsep)
  63.         
  64.  
  65.     
  66.     def run(self):
  67.         if not self.libraries:
  68.             return None
  69.         new_compiler = new_compiler
  70.         import distutils.ccompiler
  71.         self.compiler = new_compiler(compiler = self.compiler, dry_run = self.dry_run, force = self.force)
  72.         customize_compiler(self.compiler)
  73.         if self.include_dirs is not None:
  74.             self.compiler.set_include_dirs(self.include_dirs)
  75.         
  76.         if self.define is not None:
  77.             for name, value in self.define:
  78.                 self.compiler.define_macro(name, value)
  79.             
  80.         
  81.         if self.undef is not None:
  82.             for macro in self.undef:
  83.                 self.compiler.undefine_macro(macro)
  84.             
  85.         
  86.         self.build_libraries(self.libraries)
  87.  
  88.     
  89.     def check_library_list(self, libraries):
  90.         """Ensure that the list of libraries (presumably provided as a
  91.            command option 'libraries') is valid, i.e. it is a list of
  92.            2-tuples, where the tuples are (library_name, build_info_dict).
  93.            Raise DistutilsSetupError if the structure is invalid anywhere;
  94.            just returns otherwise."""
  95.         if type(libraries) is not ListType:
  96.             raise DistutilsSetupError, "'libraries' option must be a list of tuples"
  97.         type(libraries) is not ListType
  98.         for lib in libraries:
  99.             if type(lib) is not TupleType and len(lib) != 2:
  100.                 raise DistutilsSetupError, "each element of 'libraries' must a 2-tuple"
  101.             len(lib) != 2
  102.             if type(lib[0]) is not StringType:
  103.                 raise DistutilsSetupError, "first element of each tuple in 'libraries' " + 'must be a string (the library name)'
  104.             type(lib[0]) is not StringType
  105.             if ('/' in lib[0] or os.sep != '/') and os.sep in lib[0]:
  106.                 raise DistutilsSetupError, ("bad library name '%s': " + 'may not contain directory separators') % lib[0]
  107.             os.sep in lib[0]
  108.             if type(lib[1]) is not DictionaryType:
  109.                 raise DistutilsSetupError, "second element of each tuple in 'libraries' " + 'must be a dictionary (build info)'
  110.             type(lib[1]) is not DictionaryType
  111.         
  112.  
  113.     
  114.     def get_library_names(self):
  115.         if not self.libraries:
  116.             return None
  117.         lib_names = []
  118.         for lib_name, build_info in self.libraries:
  119.             lib_names.append(lib_name)
  120.         
  121.         return lib_names
  122.  
  123.     
  124.     def get_source_files(self):
  125.         self.check_library_list(self.libraries)
  126.         filenames = []
  127.         for lib_name, build_info in self.libraries:
  128.             sources = build_info.get('sources')
  129.             if sources is None or type(sources) not in (ListType, TupleType):
  130.                 raise DistutilsSetupError, "in 'libraries' option (library '%s'), 'sources' must be present and must be a list of source filenames" % lib_name
  131.             type(sources) not in (ListType, TupleType)
  132.             filenames.extend(sources)
  133.         
  134.         return filenames
  135.  
  136.     
  137.     def build_libraries(self, libraries):
  138.         for lib_name, build_info in libraries:
  139.             sources = build_info.get('sources')
  140.             if sources is None or type(sources) not in (ListType, TupleType):
  141.                 raise DistutilsSetupError, ("in 'libraries' option (library '%s'), " + "'sources' must be present and must be " + 'a list of source filenames') % lib_name
  142.             type(sources) not in (ListType, TupleType)
  143.             sources = list(sources)
  144.             log.info("building '%s' library", lib_name)
  145.             macros = build_info.get('macros')
  146.             include_dirs = build_info.get('include_dirs')
  147.             objects = self.compiler.compile(sources, output_dir = self.build_temp, macros = macros, include_dirs = include_dirs, debug = self.debug)
  148.             self.compiler.create_static_lib(objects, lib_name, output_dir = self.build_clib, debug = self.debug)
  149.         
  150.  
  151.  
  152.