Beispiel #1
0
def CHECK_CFLAGS(conf, cflags, fragment='int main(void) { return 0; }\n'):
    '''check if the given cflags are accepted by the compiler
    '''
    check_cflags = TO_LIST(cflags)
    if 'WERROR_CFLAGS' in conf.env:
        check_cflags.extend(conf.env['WERROR_CFLAGS'])
    return conf.check(fragment=fragment,
                      execute=0,
                      type='nolink',
                      ccflags=check_cflags,
                      msg="Checking compiler accepts %s" % cflags)
Beispiel #2
0
def CURRENT_CFLAGS(bld, target, cflags, allow_warnings=False, hide_symbols=False):
    '''work out the current flags. local flags are added first'''
    ret = TO_LIST(cflags)
    if not 'EXTRA_CFLAGS' in bld.env:
        list = []
    else:
        list = bld.env['EXTRA_CFLAGS'];
    ret.extend(list)
    if not allow_warnings and 'PICKY_CFLAGS' in bld.env:
        list = bld.env['PICKY_CFLAGS'];
        ret.extend(list)
    if hide_symbols and bld.env.HAVE_VISIBILITY_ATTR:
        ret.append(bld.env.VISIBILITY_CFLAGS)
    return ret
def CHECK_CODE(conf,
               code,
               define,
               always=False,
               execute=False,
               addmain=True,
               add_headers=True,
               mandatory=False,
               headers=None,
               msg=None,
               cflags='',
               includes='# .',
               local_include=True,
               lib=None,
               link=True,
               define_ret=False,
               quote=False,
               on_target=True,
               strict=False):
    '''check if some code compiles and/or runs'''

    if CONFIG_SET(conf, define):
        return True

    if headers is not None:
        CHECK_HEADERS(conf, headers=headers, lib=lib)

    if add_headers:
        hdrs = header_list(conf, headers=headers, lib=lib)
    else:
        hdrs = ''
    if execute:
        execute = 1
    else:
        execute = 0

    if addmain:
        fragment = '%s\n int main(void) { %s; return 0; }\n' % (hdrs, code)
    else:
        fragment = '%s\n%s\n' % (hdrs, code)

    if msg is None:
        msg = "Checking for %s" % define

    cflags = TO_LIST(cflags)

    # Be strict when relying on a compiler check
    # Some compilers (e.g. xlc) ignore non-supported features as warnings
    if strict:
        if 'WERROR_CFLAGS' in conf.env:
            cflags.extend(conf.env['WERROR_CFLAGS'])

    if local_include:
        cflags.append('-I%s' % conf.path.abspath())

    if not link:
        type = 'nolink'
    else:
        type = 'cprogram'

    uselib = TO_LIST(lib)

    (ccflags, ldflags, cpppath) = library_flags(conf, uselib)

    includes = TO_LIST(includes)
    includes.extend(cpppath)

    uselib = [l.upper() for l in uselib]

    cflags.extend(ccflags)

    if on_target:
        test_args = conf.SAMBA_CROSS_ARGS(msg=msg)
    else:
        test_args = []

    conf.COMPOUND_START(msg)

    try:
        ret = conf.check(fragment=fragment,
                         execute=execute,
                         define_name=define,
                         cflags=cflags,
                         ldflags=ldflags,
                         includes=includes,
                         uselib=uselib,
                         type=type,
                         msg=msg,
                         quote=quote,
                         test_args=test_args,
                         define_ret=define_ret)
    except Exception:
        if always:
            conf.DEFINE(define, 0)
        else:
            conf.undefine(define)
        conf.COMPOUND_END(False)
        if mandatory:
            raise
        return False
    else:
        # Success is indicated by ret but we should unset
        # defines set by WAF's c_config.check() because it
        # defines it to int(ret) and we want to undefine it
        if not ret:
            conf.undefine(define)
            conf.COMPOUND_END(False)
            return False
        if not define_ret:
            conf.DEFINE(define, 1)
            conf.COMPOUND_END(True)
        else:
            conf.DEFINE(define, ret, quote=quote)
            conf.COMPOUND_END(ret)
        return True
Beispiel #4
0
def CHECK_CODE(conf,
               code,
               define,
               always=False,
               execute=False,
               addmain=True,
               add_headers=True,
               mandatory=False,
               headers=None,
               msg=None,
               cflags='',
               includes='# .',
               local_include=True,
               lib=None,
               link=True,
               define_ret=False,
               quote=False,
               on_target=True):
    '''check if some code compiles and/or runs'''

    if CONFIG_SET(conf, define):
        return True

    if headers is not None:
        CHECK_HEADERS(conf, headers=headers, lib=lib)

    if add_headers:
        hdrs = header_list(conf, headers=headers, lib=lib)
    else:
        hdrs = ''
    if execute:
        execute = 1
    else:
        execute = 0

    defs = conf.get_config_header()

    if addmain:
        fragment = '%s\n%s\n int main(void) { %s; return 0; }\n' % (defs, hdrs,
                                                                    code)
    else:
        fragment = '%s\n%s\n%s\n' % (defs, hdrs, code)

    if msg is None:
        msg = "Checking for %s" % define

    cflags = TO_LIST(cflags)

    if local_include:
        cflags.append('-I%s' % conf.curdir)

    if not link:
        type = 'nolink'
    else:
        type = 'cprogram'

    uselib = TO_LIST(lib)

    (ccflags, ldflags, cpppath) = library_flags(conf, uselib)

    includes = TO_LIST(includes)
    includes.extend(cpppath)

    uselib = [l.upper() for l in uselib]

    cflags.extend(ccflags)

    if on_target:
        exec_args = conf.SAMBA_CROSS_ARGS(msg=msg)
    else:
        exec_args = []

    conf.COMPOUND_START(msg)

    ret = conf.check(fragment=fragment,
                     execute=execute,
                     define_name=define,
                     mandatory=mandatory,
                     ccflags=cflags,
                     ldflags=ldflags,
                     includes=includes,
                     uselib=uselib,
                     type=type,
                     msg=msg,
                     quote=quote,
                     exec_args=exec_args,
                     define_ret=define_ret)
    if not ret and CONFIG_SET(conf, define):
        # sometimes conf.check() returns false, but it
        # sets the define. Maybe a waf bug?
        ret = True
    if ret:
        if not define_ret:
            conf.DEFINE(define, 1)
            conf.COMPOUND_END(True)
        else:
            conf.COMPOUND_END(conf.env[define])
        return True
    if always:
        conf.DEFINE(define, 0)
    conf.COMPOUND_END(False)
    return False
Beispiel #5
0
def CHECK_CODE(conf, code, define,
               always=False, execute=False, addmain=True,
               add_headers=True, mandatory=False,
               headers=None, msg=None, cflags='', includes='# .',
               local_include=True, lib=None, link=True,
               define_ret=False, quote=False,
               on_target=True):
    '''check if some code compiles and/or runs'''

    if CONFIG_SET(conf, define):
        return True

    if headers is not None:
        CHECK_HEADERS(conf, headers=headers, lib=lib)

    if add_headers:
        hdrs = header_list(conf, headers=headers, lib=lib)
    else:
        hdrs = ''
    if execute:
        execute = 1
    else:
        execute = 0

    defs = conf.get_config_header()

    if addmain:
        fragment='%s\n%s\n int main(void) { %s; return 0; }\n' % (defs, hdrs, code)
    else:
        fragment='%s\n%s\n%s\n' % (defs, hdrs, code)

    if msg is None:
        msg="Checking for %s" % define

    cflags = TO_LIST(cflags)

    if local_include:
        cflags.append('-I%s' % conf.curdir)

    if not link:
        type='nolink'
    else:
        type='cprogram'

    uselib = TO_LIST(lib)

    (ccflags, ldflags, cpppath) = library_flags(conf, uselib)

    includes = TO_LIST(includes)
    includes.extend(cpppath)

    uselib = [l.upper() for l in uselib]

    cflags.extend(ccflags)

    if on_target:
        exec_args = conf.SAMBA_CROSS_ARGS(msg=msg)
    else:
        exec_args = []

    conf.COMPOUND_START(msg)

    ret = conf.check(fragment=fragment,
                     execute=execute,
                     define_name = define,
                     mandatory = mandatory,
                     ccflags=cflags,
                     ldflags=ldflags,
                     includes=includes,
                     uselib=uselib,
                     type=type,
                     msg=msg,
                     quote=quote,
                     exec_args=exec_args,
                     define_ret=define_ret)
    if not ret and CONFIG_SET(conf, define):
        # sometimes conf.check() returns false, but it
        # sets the define. Maybe a waf bug?
        ret = True
    if ret:
        if not define_ret:
            conf.DEFINE(define, 1)
            conf.COMPOUND_END(True)
        else:
            conf.COMPOUND_END(conf.env[define])
        return True
    if always:
        conf.DEFINE(define, 0)
    conf.COMPOUND_END(False)
    return False