src/wscript
author Tom Henderson <tomh@tomh.org>
Fri, 03 Aug 2007 08:29:24 -0700
changeset 1119 520de3dc31a9
parent 1111 835cd416a0a8
parent 977 09bf4e458015
child 1120 050454d7d028
permissions -rw-r--r--
merge with ns-3-dev

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

import os, os.path
import shutil

import Action
import Common
import Object
import Params


all_modules = (
    'core',
    'common',
    'simulator',
    'node',
    'internet-node',
    'devices/point-to-point',
    'devices/csma-cd',
    'applications',
    'routing/global',
    'mobility',
    )

def set_options(opt):
    opt.sub_options('simulator')

    opt.add_option('--enable-rpath',
                   help=("Link programs with rpath"
                         " (normally not needed, see "
                         " --run and --shell; moreover, only works in some"
                         " specific platforms, such as Linux and Solaris)"),
                   action="store_true", dest='enable_rpath', default=False)


def configure(conf):
    conf.sub_config('core')
    conf.sub_config('simulator')

    blddir = os.path.abspath(os.path.join(conf.m_blddir, conf.env.variant()))
    for module in all_modules:
        module_path = os.path.join(blddir, 'src', module)
        conf.env.append_value('NS3_MODULE_PATH', module_path)
        if Params.g_options.enable_rpath:
            conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (module_path,))

    ## Used to link the 'run-tests' program with all of ns-3 code
    conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules]



def build(bld):
    Object.register('ns3header', Ns3Header)
    Action.Action('ns3header', func=_ns3_headers_inst, color='BLUE')
    
    bld.add_subdirs(list(all_modules))

class Ns3Header(Object.genobj):
    """A set of NS-3 header files"""
    def __init__(self, env=None):
        Object.genobj.__init__(self, 'other')
        self.inst_var = 'INCLUDEDIR'
        self.inst_dir = 'ns3'
        self.env = env
        if not self.env:
            self.env = Params.g_build.m_allenvs['default']

    def apply(self):
        ns3_dir_node = Params.g_build.m_srcnode.find_dir("ns3")
        for filename in self.to_list(self.source):
            src_node = self.path.find_source(filename)
            if src_node is None:
                Params.fatal("source ns3 header file %s not found" % (filename,))
            dst_node = ns3_dir_node.find_build(os.path.basename(filename))
            assert dst_node is not None
            task = self.create_task('ns3header', self.env, 1)
            task.set_inputs([src_node])
            task.set_outputs([dst_node])

    def install(self):
        for i in self.m_tasks:
            current = Params.g_build.m_curdirnode
            lst = map(lambda a: a.relpath_gen(current), i.m_outputs)
            Common.install_files(self.inst_var, self.inst_dir, lst)

def _ns3_headers_inst(task):
    assert len(task.m_inputs) == len(task.m_outputs)
    inputs = [node.srcpath(task.m_env) for node in task.m_inputs]
    outputs = [node.bldpath(task.m_env) for node in task.m_outputs]
    for src, dst in zip(inputs, outputs):
        try:
            os.chmod(dst, 0600)
        except OSError:
            pass
        shutil.copy2(src, dst)
        ## make the headers in builddir read-only, to prevent
        ## accidental modification
        os.chmod(dst, 0400)
    return 0