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

import os.path

def configure(conf):
    if conf.env['ENABLE_THREADING']:
        conf.env['ENABLE_EMU'] = conf.check_nonfatal(header_name='netpacket/packet.h',
                                            define_name='HAVE_PACKET_H')
        conf.report_optional_feature("EmuNetDevice", "Emulated Net Device",
                                     conf.env['ENABLE_EMU'],
                                     "<netpacket/packet.h> include not detected")
    else:
        conf.report_optional_feature("EmuNetDevice", "Emulated Net Device",
                                     False,
                                     "needs threading support which is not available")

    if conf.env['ENABLE_EMU']:
        #blddir = conf.bldnode.abspath()
        blddir = os.path.abspath(os.path.join(conf.bldnode.abspath(), conf.variant))
        emucreatordir = os.path.abspath(os.path.join(blddir, "src/emu"))
        conf.env.append_value('NS3_EXECUTABLE_PATH', emucreatordir)
    else:
        # Add this module to the list of modules that won't be built
        # if they are enabled.
        conf.env['MODULES_NOT_BUILT'].append('emu')

def build(bld):
    # Don't do anything for this module if emu's not enabled.
    if not bld.env['ENABLE_EMU']:
        return

    module = bld.create_ns3_module('emu', ['network'])
    module.source = [
            'model/emu-net-device.cc',
            'model/emu-encode-decode.cc',
            'helper/emu-helper.cc',
        ]

    headers = bld(features='ns3header')
    headers.module = 'emu'
    headers.source = [
            'model/emu-net-device.h',
            'helper/emu-helper.h',
        ]

    creator = bld.create_suid_program('emu-sock-creator')
    creator.source = [
        'model/emu-sock-creator.cc',
        'model/emu-encode-decode.cc',
        ]

    module.env.append_value("DEFINES", "EMU_SOCK_CREATOR=\"%s\"" % (creator.target,))

    if bld.env['ENABLE_EXAMPLES']:
        bld.recurse('examples')

    bld.ns3_python_bindings()
