Esempio n. 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).decode('utf8')
    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
def CHECK_HEADER(conf, h, add_headers=False, lib=None):
    '''check for a header'''
    if h in missing_headers and lib is None:
        return False
    d = h.upper().replace('/', '_')
    d = d.replace('.', '_')
    d = d.replace('-', '_')
    d = 'HAVE_%s' % d
    if CONFIG_SET(conf, d):
        if add_headers:
            if not h in conf.env.hlist:
                conf.env.hlist.append(h)
        return True

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

    hdrs = hlist_to_string(conf, headers=h)
    if lib is None:
        lib = ""
    ret = conf.check(fragment='%s\nint main(void) { return 0; }\n' % hdrs,
                     type='nolink',
                     execute=0,
                     cflags=ccflags,
                     mandatory=False,
                     includes=cpppath,
                     uselib=lib.upper(),
                     msg="Checking for header %s" % h)
    if not ret:
        missing_headers.add(h)
        return False

    conf.DEFINE(d, 1)
    if add_headers and not h in conf.env.hlist:
        conf.env.hlist.append(h)
    return ret
Esempio n. 3
0
def CHECK_ICONV(conf, define='HAVE_NATIVE_ICONV'):
    '''check if the iconv library is installed
       optionally pass a define'''
    if conf.CHECK_FUNCS_IN('iconv_open', 'iconv', checklibc=True, headers='iconv.h'):
        conf.DEFINE(define, 1)
        return True
    return False
Esempio n. 4
0
def CHECK_LARGEFILE(conf, define='HAVE_LARGEFILE'):
    '''see what we need for largefile support'''
    getconf_cflags = conf.CHECK_COMMAND(['getconf', 'LFS_CFLAGS'])
    if getconf_cflags is not False:
        if (conf.CHECK_CODE(
                'return !(sizeof(off_t) >= 8)',
                define='WORKING_GETCONF_LFS_CFLAGS',
                execute=True,
                cflags=getconf_cflags,
                msg='Checking getconf large file support flags work')):
            conf.ADD_CFLAGS(getconf_cflags)
            getconf_cflags_list = TO_LIST(getconf_cflags)
            for flag in getconf_cflags_list:
                if flag[:2] == "-D":
                    flag_split = flag[2:].split('=')
                    if len(flag_split) == 1:
                        conf.DEFINE(flag_split[0], '1')
                    else:
                        conf.DEFINE(flag_split[0], flag_split[1])

    if conf.CHECK_CODE(
            'return !(sizeof(off_t) >= 8)',
            define,
            execute=True,
            msg='Checking for large file support without additional flags'):
        return True

    if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
                       define,
                       execute=True,
                       cflags='-D_FILE_OFFSET_BITS=64',
                       msg='Checking for -D_FILE_OFFSET_BITS=64'):
        conf.DEFINE('_FILE_OFFSET_BITS', 64)
        return True

    if conf.CHECK_CODE('return !(sizeof(off_t) >= 8)',
                       define,
                       execute=True,
                       cflags='-D_LARGE_FILES',
                       msg='Checking for -D_LARGE_FILES'):
        conf.DEFINE('_LARGE_FILES', 1)
        return True
    return False
Esempio n. 5
0
def CHECK_SAMBA3_CHARSET(conf, crossbuild=False):
    '''Check for default charsets for Samba3
    '''
    if conf.CHECK_ICONV(define='HAVE_NATIVE_ICONV'):
        default_dos_charset = False
        default_unix_charset = False

        # check for default dos charset name
        for charset in ['CP850', 'IBM850']:
            if conf.CHECK_CHARSET_EXISTS(charset, headers='iconv.h'):
                default_dos_charset = charset
                break

        # check for default unix charset name
        for charset in ['UTF-8', 'UTF8']:
            if conf.CHECK_CHARSET_EXISTS(charset, headers='iconv.h'):
                default_unix_charset = charset
                break

        # At this point, we have a libiconv candidate. We know that
        # we have the right headers and libraries, but we don't know
        # whether it does the conversions we want. We can't test this
        # because we are cross-compiling. This is not necessarily a big
        # deal, since we can't guarantee that the results we get now will
        # match the results we get at runtime anyway.
        if crossbuild:
            default_dos_charset = "CP850"
            default_unix_charset = "UTF-8"
            # TODO: this used to warn about the set charset on cross builds

        if default_dos_charset is False or default_unix_charset is False:
            # we found iconv, but it failed to convert anything (e.g. on AIX)
            conf.undefine('HAVE_NATIVE_ICONV')
            default_dos_charset = "ASCII"
            default_unix_charset = "UTF-8"

        conf.DEFINE('DEFAULT_DOS_CHARSET', default_dos_charset, quote=True)
        conf.DEFINE('DEFAULT_UNIX_CHARSET', default_unix_charset, quote=True)

    else:
        conf.DEFINE('DEFAULT_DOS_CHARSET', "ASCII", quote=True)
        conf.DEFINE('DEFAULT_UNIX_CHARSET', "UTF8", quote=True)
Esempio n. 6
0
def CHECK_TYPE(conf, t, alternate=None, headers=None, define=None, lib=None, msg=None):
    '''check for a single type'''
    if define is None:
        define = 'HAVE_' + t.upper().replace(' ', '_')
    if msg is None:
        msg='Checking for %s' % t
    ret = CHECK_CODE(conf, '%s _x' % t,
                     define,
                     execute=False,
                     headers=headers,
                     local_include=False,
                     msg=msg,
                     lib=lib,
                     link=False)
    if not ret and alternate:
        conf.DEFINE(t, alternate)
    return ret
Esempio n. 7
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
Esempio n. 8
0
def CHECK_SIZEOF(conf, vars, headers=None, define=None, critical=True):
    '''check the size of a type'''
    for v in TO_LIST(vars):
        v_define = define
        ret = False
        if v_define is None:
            v_define = 'SIZEOF_%s' % v.upper().replace(' ', '_')
        for size in list((1, 2, 4, 8, 16, 32, 64)):
            if CHECK_CODE(conf,
                      'static int test_array[1 - 2 * !(((long int)(sizeof(%s))) <= %d)];' % (v, size),
                      define=v_define,
                      quote=False,
                      headers=headers,
                      local_include=False,
                      msg="Checking if size of %s == %d" % (v, size)):
                conf.DEFINE(v_define, size)
                ret = True
                break
        if not ret and critical:
            Logs.error("Couldn't determine size of '%s'" % v)
            sys.exit(1)
    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