<s> """<STR_LIT>""" <EOL> __revision__ = "<STR_LIT>" <EOL> import os , sys , copy <EOL> from distutils . ccompiler import gen_preprocess_options , gen_lib_options <EOL> from distutils . unixccompiler import UnixCCompiler <EOL> from distutils . file_util import write_file <EOL> from distutils . errors import DistutilsExecError , CompileError , UnknownFileError <EOL> from distutils import log <EOL> class CygwinCCompiler ( UnixCCompiler ) : <EOL> compiler_type = '<STR_LIT>' <EOL> obj_extension = "<STR_LIT>" <EOL> static_lib_extension = "<STR_LIT>" <EOL> shared_lib_extension = "<STR_LIT>" <EOL> static_lib_format = "<STR_LIT>" <EOL> shared_lib_format = "<STR_LIT>" <EOL> exe_extension = "<STR_LIT>" <EOL> def __init__ ( self , verbose = <NUM_LIT:0> , dry_run = <NUM_LIT:0> , force = <NUM_LIT:0> ) : <EOL> UnixCCompiler . __init__ ( self , verbose , dry_run , force ) <EOL> ( status , details ) = check_config_h ( ) <EOL> self . debug_print ( "<STR_LIT>" % <EOL> ( status , details ) ) <EOL> if status is not CONFIG_H_OK : <EOL> self . warn ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % details ) <EOL> self . gcc_version , self . ld_version , self . dllwrap_version = get_versions ( ) <EOL> self . debug_print ( self . compiler_type + "<STR_LIT>" % <EOL> ( self . gcc_version , <EOL> self . ld_version , <EOL> self . dllwrap_version ) ) <EOL> if self . ld_version >= "<STR_LIT>" : <EOL> self . linker_dll = "<STR_LIT>" <EOL> else : <EOL> self . linker_dll = "<STR_LIT>" <EOL> if self . ld_version >= "<STR_LIT>" : <EOL> shared_option = "<STR_LIT>" <EOL> else : <EOL> shared_option = "<STR_LIT>" <EOL> self . set_executables ( compiler = '<STR_LIT>' , <EOL> compiler_so = '<STR_LIT>' , <EOL> compiler_cxx = '<STR_LIT>' , <EOL> linker_exe = '<STR_LIT>' , <EOL> linker_so = ( '<STR_LIT>' % <EOL> ( self . linker_dll , shared_option ) ) ) <EOL> if self . gcc_version == "<STR_LIT>" : <EOL> self . dll_libraries = [ "<STR_LIT>" ] <EOL> self . warn ( <EOL> "<STR_LIT>" ) <EOL> else : <EOL> self . dll_libraries = [ ] <EOL> msc_pos = sys . version . find ( '<STR_LIT>' ) <EOL> if msc_pos != - <NUM_LIT:1> : <EOL> msc_ver = sys . version [ msc_pos + <NUM_LIT:6> : msc_pos + <NUM_LIT:10> ] <EOL> if msc_ver == '<STR_LIT>' : <EOL> self . dll_libraries = [ '<STR_LIT>' ] <EOL> elif msc_ver == '<STR_LIT>' : <EOL> self . dll_libraries = [ '<STR_LIT>' ] <EOL> def _compile ( self , obj , src , ext , cc_args , extra_postargs , pp_opts ) : <EOL> if ext == '<STR_LIT>' or ext == '<STR_LIT>' : <EOL> try : <EOL> self . spawn ( [ "<STR_LIT>" , "<STR_LIT>" , src , "<STR_LIT>" , obj ] ) <EOL> except DistutilsExecError , msg : <EOL> raise CompileError , msg <EOL> else : <EOL> try : <EOL> self . spawn ( self . compiler_so + cc_args + [ src , '<STR_LIT>' , obj ] + <EOL> extra_postargs ) <EOL> except DistutilsExecError , msg : <EOL> raise CompileError , msg <EOL> def link ( self , <EOL> target_desc , <EOL> objects , <EOL> output_filename , <EOL> output_dir = None , <EOL> libraries = None , <EOL> library_dirs = None , <EOL> runtime_library_dirs = None , <EOL> export_symbols = None , <EOL> debug = <NUM_LIT:0> , <EOL> extra_preargs = None , <EOL> extra_postargs = None , <EOL> build_temp = None , <EOL> target_lang = None ) : <EOL> extra_preargs = copy . copy ( extra_preargs or [ ] ) <EOL> libraries = copy . copy ( libraries or [ ] ) <EOL> objects = copy . copy ( objects or [ ] ) <EOL> libraries . extend ( self . dll_libraries ) <EOL> if ( ( export_symbols is not None ) and <EOL> ( target_desc != self . EXECUTABLE or self . linker_dll == "<STR_LIT>" ) ) : <EOL> temp_dir = os . path . dirname ( objects [ <NUM_LIT:0> ] ) <EOL> ( dll_name , dll_extension ) = os . path . splitext ( <EOL> os . path . basename ( output_filename ) ) <EOL> def_file = os . path . join ( temp_dir , dll_name + "<STR_LIT>" ) <EOL> lib_file = os . path . join ( temp_dir , '<STR_LIT>' + dll_name + "<STR_LIT>" ) <EOL> contents = [ <EOL> "<STR_LIT>" % os . path . basename ( output_filename ) , <EOL> "<STR_LIT>" ] <EOL> for sym in export_symbols : <EOL> contents . append ( sym ) <EOL> self . execute ( write_file , ( def_file , contents ) , <EOL> "<STR_LIT>" % def_file ) <EOL> if self . linker_dll == "<STR_LIT>" : <EOL> extra_preargs . extend ( [ "<STR_LIT>" , lib_file ] ) <EOL> extra_preargs . extend ( [ "<STR_LIT>" , def_file ] ) <EOL> else : <EOL> objects . append ( def_file ) <EOL> if not debug : <EOL> extra_preargs . append ( "<STR_LIT>" ) <EOL> UnixCCompiler . link ( self , <EOL> target_desc , <EOL> objects , <EOL> output_filename , <EOL> output_dir , <EOL> libraries , <EOL> library_dirs , <EOL> runtime_library_dirs , <EOL> None , <EOL> debug , <EOL> extra_preargs , <EOL> extra_postargs , <EOL> build_temp , <EOL> target_lang ) <EOL> def object_filenames ( self , <EOL> source_filenames , <EOL> strip_dir = <NUM_LIT:0> , <EOL> output_dir = '<STR_LIT>' ) : <EOL> if output_dir is None : output_dir = '<STR_LIT>' <EOL> obj_names = [ ] <EOL> for src_name in source_filenames : <EOL> ( base , ext ) = os . path . splitext ( os . path . normcase ( src_name ) ) <EOL> if ext not in ( self . src_extensions + [ '<STR_LIT>' , '<STR_LIT>' ] ) : <EOL> raise UnknownFileError , "<STR_LIT>" % ( ext , src_name ) <EOL> if strip_dir : <EOL> base = os . path . basename ( base ) <EOL> if ext == '<STR_LIT>' or ext == '<STR_LIT>' : <EOL> obj_names . append ( os . path . join ( output_dir , <EOL> base + ext + self . obj_extension ) ) <EOL> else : <EOL> obj_names . append ( os . path . join ( output_dir , <EOL> base + self . obj_extension ) ) <EOL> return obj_names <EOL> class Mingw32CCompiler ( CygwinCCompiler ) : <EOL> compiler_type = '<STR_LIT>' <EOL> def __init__ ( self , <EOL> verbose = <NUM_LIT:0> , <EOL> dry_run = <NUM_LIT:0> , <EOL> force = <NUM_LIT:0> ) : <EOL> CygwinCCompiler . __init__ ( self , verbose , dry_run , force ) <EOL> if self . ld_version >= "<STR_LIT>" : <EOL> shared_option = "<STR_LIT>" <EOL> else : <EOL> shared_option = "<STR_LIT>" <EOL> if self . gcc_version <= "<STR_LIT>" : <EOL> entry_point = '<STR_LIT>' <EOL> else : <EOL> entry_point = '<STR_LIT>' <EOL> self . set_executables ( compiler = '<STR_LIT>' , <EOL> compiler_so = '<STR_LIT>' , <EOL> compiler_cxx = '<STR_LIT>' , <EOL> linker_exe = '<STR_LIT>' , <EOL> linker_so = '<STR_LIT>' <EOL> % ( self . linker_dll , shared_option , <EOL> entry_point ) ) <EOL> self . dll_libraries = [ ] <EOL> msc_pos = sys . version . find ( '<STR_LIT>' ) <EOL> if msc_pos != - <NUM_LIT:1> : <EOL> msc_ver = sys . version [ msc_pos + <NUM_LIT:6> : msc_pos + <NUM_LIT:10> ] <EOL> if msc_ver == '<STR_LIT>' : <EOL> self . dll_libraries = [ '<STR_LIT>' ] <EOL> elif msc_ver == '<STR_LIT>' : <EOL> self . dll_libraries = [ '<STR_LIT>' ] <EOL> CONFIG_H_OK = "<STR_LIT>" <EOL> CONFIG_H_NOTOK = "<STR_LIT>" <EOL> CONFIG_H_UNCERTAIN = "<STR_LIT>" <EOL> def check_config_h ( ) : <EOL> """<STR_LIT>""" <EOL> from distutils import sysconfig <EOL> import string <EOL> if string . find ( sys . version , "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> return ( CONFIG_H_OK , "<STR_LIT>" ) <EOL> fn = sysconfig . get_config_h_filename ( ) <EOL> try : <EOL> f = open ( fn ) <EOL> s = f . read ( ) <EOL> f . close ( ) <EOL> except IOError , exc : <EOL> return ( CONFIG_H_UNCERTAIN , <EOL> "<STR_LIT>" % ( fn , exc . strerror ) ) <EOL> else : <EOL> if string . find ( s , "<STR_LIT>" ) >= <NUM_LIT:0> : <EOL> return ( CONFIG_H_OK , "<STR_LIT>" % fn ) <EOL> else : <EOL> return ( CONFIG_H_NOTOK , "<STR_LIT>" % fn ) <EOL> def get_versions ( ) : <EOL> """<STR_LIT>""" <EOL> from distutils . version import LooseVersion <EOL> from distutils . spawn import find_executable <EOL> import re <EOL> gcc_exe = find_executable ( '<STR_LIT>' ) <EOL> if gcc_exe : <EOL> out = os . popen ( gcc_exe + '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> out_string = out . read ( ) <EOL> out . close ( ) <EOL> result = re . search ( '<STR_LIT>' , out_string ) <EOL> if result : <EOL> gcc_version = LooseVersion ( result . group ( <NUM_LIT:1> ) ) <EOL> else : <EOL> gcc_version = None <EOL> else : <EOL> gcc_version = None <EOL> ld_exe = find_executable ( '<STR_LIT>' ) <EOL> if ld_exe : <EOL> out = os . popen ( ld_exe + '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> out_string = out . read ( ) <EOL> out . close ( ) <EOL> result = re . search ( '<STR_LIT>' , out_string ) <EOL> if result : <EOL> ld_version = LooseVersion ( result . group ( <NUM_LIT:1> ) ) <EOL> else : <EOL> ld_version = None <EOL> else : <EOL> ld_version = None <EOL> dllwrap_exe = find_executable ( '<STR_LIT>' ) <EOL> if dllwrap_exe : <EOL> out = os . popen ( dllwrap_exe + '<STR_LIT>' , '<STR_LIT:r>' ) <EOL> out_string = out . read ( ) <EOL> out . close ( ) <EOL> result = re . search ( '<STR_LIT>' , out_string ) <EOL> if result : <EOL> dllwrap_version = LooseVersion ( result . group ( <NUM_LIT:1> ) ) <EOL> else : <EOL> dllwrap_version = None <EOL> else : <EOL> dllwrap_version = None <EOL> return ( gcc_version , ld_version , dllwrap_version ) </s>
