<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import os , sys , re <EOL> from types import StringType , NoneType <EOL> from distutils import sysconfig <EOL> from distutils . dep_util import newer <EOL> from distutils . ccompiler import CCompiler , gen_preprocess_options , gen_lib_options <EOL> from distutils . errors import DistutilsExecError , CompileError , LibError , LinkError <EOL> from distutils import log <EOL> def _darwin_compiler_fixup ( compiler_so , cc_args ) : <EOL> """<STR_LIT>""" <EOL> stripArch = stripSysroot = <NUM_LIT:0> <EOL> compiler_so = list ( compiler_so ) <EOL> kernel_version = os . uname ( ) [ <NUM_LIT:2> ] <EOL> major_version = int ( kernel_version . split ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] ) <EOL> if major_version < <NUM_LIT:8> : <EOL> stripArch = stripSysroot = True <EOL> else : <EOL> stripArch = '<STR_LIT>' in cc_args <EOL> stripSysroot = '<STR_LIT>' in cc_args <EOL> if stripArch or '<STR_LIT>' in os . environ : <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> index = compiler_so . index ( '<STR_LIT>' ) <EOL> del compiler_so [ index : index + <NUM_LIT:2> ] <EOL> except ValueError : <EOL> break <EOL> if '<STR_LIT>' in os . environ and not stripArch : <EOL> compiler_so = compiler_so + os . environ [ '<STR_LIT>' ] . split ( ) <EOL> if stripSysroot : <EOL> try : <EOL> index = compiler_so . index ( '<STR_LIT>' ) <EOL> del compiler_so [ index : index + <NUM_LIT:2> ] <EOL> except ValueError : <EOL> pass <EOL> sysroot = None <EOL> if '<STR_LIT>' in cc_args : <EOL> idx = cc_args . index ( '<STR_LIT>' ) <EOL> sysroot = cc_args [ idx + <NUM_LIT:1> ] <EOL> elif '<STR_LIT>' in compiler_so : <EOL> idx = compiler_so . index ( '<STR_LIT>' ) <EOL> sysroot = compiler_so [ idx + <NUM_LIT:1> ] <EOL> if sysroot and not os . path . isdir ( sysroot ) : <EOL> log . warn ( "<STR_LIT>" , <EOL> sysroot ) <EOL> log . warn ( "<STR_LIT>" ) <EOL> return compiler_so <EOL> class UnixCCompiler ( CCompiler ) : <EOL> compiler_type = '<STR_LIT>' <EOL> executables = { '<STR_LIT>' : None , <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" ] , <EOL> '<STR_LIT>' : [ "<STR_LIT>" , "<STR_LIT>" ] , <EOL> '<STR_LIT>' : None , <EOL> } <EOL> if sys . platform [ : <NUM_LIT:6> ] == "<STR_LIT>" : <EOL> executables [ '<STR_LIT>' ] = [ "<STR_LIT>" ] <EOL> src_extensions = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> obj_extension = "<STR_LIT>" <EOL> static_lib_extension = "<STR_LIT>" <EOL> shared_lib_extension = "<STR_LIT>" <EOL> dylib_lib_extension = "<STR_LIT>" <EOL> static_lib_format = shared_lib_format = dylib_lib_format = "<STR_LIT>" <EOL> if sys . platform == "<STR_LIT>" : <EOL> exe_extension = "<STR_LIT>" <EOL> def preprocess ( self , source , <EOL> output_file = None , macros = None , include_dirs = None , <EOL> extra_preargs = None , extra_postargs = None ) : <EOL> ignore , macros , include_dirs = self . _fix_compile_args ( None , macros , include_dirs ) <EOL> pp_opts = gen_preprocess_options ( macros , include_dirs ) <EOL> pp_args = self . preprocessor + pp_opts <EOL> if output_file : <EOL> pp_args . extend ( [ '<STR_LIT>' , output_file ] ) <EOL> if extra_preargs : <EOL> pp_args [ : <NUM_LIT:0> ] = extra_preargs <EOL> if extra_postargs : <EOL> pp_args . extend ( extra_postargs ) <EOL> pp_args . append ( source ) <EOL> if self . force or output_file is None or newer ( source , output_file ) : <EOL> if output_file : <EOL> self . mkpath ( os . path . dirname ( output_file ) ) <EOL> try : <EOL> self . spawn ( pp_args ) <EOL> except DistutilsExecError , msg : <EOL> raise CompileError , msg <EOL> def _compile ( self , obj , src , ext , cc_args , extra_postargs , pp_opts ) : <EOL> compiler_so = self . compiler_so <EOL> if sys . platform == '<STR_LIT>' : <EOL> compiler_so = _darwin_compiler_fixup ( compiler_so , cc_args + extra_postargs ) <EOL> try : <EOL> self . spawn ( compiler_so + cc_args + [ src , '<STR_LIT>' , obj ] + <EOL> extra_postargs ) <EOL> except DistutilsExecError , msg : <EOL> raise CompileError , msg <EOL> def create_static_lib ( self , objects , output_libname , <EOL> output_dir = None , debug = <NUM_LIT:0> , target_lang = None ) : <EOL> objects , output_dir = self . _fix_object_args ( objects , output_dir ) <EOL> output_filename = self . library_filename ( output_libname , output_dir = output_dir ) <EOL> if self . _need_link ( objects , output_filename ) : <EOL> self . mkpath ( os . path . dirname ( output_filename ) ) <EOL> self . spawn ( self . archiver + <EOL> [ output_filename ] + <EOL> objects + self . objects ) <EOL> if self . ranlib : <EOL> try : <EOL> self . spawn ( self . ranlib + [ output_filename ] ) <EOL> except DistutilsExecError , msg : <EOL> raise LibError , msg <EOL> else : <EOL> log . debug ( "<STR_LIT>" , output_filename ) <EOL> def link ( self , target_desc , objects , <EOL> output_filename , output_dir = None , libraries = None , <EOL> library_dirs = None , runtime_library_dirs = None , <EOL> export_symbols = None , debug = <NUM_LIT:0> , extra_preargs = None , <EOL> extra_postargs = None , build_temp = None , target_lang = None ) : <EOL> objects , output_dir = self . _fix_object_args ( objects , output_dir ) <EOL> libraries , library_dirs , runtime_library_dirs = self . _fix_lib_args ( libraries , library_dirs , runtime_library_dirs ) <EOL> lib_opts = gen_lib_options ( self , library_dirs , runtime_library_dirs , <EOL> libraries ) <EOL> if type ( output_dir ) not in ( StringType , NoneType ) : <EOL> raise TypeError , "<STR_LIT>" <EOL> if output_dir is not None : <EOL> output_filename = os . path . join ( output_dir , output_filename ) <EOL> if self . _need_link ( objects , output_filename ) : <EOL> ld_args = ( objects + self . objects + <EOL> lib_opts + [ '<STR_LIT>' , output_filename ] ) <EOL> if debug : <EOL> ld_args [ : <NUM_LIT:0> ] = [ '<STR_LIT>' ] <EOL> if extra_preargs : <EOL> ld_args [ : <NUM_LIT:0> ] = extra_preargs <EOL> if extra_postargs : <EOL> ld_args . extend ( extra_postargs ) <EOL> self . mkpath ( os . path . dirname ( output_filename ) ) <EOL> try : <EOL> if target_desc == CCompiler . EXECUTABLE : <EOL> linker = self . linker_exe [ : ] <EOL> else : <EOL> linker = self . linker_so [ : ] <EOL> if target_lang == "<STR_LIT>" and self . compiler_cxx : <EOL> i = <NUM_LIT:0> <EOL> if os . path . basename ( linker [ <NUM_LIT:0> ] ) == "<STR_LIT>" : <EOL> i = <NUM_LIT:1> <EOL> while '<STR_LIT:=>' in linker [ i ] : <EOL> i = i + <NUM_LIT:1> <EOL> linker [ i ] = self . compiler_cxx [ i ] <EOL> if sys . platform == '<STR_LIT>' : <EOL> linker = _darwin_compiler_fixup ( linker , ld_args ) <EOL> self . spawn ( linker + ld_args ) <EOL> except DistutilsExecError , msg : <EOL> raise LinkError , msg <EOL> else : <EOL> log . debug ( "<STR_LIT>" , output_filename ) <EOL> def library_dir_option ( self , dir ) : <EOL> return "<STR_LIT>" + dir <EOL> def _is_gcc ( self , compiler_name ) : <EOL> return "<STR_LIT>" in compiler_name or "<STR_LIT>" in compiler_name <EOL> def runtime_library_dir_option ( self , dir ) : <EOL> compiler = os . path . basename ( sysconfig . get_config_var ( "<STR_LIT>" ) ) <EOL> if sys . platform [ : <NUM_LIT:6> ] == "<STR_LIT>" : <EOL> return "<STR_LIT>" + dir <EOL> elif sys . platform [ : <NUM_LIT:5> ] == "<STR_LIT>" : <EOL> if self . _is_gcc ( compiler ) : <EOL> return [ "<STR_LIT>" , "<STR_LIT>" + dir ] <EOL> return [ "<STR_LIT>" , "<STR_LIT>" + dir ] <EOL> elif sys . platform [ : <NUM_LIT:7> ] == "<STR_LIT>" or sys . platform [ : <NUM_LIT:6> ] == "<STR_LIT>" : <EOL> return [ "<STR_LIT>" , dir ] <EOL> elif self . _is_gcc ( compiler ) : <EOL> return "<STR_LIT>" + dir <EOL> else : <EOL> return "<STR_LIT>" + dir <EOL> def library_option ( self , lib ) : <EOL> return "<STR_LIT>" + lib <EOL> def find_library_file ( self , dirs , lib , debug = <NUM_LIT:0> ) : <EOL> shared_f = self . library_filename ( lib , lib_type = '<STR_LIT>' ) <EOL> dylib_f = self . library_filename ( lib , lib_type = '<STR_LIT>' ) <EOL> static_f = self . library_filename ( lib , lib_type = '<STR_LIT>' ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> cflags = sysconfig . get_config_var ( '<STR_LIT>' ) <EOL> m = re . search ( r'<STR_LIT>' , cflags ) <EOL> if m is None : <EOL> sysroot = '<STR_LIT:/>' <EOL> else : <EOL> sysroot = m . group ( <NUM_LIT:1> ) <EOL> for dir in dirs : <EOL> shared = os . path . join ( dir , shared_f ) <EOL> dylib = os . path . join ( dir , dylib_f ) <EOL> static = os . path . join ( dir , static_f ) <EOL> if sys . platform == '<STR_LIT>' and ( <EOL> dir . startswith ( '<STR_LIT>' ) or ( <EOL> dir . startswith ( '<STR_LIT>' ) and not dir . startswith ( '<STR_LIT>' ) ) ) : <EOL> shared = os . path . join ( sysroot , dir [ <NUM_LIT:1> : ] , shared_f ) <EOL> dylib = os . path . join ( sysroot , dir [ <NUM_LIT:1> : ] , dylib_f ) <EOL> static = os . path . join ( sysroot , dir [ <NUM_LIT:1> : ] , static_f ) <EOL> if os . path . exists ( dylib ) : <EOL> return dylib <EOL> elif os . path . exists ( shared ) : <EOL> return shared <EOL> elif os . path . exists ( static ) : <EOL> return static <EOL> return None </s>
