## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-

import waflib
from waflib.Configure import conf
from waflib import Utils,Logs,Errors

@conf
def _print_optional_features(conf):
    # Write a summary of optional features status
    print "---- Summary of optional NS-3 features:"
    Logs.pprint ('RED', "---- Summary of optional NS-3 features:")
    # for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']:
    #     if was_enabled:
    #         status = 'enabled'
    #     else:
    #         status = 'not enabled (%s)' % reason_not_enabled
    #     print "%-30s: %s" % (caption, status)

@conf
def _check_dependencies(conf, required, mandatory):
    # Logs.pprint ('CYAN', '  + %s' % required)
    found = []
    for module in required:
        retval = conf.check_cfg(package = 'libns3-dev-%s-debug' % module,
                                args='--cflags --libs', mandatory=mandatory,
                                msg="Checking for ns3-%s" % module,
                                uselib_store='NS3_%s' % module.upper())
        # Logs.pprint ('CYAN', 'NS3_%s' % module.upper())
        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)

def modules_uselib(bld, names):
    return ['NS3_%s' % name.upper() for name in names] + \
        ['NS3_LIBRARY_%s' % name.upper() for name in names] + \
        ['NS3_HEADERS_%s' % name.upper() for name in names]

def modules_found(bld, needed):
    for module in needed:
        if not module in bld.env['NS3_MODULES_FOUND']:
            return False
    return True

@conf
def check_modules(conf, modules, mandatory = True):
    import os

    if not 'NS3_CHECK_MODULE_ONCE' in conf.env:
        conf.env['NS3_CHECK_MODULE_ONCE'] = ''

        conf.check_cfg(atleast_pkgconfig_version='0.0.0')

        if conf.options.log4cxx:
            conf.env.append_value('DEFINES', 'NS3_LOG_ENABLE')

    conf._check_dependencies(modules, mandatory)
    conf._print_optional_features

@conf
def print_ns3_feature_summary(conf):
    Logs.pprint ('CYAN', "---- Summary of optional NS-3 features:")
    conf._print_optional_features

