<s> import copy <EOL> def check_compiler ( conf , msg = None ) : <EOL> code = """<STR_LIT>""" <EOL> if msg is None : <EOL> conf . start_message ( "<STR_LIT>" ) <EOL> else : <EOL> conf . start_message ( msg ) <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_program ( "<STR_LIT>" , code , None ) <EOL> if ret : <EOL> conf . end_message ( "<STR_LIT:yes>" ) <EOL> else : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> return ret <EOL> def check_cpp_symbol ( conf , symbol , headers = None ) : <EOL> code = [ ] <EOL> if headers : <EOL> for h in headers : <EOL> code . append ( r"<STR_LIT>" % h ) <EOL> code . append ( r"""<STR_LIT>""" % ( symbol , symbol ) ) <EOL> src = "<STR_LIT:\n>" . join ( code ) <EOL> conf . start_message ( "<STR_LIT>" % symbol ) <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_compile ( "<STR_LIT>" , src , headers ) <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:value>" : symbol , <EOL> "<STR_LIT:result>" : ret } ) <EOL> if ret : <EOL> conf . end_message ( "<STR_LIT:yes>" ) <EOL> else : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> return ret <EOL> def check_type ( conf , type_name , headers = None ) : <EOL> code = r"""<STR_LIT>""" % { '<STR_LIT:name>' : type_name } <EOL> conf . start_message ( "<STR_LIT>" % type_name ) <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_compile ( "<STR_LIT>" , code , <EOL> headers ) <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT:type>" , "<STR_LIT:value>" : type_name , <EOL> "<STR_LIT:result>" : ret } ) <EOL> if ret : <EOL> conf . end_message ( "<STR_LIT:yes>" ) <EOL> else : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> return ret <EOL> def check_type_size ( conf , type_name , headers = None , expect = None ) : <EOL> """<STR_LIT>""" <EOL> conf . start_message ( "<STR_LIT>" % type_name ) <EOL> body = r"""<STR_LIT>""" % { "<STR_LIT:type>" : type_name } <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_compile ( "<STR_LIT>" , body , headers ) <EOL> if not ret : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> return False <EOL> if expect is None : <EOL> body = r"""<STR_LIT>""" <EOL> low = <NUM_LIT:0> <EOL> mid = <NUM_LIT:0> <EOL> while True : <EOL> code = body % { '<STR_LIT:type>' : type_name , '<STR_LIT:size>' : mid } <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_compile ( "<STR_LIT>" , <EOL> code , headers ) <EOL> if ret : <EOL> break <EOL> low = mid + <NUM_LIT:1> <EOL> mid = <NUM_LIT:2> * mid + <NUM_LIT:1> <EOL> high = mid <EOL> while low != high : <EOL> mid = ( high - low ) / <NUM_LIT:2> + low <EOL> code = body % { '<STR_LIT:type>' : type_name , '<STR_LIT:size>' : mid } <EOL> if conf . builders [ "<STR_LIT>" ] . try_compile ( "<STR_LIT>" , <EOL> code , headers ) : <EOL> high = mid <EOL> else : <EOL> low = mid + <NUM_LIT:1> <EOL> ret = low <EOL> size = low <EOL> conf . end_message ( "<STR_LIT>" % low ) <EOL> else : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:value>" : type_name , <EOL> "<STR_LIT:result>" : ret } ) <EOL> return ret <EOL> def define ( conf , name , value = None , comment = None ) : <EOL> """<STR_LIT>""" <EOL> lines = [ ] <EOL> if comment : <EOL> comment_str = "<STR_LIT>" % comment <EOL> lines . append ( comment_str ) <EOL> else : <EOL> lines . append ( "<STR_LIT:\n>" ) <EOL> if value is not None : <EOL> define_str = "<STR_LIT>" % ( name , value ) <EOL> else : <EOL> define_str = "<STR_LIT>" % name <EOL> lines . append ( define_str ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> content = "<STR_LIT:\n>" . join ( lines ) <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:value>" : content , <EOL> "<STR_LIT:result>" : True } ) <EOL> def check_header ( conf , header ) : <EOL> code = r"""<STR_LIT>""" % header <EOL> conf . start_message ( "<STR_LIT>" % header ) <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_compile ( "<STR_LIT>" , code , None ) <EOL> if ret : <EOL> conf . end_message ( "<STR_LIT:yes>" ) <EOL> else : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:value>" : header , <EOL> "<STR_LIT:result>" : ret } ) <EOL> return ret <EOL> def check_func ( conf , func , libs = None ) : <EOL> if libs is None : <EOL> libs = [ ] <EOL> code = r"""<STR_LIT>""" % { "<STR_LIT>" : func } <EOL> if libs : <EOL> msg = "<STR_LIT>" % ( func , "<STR_LIT:U+0020>" . join ( [ conf . env [ "<STR_LIT>" ] % lib for lib in libs ] ) ) <EOL> else : <EOL> msg = "<STR_LIT>" % func <EOL> conf . start_message ( msg ) <EOL> old_lib = copy . deepcopy ( conf . env [ "<STR_LIT>" ] ) <EOL> try : <EOL> for lib in libs [ : : - <NUM_LIT:1> ] : <EOL> conf . env [ "<STR_LIT>" ] . insert ( <NUM_LIT:0> , lib ) <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_program ( "<STR_LIT>" , code , None ) <EOL> if ret : <EOL> conf . end_message ( "<STR_LIT:yes>" ) <EOL> else : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> finally : <EOL> conf . env [ "<STR_LIT>" ] = old_lib <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:value>" : func , <EOL> "<STR_LIT:result>" : ret } ) <EOL> return ret <EOL> def check_lib ( conf , libs , func ) : <EOL> code = r"""<STR_LIT>""" % { "<STR_LIT>" : func } <EOL> conf . start_message ( "<STR_LIT>" % ( func , "<STR_LIT:U+0020>" . join ( [ conf . env [ "<STR_LIT>" ] % lib for lib in libs ] ) ) ) <EOL> old_lib = copy . deepcopy ( conf . env [ "<STR_LIT>" ] ) <EOL> try : <EOL> for i in range ( len ( libs ) ) : <EOL> conf . env [ "<STR_LIT>" ] . insert ( i , libs [ i ] ) <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_program ( "<STR_LIT>" , code , None ) <EOL> if ret : <EOL> conf . end_message ( "<STR_LIT:yes>" ) <EOL> else : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> finally : <EOL> conf . env [ "<STR_LIT>" ] = old_lib <EOL> for lib in libs : <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:value>" : lib , <EOL> "<STR_LIT:result>" : ret , "<STR_LIT>" : func } ) <EOL> return ret <EOL> def check_funcs_at_once ( conf , funcs , libs = None ) : <EOL> if libs is None : <EOL> libs = [ ] <EOL> header = [ ] <EOL> header = [ '<STR_LIT>' ] <EOL> header . append ( '<STR_LIT>' ) <EOL> header . append ( '<STR_LIT>' ) <EOL> for f in funcs : <EOL> header . append ( "<STR_LIT>" % f ) <EOL> header . append ( "<STR_LIT>" ) <EOL> header . append ( "<STR_LIT>" % f ) <EOL> header . append ( "<STR_LIT>" ) <EOL> header . append ( '<STR_LIT>' ) <EOL> header . append ( '<STR_LIT>' ) <EOL> header . append ( '<STR_LIT>' ) <EOL> header = "<STR_LIT:\n>" . join ( header ) <EOL> tmp = [ ] <EOL> for f in funcs : <EOL> tmp . append ( "<STR_LIT>" % f ) <EOL> tmp = "<STR_LIT:\n>" . join ( tmp ) <EOL> body = r"""<STR_LIT>""" % { "<STR_LIT>" : tmp , "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : header } <EOL> conf . start_message ( "<STR_LIT>" % "<STR_LIT:U+002CU+0020>" . join ( funcs ) ) <EOL> old_lib = copy . deepcopy ( conf . env [ "<STR_LIT>" ] ) <EOL> try : <EOL> for lib in libs [ : : - <NUM_LIT:1> ] : <EOL> conf . env [ "<STR_LIT>" ] . insert ( <NUM_LIT:0> , lib ) <EOL> ret = conf . builders [ "<STR_LIT>" ] . try_program ( "<STR_LIT>" , body , None ) <EOL> if ret : <EOL> conf . end_message ( "<STR_LIT:yes>" ) <EOL> else : <EOL> conf . end_message ( "<STR_LIT>" ) <EOL> finally : <EOL> conf . env [ "<STR_LIT>" ] = old_lib <EOL> for func in funcs : <EOL> conf . conf_results . append ( { "<STR_LIT:type>" : "<STR_LIT>" , "<STR_LIT:value>" : func , <EOL> "<STR_LIT:result>" : ret } ) <EOL> return ret </s>
