Exemple #1
0
def CHECK_BUNDLED_SYSTEM_PKG(conf,
                             libname,
                             minversion='0.0.0',
                             onlyif=None,
                             implied_deps=None,
                             pkg=None):
    '''check if a library is available as a system library.

    This only tries using pkg-config
    '''
    if conf.LIB_MUST_BE_BUNDLED(libname):
        return False
    found = 'FOUND_SYSTEMLIB_%s' % libname
    if found in conf.env:
        return conf.env[found]

    # see if the library should only use a system version if another dependent
    # system version is found. That prevents possible use of mixed library
    # versions
    if onlyif:
        if not conf.CHECK_PREREQUISITES(onlyif):
            if not conf.LIB_MAY_BE_BUNDLED(libname):
                Logs.error(
                    'ERROR: Use of system library %s depends on missing system library %s'
                    % (libname, onlyif))
                sys.exit(1)
            conf.env[found] = False
            return False

    minversion = minimum_library_version(conf, libname, minversion)

    msg = 'Checking for system %s' % libname
    if minversion != '0.0.0':
        msg += ' >= %s' % minversion

    if pkg is None:
        pkg = libname

    if conf.check_cfg(package=pkg,
                      args='"%s >= %s" --cflags --libs' % (pkg, minversion),
                      msg=msg,
                      uselib_store=libname.upper()):
        conf.SET_TARGET_TYPE(libname, 'SYSLIB')
        conf.env[found] = True
        if implied_deps:
            conf.SET_SYSLIB_DEPS(libname, implied_deps)
        return True
    conf.env[found] = False
    if not conf.LIB_MAY_BE_BUNDLED(libname):
        Logs.error(
            'ERROR: System library %s of version %s not found, and bundling disabled'
            % (libname, minversion))
        sys.exit(1)
    return False
Exemple #2
0
def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
                         maxversion=None, version_blacklist=[],
                         checkfunctions=None, headers=None, checkcode=None,
                         onlyif=None, implied_deps=None,
                         require_headers=True, pkg=None, set_target=True):
    '''check if a library is available as a system library.
    this first tries via pkg-config, then if that fails
    tries by testing for a specified function in the specified lib
    '''
    # We always do a logic validation of 'onlyif' first
    missing = []
    if onlyif:
        for l in TO_LIST(onlyif):
            f = 'FOUND_SYSTEMLIB_%s' % l
            if not f in conf.env:
                Logs.error('ERROR: CHECK_BUNDLED_SYSTEM(%s) - ' % (libname) +
                           'missing prerequisite check for ' +
                           'system library %s, onlyif=%r' % (l, onlyif))
                sys.exit(1)
            if not conf.env[f]:
                missing.append(l)
    found = 'FOUND_SYSTEMLIB_%s' % libname
    if found in conf.env:
        return conf.env[found]
    if conf.LIB_MUST_BE_BUNDLED(libname):
        conf.env[found] = False
        return False

    # see if the library should only use a system version if another dependent
    # system version is found. That prevents possible use of mixed library
    # versions
    if missing:
        if not conf.LIB_MAY_BE_BUNDLED(libname):
            Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
            sys.exit(1)
        conf.env[found] = False
        return False

    def check_functions_headers_code():
        '''helper function for CHECK_BUNDLED_SYSTEM'''
        if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
            return False
        if checkfunctions is not None:
            ok = conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
                                     empty_decl=False, set_target=False)
            if not ok:
                return False
        if checkcode is not None:
            define='CHECK_BUNDLED_SYSTEM_%s' % libname.upper()
            ok = conf.CHECK_CODE(checkcode, lib=libname,
                                 headers=headers, local_include=False,
                                 msg=msg, define=define)
            conf.CONFIG_RESET(define)
            if not ok:
                return False
        return True

    minversion = minimum_library_version(conf, libname, minversion)

    msg = 'Checking for system %s' % libname
    msg_ver = []
    if minversion != '0.0.0':
        msg_ver.append('>=%s' % minversion)
    if maxversion is not None:
        msg_ver.append('<=%s' % maxversion)
    for v in version_blacklist:
        msg_ver.append('!=%s' % v)
    if msg_ver != []:
        msg += " (%s)" % (" ".join(msg_ver))

    uselib_store=libname.upper()
    if pkg is None:
        pkg = libname

    version_checks = '%s >= %s' % (pkg, minversion)
    if maxversion is not None:
        version_checks += ' %s <= %s' % (pkg, maxversion)
    for v in version_blacklist:
        version_checks += ' %s != %s' % (pkg, v)

    # try pkgconfig first
    if (conf.CHECK_CFG(package=pkg,
                      args='"%s" --cflags --libs' % (version_checks),
                      msg=msg, uselib_store=uselib_store) and
        check_functions_headers_code()):
        if set_target:
            conf.SET_TARGET_TYPE(libname, 'SYSLIB')
        conf.env[found] = True
        if implied_deps:
            conf.SET_SYSLIB_DEPS(libname, implied_deps)
        return True
    if checkfunctions is not None:
        if check_functions_headers_code():
            conf.env[found] = True
            if implied_deps:
                conf.SET_SYSLIB_DEPS(libname, implied_deps)
            if set_target:
                conf.SET_TARGET_TYPE(libname, 'SYSLIB')
            return True
    conf.env[found] = False
    if not conf.LIB_MAY_BE_BUNDLED(libname):
        Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
        sys.exit(1)
    return False
Exemple #3
0
def CHECK_BUNDLED_SYSTEM(conf, libname, minversion='0.0.0',
                         checkfunctions=None, headers=None, checkcode=None,
                         onlyif=None, implied_deps=None,
                         require_headers=True, pkg=None, set_target=True):
    '''check if a library is available as a system library.
    this first tries via pkg-config, then if that fails
    tries by testing for a specified function in the specified lib
    '''
    if conf.LIB_MUST_BE_BUNDLED(libname):
        return False
    found = 'FOUND_SYSTEMLIB_%s' % libname
    if found in conf.env:
        return conf.env[found]

    def check_functions_headers_code():
        '''helper function for CHECK_BUNDLED_SYSTEM'''
        if require_headers and headers and not conf.CHECK_HEADERS(headers, lib=libname):
            return False
        if checkfunctions is not None:
            ok = conf.CHECK_FUNCS_IN(checkfunctions, libname, headers=headers,
                                     empty_decl=False, set_target=False)
            if not ok:
                return False
        if checkcode is not None:
            define='CHECK_BUNDLED_SYSTEM_%s' % libname.upper()
            ok = conf.CHECK_CODE(checkcode, lib=libname,
                                 headers=headers, local_include=False,
                                 msg=msg, define=define)
            conf.CONFIG_RESET(define)
            if not ok:
                return False
        return True


    # see if the library should only use a system version if another dependent
    # system version is found. That prevents possible use of mixed library
    # versions
    if onlyif:
        missing = conf.CHECK_PREREQUISITES(onlyif)
        if missing:
            if not conf.LIB_MAY_BE_BUNDLED(libname):
                Logs.error('ERROR: Use of system library %s depends on missing system library/libraries %r' % (libname, missing))
                sys.exit(1)
            conf.env[found] = False
            return False

    minversion = minimum_library_version(conf, libname, minversion)

    msg = 'Checking for system %s' % libname
    if minversion != '0.0.0':
        msg += ' >= %s' % minversion

    uselib_store=libname.upper()
    if pkg is None:
        pkg = libname

    # try pkgconfig first
    if (conf.check_cfg(package=pkg,
                      args='"%s >= %s" --cflags --libs' % (pkg, minversion),
                      msg=msg, uselib_store=uselib_store) and
        check_functions_headers_code()):
        if set_target:
            conf.SET_TARGET_TYPE(libname, 'SYSLIB')
        conf.env[found] = True
        if implied_deps:
            conf.SET_SYSLIB_DEPS(libname, implied_deps)
        return True
    if checkfunctions is not None:
        if check_functions_headers_code():
            conf.env[found] = True
            if implied_deps:
                conf.SET_SYSLIB_DEPS(libname, implied_deps)
            if set_target:
                conf.SET_TARGET_TYPE(libname, 'SYSLIB')
            return True
    conf.env[found] = False
    if not conf.LIB_MAY_BE_BUNDLED(libname):
        Logs.error('ERROR: System library %s of version %s not found, and bundling disabled' % (libname, minversion))
        sys.exit(1)
    return False
Exemple #4
0
def CHECK_BUNDLED_SYSTEM(conf,
                         libname,
                         minversion='0.0.0',
                         checkfunctions=None,
                         headers=None,
                         onlyif=None,
                         implied_deps=None,
                         require_headers=True):
    '''check if a library is available as a system library.
    this first tries via pkg-config, then if that fails
    tries by testing for a specified function in the specified lib
    '''
    if conf.LIB_MUST_BE_BUNDLED(libname):
        return False
    found = 'FOUND_SYSTEMLIB_%s' % libname
    if found in conf.env:
        return conf.env[found]

    def check_functions_headers():
        '''helper function for CHECK_BUNDLED_SYSTEM'''
        if checkfunctions is None:
            return True
        if require_headers and headers and not conf.CHECK_HEADERS(headers,
                                                                  lib=libname):
            return False
        return conf.CHECK_FUNCS_IN(checkfunctions,
                                   libname,
                                   headers=headers,
                                   empty_decl=False,
                                   set_target=False)

    # see if the library should only use a system version if another dependent
    # system version is found. That prevents possible use of mixed library
    # versions
    if onlyif:
        for syslib in TO_LIST(onlyif):
            f = 'FOUND_SYSTEMLIB_%s' % syslib
            if not f in conf.env:
                if not conf.LIB_MAY_BE_BUNDLED(libname):
                    Logs.error(
                        'ERROR: Use of system library %s depends on missing system library %s'
                        % (libname, syslib))
                    sys.exit(1)
                conf.env[found] = False
                return False

    minversion = minimum_library_version(conf, libname, minversion)

    msg = 'Checking for system %s' % libname
    if minversion != '0.0.0':
        msg += ' >= %s' % minversion

    # try pkgconfig first
    if (conf.check_cfg(package=libname,
                       args='"%s >= %s" --cflags --libs' %
                       (libname, minversion),
                       msg=msg) and check_functions_headers()):
        conf.SET_TARGET_TYPE(libname, 'SYSLIB')
        conf.env[found] = True
        if implied_deps:
            conf.SET_SYSLIB_DEPS(libname, implied_deps)
        return True
    if checkfunctions is not None:
        if check_functions_headers():
            conf.env[found] = True
            if implied_deps:
                conf.SET_SYSLIB_DEPS(libname, implied_deps)
            conf.SET_TARGET_TYPE(libname, 'SYSLIB')
            return True
    conf.env[found] = False
    if not conf.LIB_MAY_BE_BUNDLED(libname):
        Logs.error(
            'ERROR: System library %s of version %s not found, and bundling disabled'
            % (libname, minversion))
        sys.exit(1)
    return False