示例#1
0
def _check_dependencies(conf, required, mandatory):
    found = []
    libcore = build_ns3_libname("*", "core", conf.env['LIB_SUFFIX'])
    ns3_dir_pkgconfig = conf.env['NS3_DIR'] + '/lib/pkgconfig'

    if not 'NS3_VERSION' in conf.env:

        pcfiles = glob.glob(ns3_dir_pkgconfig + '/' + libcore + ".pc")
        if len(pcfiles) > 1:
            Logs.errors(
                "Too many candidates, DCE should only see one ns-3 version.")
            return
        elif len(pcfiles) == 1:
            match_pkg = os.path.basename(pcfiles[0])
            lib = re.search("(ns[0-9][\.\-][dev0-9\.]+)", match_pkg)
            if lib.group(0) is None:
                Logs.error("Could not find version for the match %s" %
                           match_pkg)
                return

            version = lib.group(0)
            conf.env['NS3_VERSION'] = version
        else:
            Logs.error("Could not find " + libcore)
            return

    for module in required:
        if module in conf.env['NS3_MODULES_FOUND']:
            continue
        libname = build_ns3_libname(conf.env['NS3_VERSION'], module.lower(),
                                    conf.env['LIB_SUFFIX'])
        retval = conf.check_cfg(
            package=libname,
            args='--cflags --libs' +
            (' --static' if conf.env['NS3_ENABLE_STATIC'] else ''),
            mandatory=mandatory,
            msg="Checking for %s (%s)" %
            (libname, "mandatory" if mandatory else "optional"),
            uselib_store='NS3_%s' % module.upper(),
            pkg_config_path=":".join(
                [os.environ.get("PKG_CONFIG_PATH"), ns3_dir_pkgconfig]))

        if retval is not None:
            # XXX pkg-config doesn't give the proper order of whole-archive option..
            if conf.env['NS3_ENABLE_STATIC']:
                libname = 'STLIB_ST_NS3_%s' % module.upper()
                conf.env[libname] = '-l%s' % (match_pkg.replace(
                    'libns3', 'ns3'))
                for lib in conf.env['LIB_NS3_%s' % module.upper()]:
                    if 'ns3' in lib:
                        conf.env.append_value(libname, '-l%s' % lib)

        if not retval is None:
            found.append(module)

    import copy
    if not 'NS3_MODULES_FOUND' in conf.env:
        conf.env['NS3_MODULES_FOUND'] = []
    conf.env['NS3_MODULES_FOUND'] = conf.env['NS3_MODULES_FOUND'] + copy.copy(
        found)