예제 #1
0
def CHECK_COMMAND(conf,
                  cmd,
                  msg=None,
                  define=None,
                  on_target=True,
                  boolean=False):
    '''run a command and return result'''
    if msg is None:
        msg = 'Checking %s' % ' '.join(cmd)
    conf.COMPOUND_START(msg)
    cmd = cmd[:]
    if on_target:
        cmd.extend(conf.SAMBA_CROSS_ARGS(msg=msg))
    try:
        ret = Utils.cmd_output(cmd)
    except:
        conf.COMPOUND_END(False)
        return False
    if boolean:
        conf.COMPOUND_END('ok')
        if define:
            conf.DEFINE(define, '1')
    else:
        ret = ret.strip()
        conf.COMPOUND_END(ret)
        if define:
            conf.DEFINE(define, ret, quote=True)
    return ret
예제 #2
0
def CHECK_FUNC(conf, f, link=True, lib=None, headers=None):
    '''check for a function'''
    define='HAVE_%s' % f.upper()

    ret = False

    conf.COMPOUND_START('Checking for %s' % f)

    if link is None or link:
        ret = CHECK_CODE(conf,
                         # this is based on the autoconf strategy
                         '''
                         #define %s __fake__%s
                         #ifdef HAVE_LIMITS_H
                         # include <limits.h>
                         #else
                         # include <assert.h>
                         #endif
                         #undef %s
                         #if defined __stub_%s || defined __stub___%s
                         #error "bad glibc stub"
                         #endif
                         extern char %s();
                         int main() { return %s(); }
                         ''' % (f, f, f, f, f, f, f),
                         execute=False,
                         link=True,
                         addmain=False,
                         add_headers=False,
                         define=define,
                         local_include=False,
                         lib=lib,
                         headers=headers,
                         msg='Checking for %s' % f)

        if not ret:
            ret = CHECK_CODE(conf,
                             # it might be a macro
                             # we need to make sure the compiler doesn't
                             # optimize it out...
                             'void *__x = (void *)%s; return (int)__x' % f,
                             execute=False,
                             link=True,
                             addmain=True,
                             add_headers=True,
                             define=define,
                             local_include=False,
                             lib=lib,
                             headers=headers,
                             msg='Checking for macro %s' % f)

    if not ret and (link is None or not link):
        ret = CHECK_VARIABLE(conf, f,
                             define=define,
                             headers=headers,
                             msg='Checking for declaration of %s' % f)
    conf.COMPOUND_END(ret)
    return ret
예제 #3
0
def CHECK_INLINE(conf):
    '''check for the right value for inline'''
    conf.COMPOUND_START('Checking for inline')
    for i in ['inline', '__inline__', '__inline']:
        ret = conf.CHECK_CODE('''
        typedef int foo_t;
        static %s foo_t static_foo () {return 0; }
        %s foo_t foo () {return 0; }''' % (i, i),
                              define='INLINE_MACRO',
                              addmain=False,
                              link=False)
        if ret:
            if i != 'inline':
                conf.DEFINE('inline', i, quote=False)
            break
    if not ret:
        conf.COMPOUND_END(ret)
    else:
        conf.COMPOUND_END(i)
    return ret
예제 #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