<s> """<STR_LIT>""" <EOL> import re <EOL> from types import IntType <EOL> LogInputFiles = <NUM_LIT:1> <EOL> LogErrorMessages = <NUM_LIT:1> <EOL> def CheckBuilder ( context , text = None , language = None ) : <EOL> """<STR_LIT>""" <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> context . Display ( "<STR_LIT>" % msg ) <EOL> return msg <EOL> if not text : <EOL> text = """<STR_LIT>""" <EOL> context . Display ( "<STR_LIT>" % lang ) <EOL> ret = context . BuildProg ( text , suffix ) <EOL> _YesNoResult ( context , ret , None , text ) <EOL> return ret <EOL> def CheckCC ( context ) : <EOL> """<STR_LIT>""" <EOL> context . Display ( "<STR_LIT>" ) <EOL> text = """<STR_LIT>""" <EOL> ret = _check_empty_program ( context , '<STR_LIT>' , text , '<STR_LIT:C>' ) <EOL> _YesNoResult ( context , ret , None , text ) <EOL> return ret <EOL> def CheckSHCC ( context ) : <EOL> """<STR_LIT>""" <EOL> context . Display ( "<STR_LIT>" ) <EOL> text = """<STR_LIT>""" <EOL> ret = _check_empty_program ( context , '<STR_LIT>' , text , '<STR_LIT:C>' , use_shared = True ) <EOL> _YesNoResult ( context , ret , None , text ) <EOL> return ret <EOL> def CheckCXX ( context ) : <EOL> """<STR_LIT>""" <EOL> context . Display ( "<STR_LIT>" ) <EOL> text = """<STR_LIT>""" <EOL> ret = _check_empty_program ( context , '<STR_LIT>' , text , '<STR_LIT>' ) <EOL> _YesNoResult ( context , ret , None , text ) <EOL> return ret <EOL> def CheckSHCXX ( context ) : <EOL> """<STR_LIT>""" <EOL> context . Display ( "<STR_LIT>" ) <EOL> text = """<STR_LIT>""" <EOL> ret = _check_empty_program ( context , '<STR_LIT>' , text , '<STR_LIT>' , use_shared = True ) <EOL> _YesNoResult ( context , ret , None , text ) <EOL> return ret <EOL> def _check_empty_program ( context , comp , text , language , use_shared = False ) : <EOL> """<STR_LIT>""" <EOL> if comp not in context . env or not context . env [ comp ] : <EOL> return <NUM_LIT:1> <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> return <NUM_LIT:1> <EOL> if use_shared : <EOL> return context . CompileSharedObject ( text , suffix ) <EOL> else : <EOL> return context . CompileProg ( text , suffix ) <EOL> def CheckFunc ( context , function_name , header = None , language = None ) : <EOL> """<STR_LIT>""" <EOL> if context . headerfilename : <EOL> includetext = '<STR_LIT>' % context . headerfilename <EOL> else : <EOL> includetext = '<STR_LIT>' <EOL> if not header : <EOL> header = """<STR_LIT>""" % function_name <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> context . Display ( "<STR_LIT>" % ( function_name , msg ) ) <EOL> return msg <EOL> text = """<STR_LIT>""" % { '<STR_LIT:name>' : function_name , <EOL> '<STR_LIT>' : includetext , <EOL> '<STR_LIT>' : header } <EOL> context . Display ( "<STR_LIT>" % ( lang , function_name ) ) <EOL> ret = context . BuildProg ( text , suffix ) <EOL> _YesNoResult ( context , ret , "<STR_LIT>" + function_name , text , <EOL> "<STR_LIT>" % function_name ) <EOL> return ret <EOL> def CheckHeader ( context , header_name , header = None , language = None , <EOL> include_quotes = None ) : <EOL> """<STR_LIT>""" <EOL> if context . headerfilename : <EOL> includetext = '<STR_LIT>' % context . headerfilename <EOL> else : <EOL> includetext = '<STR_LIT>' <EOL> if not header : <EOL> header = "<STR_LIT>" <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> context . Display ( "<STR_LIT>" <EOL> % ( header_name , msg ) ) <EOL> return msg <EOL> if not include_quotes : <EOL> include_quotes = "<STR_LIT>" <EOL> text = "<STR_LIT>" % ( includetext , header , <EOL> include_quotes [ <NUM_LIT:0> ] , header_name , include_quotes [ <NUM_LIT:1> ] ) <EOL> context . Display ( "<STR_LIT>" % ( lang , header_name ) ) <EOL> ret = context . CompileProg ( text , suffix ) <EOL> _YesNoResult ( context , ret , "<STR_LIT>" + header_name , text , <EOL> "<STR_LIT>" % header_name ) <EOL> return ret <EOL> def CheckType ( context , type_name , fallback = None , <EOL> header = None , language = None ) : <EOL> """<STR_LIT>""" <EOL> if context . headerfilename : <EOL> includetext = '<STR_LIT>' % context . headerfilename <EOL> else : <EOL> includetext = '<STR_LIT>' <EOL> if not header : <EOL> header = "<STR_LIT>" <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> context . Display ( "<STR_LIT>" % ( type_name , msg ) ) <EOL> return msg <EOL> text = """<STR_LIT>""" % { '<STR_LIT>' : includetext , <EOL> '<STR_LIT>' : header , <EOL> '<STR_LIT:name>' : type_name } <EOL> context . Display ( "<STR_LIT>" % ( lang , type_name ) ) <EOL> ret = context . BuildProg ( text , suffix ) <EOL> _YesNoResult ( context , ret , "<STR_LIT>" + type_name , text , <EOL> "<STR_LIT>" % type_name ) <EOL> if ret and fallback and context . headerfilename : <EOL> f = open ( context . headerfilename , "<STR_LIT:a>" ) <EOL> f . write ( "<STR_LIT>" % ( fallback , type_name ) ) <EOL> f . close ( ) <EOL> return ret <EOL> def CheckTypeSize ( context , type_name , header = None , language = None , expect = None ) : <EOL> """<STR_LIT>""" <EOL> if context . headerfilename : <EOL> includetext = '<STR_LIT>' % context . headerfilename <EOL> else : <EOL> includetext = '<STR_LIT>' <EOL> if not header : <EOL> header = "<STR_LIT>" <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> context . Display ( "<STR_LIT>" % ( type_name , msg ) ) <EOL> return msg <EOL> src = includetext + header <EOL> if not expect is None : <EOL> context . Display ( '<STR_LIT>' % ( type_name , expect ) ) <EOL> src = src + r"""<STR_LIT>""" <EOL> st = context . CompileProg ( src % ( type_name , expect ) , suffix ) <EOL> if not st : <EOL> context . Display ( "<STR_LIT>" ) <EOL> _Have ( context , "<STR_LIT>" % type_name , expect , <EOL> "<STR_LIT>" % type_name ) <EOL> return expect <EOL> else : <EOL> context . Display ( "<STR_LIT>" ) <EOL> _LogFailed ( context , src , st ) <EOL> return <NUM_LIT:0> <EOL> else : <EOL> context . Message ( '<STR_LIT>' % type_name ) <EOL> src = src + """<STR_LIT>""" + type_name + """<STR_LIT>""" <EOL> st , out = context . RunProg ( src , suffix ) <EOL> try : <EOL> size = int ( out ) <EOL> except ValueError : <EOL> st = <NUM_LIT:1> <EOL> size = <NUM_LIT:0> <EOL> if not st : <EOL> context . Display ( "<STR_LIT>" ) <EOL> _Have ( context , "<STR_LIT>" % type_name , size , <EOL> "<STR_LIT>" % type_name ) <EOL> return size <EOL> else : <EOL> context . Display ( "<STR_LIT>" ) <EOL> _LogFailed ( context , src , st ) <EOL> return <NUM_LIT:0> <EOL> return <NUM_LIT:0> <EOL> def CheckDeclaration ( context , symbol , includes = None , language = None ) : <EOL> """<STR_LIT>""" <EOL> if context . headerfilename : <EOL> includetext = '<STR_LIT>' % context . headerfilename <EOL> else : <EOL> includetext = '<STR_LIT>' <EOL> if not includes : <EOL> includes = "<STR_LIT>" <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> context . Display ( "<STR_LIT>" % ( symbol , msg ) ) <EOL> return msg <EOL> src = includetext + includes <EOL> context . Display ( '<STR_LIT>' % symbol ) <EOL> src = src + r"""<STR_LIT>""" % ( symbol , symbol ) <EOL> st = context . CompileProg ( src , suffix ) <EOL> _YesNoResult ( context , st , "<STR_LIT>" + symbol , src , <EOL> "<STR_LIT>" % symbol ) <EOL> return st <EOL> def CheckLib ( context , libs , func_name = None , header = None , <EOL> extra_libs = None , call = None , language = None , autoadd = <NUM_LIT:1> , <EOL> append = True ) : <EOL> """<STR_LIT>""" <EOL> if context . headerfilename : <EOL> includetext = '<STR_LIT>' % context . headerfilename <EOL> else : <EOL> includetext = '<STR_LIT>' <EOL> if not header : <EOL> header = "<STR_LIT>" <EOL> text = """<STR_LIT>""" % ( includetext , header ) <EOL> if func_name and func_name != "<STR_LIT>" : <EOL> if not header : <EOL> text = text + """<STR_LIT>""" % func_name <EOL> if not call : <EOL> call = "<STR_LIT>" % func_name <EOL> text = text + """<STR_LIT>""" % ( call or "<STR_LIT>" ) <EOL> if call : <EOL> i = call . find ( "<STR_LIT:\n>" ) <EOL> if i > <NUM_LIT:0> : <EOL> calltext = call [ : i ] + "<STR_LIT:..>" <EOL> elif call [ - <NUM_LIT:1> ] == '<STR_LIT:;>' : <EOL> calltext = call [ : - <NUM_LIT:1> ] <EOL> else : <EOL> calltext = call <EOL> for lib_name in libs : <EOL> lang , suffix , msg = _lang2suffix ( language ) <EOL> if msg : <EOL> context . Display ( "<STR_LIT>" % ( lib_name , msg ) ) <EOL> return msg <EOL> if call : <EOL> context . Display ( "<STR_LIT>" <EOL> % ( calltext , lang , lib_name ) ) <EOL> else : <EOL> context . Display ( "<STR_LIT>" <EOL> % ( lang , lib_name ) ) <EOL> if lib_name : <EOL> l = [ lib_name ] <EOL> if extra_libs : <EOL> l . extend ( extra_libs ) <EOL> if append : <EOL> oldLIBS = context . AppendLIBS ( l ) <EOL> else : <EOL> oldLIBS = context . PrependLIBS ( l ) <EOL> sym = "<STR_LIT>" + lib_name <EOL> else : <EOL> oldLIBS = - <NUM_LIT:1> <EOL> sym = None <EOL> ret = context . BuildProg ( text , suffix ) <EOL> _YesNoResult ( context , ret , sym , text , <EOL> "<STR_LIT>" % lib_name ) <EOL> if oldLIBS != - <NUM_LIT:1> and ( ret or not autoadd ) : <EOL> context . SetLIBS ( oldLIBS ) <EOL> if not ret : <EOL> return ret <EOL> return ret <EOL> def _YesNoResult ( context , ret , key , text , comment = None ) : <EOL> """<STR_LIT>""" <EOL> if key : <EOL> _Have ( context , key , not ret , comment ) <EOL> if ret : <EOL> context . Display ( "<STR_LIT>" ) <EOL> _LogFailed ( context , text , ret ) <EOL> else : <EOL> context . Display ( "<STR_LIT>" ) <EOL> def _Have ( context , key , have , comment = None ) : <EOL> """<STR_LIT>""" <EOL> key_up = key . upper ( ) <EOL> key_up = re . sub ( '<STR_LIT>' , '<STR_LIT:_>' , key_up ) <EOL> context . havedict [ key_up ] = have <EOL> if have == <NUM_LIT:1> : <EOL> line = "<STR_LIT>" % key_up <EOL> elif have == <NUM_LIT:0> : <EOL> line = "<STR_LIT>" % key_up <EOL> elif isinstance ( have , IntType ) : <EOL> line = "<STR_LIT>" % ( key_up , have ) <EOL> else : <EOL> line = "<STR_LIT>" % ( key_up , str ( have ) ) <EOL> if comment is not None : <EOL> lines = "<STR_LIT>" % comment + line <EOL> else : <EOL> lines = "<STR_LIT:\n>" + line <EOL> if context . headerfilename : <EOL> f = open ( context . headerfilename , "<STR_LIT:a>" ) <EOL> f . write ( lines ) <EOL> f . close ( ) <EOL> elif hasattr ( context , '<STR_LIT>' ) : <EOL> context . config_h = context . config_h + lines <EOL> def _LogFailed ( context , text , msg ) : <EOL> """<STR_LIT>""" <EOL> if LogInputFiles : <EOL> context . Log ( "<STR_LIT>" ) <EOL> lines = text . split ( '<STR_LIT:\n>' ) <EOL> if len ( lines ) and lines [ - <NUM_LIT:1> ] == '<STR_LIT>' : <EOL> lines = lines [ : - <NUM_LIT:1> ] <EOL> n = <NUM_LIT:1> <EOL> for line in lines : <EOL> context . Log ( "<STR_LIT>" % ( n , line ) ) <EOL> n = n + <NUM_LIT:1> <EOL> if LogErrorMessages : <EOL> context . Log ( "<STR_LIT>" % msg ) <EOL> def _lang2suffix ( lang ) : <EOL> """<STR_LIT>""" <EOL> if not lang or lang in [ "<STR_LIT:C>" , "<STR_LIT:c>" ] : <EOL> return ( "<STR_LIT:C>" , "<STR_LIT>" , None ) <EOL> if lang in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> return ( "<STR_LIT>" , "<STR_LIT>" , None ) <EOL> return None , None , "<STR_LIT>" % lang </s>
