src/wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Fri, 20 Jul 2007 11:27:34 +0100
changeset 954 a54d59850d03
parent 928 218063b19458
child 955 c9be0df711d2
permissions -rw-r--r--
WAF: use a separate 'waf task' for installing each public ns3 header to work around a dependency tracking bug in waf causing too many rebuilds when a single header file changes.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     2
761
0ffbc9fa8ef0 Define env['NS3_MODULE_PATH'] in configure rather than build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 693
diff changeset
     3
import os, os.path
693
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
     4
import shutil
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
     5
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
     6
import Action
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
     7
import Common
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
     8
import Object
600
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
     9
import Params
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    10
693
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    11
600
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    12
all_modules = [
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    13
    'core',
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    14
    'common',
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    15
    'simulator',
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    16
    'node',
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    17
    'internet-node',
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    18
    'devices/p2p',
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    19
    'applications',
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    20
    ]
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    21
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    22
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    23
def set_options(opt):
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    24
    opt.sub_options('simulator')
668
2df1d1f5778f WAF: fix problem in --enable/disable-rpath options
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 651
diff changeset
    25
    
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    26
def configure(conf):
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    27
    conf.sub_config('core')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    28
    conf.sub_config('simulator')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    29
761
0ffbc9fa8ef0 Define env['NS3_MODULE_PATH'] in configure rather than build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 693
diff changeset
    30
    blddir = os.path.abspath(os.path.join(conf.m_blddir, conf.env.variant()))
0ffbc9fa8ef0 Define env['NS3_MODULE_PATH'] in configure rather than build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 693
diff changeset
    31
    for module in all_modules:
0ffbc9fa8ef0 Define env['NS3_MODULE_PATH'] in configure rather than build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 693
diff changeset
    32
        conf.env.append_value('NS3_MODULE_PATH', os.path.join(blddir, 'src', module))
0ffbc9fa8ef0 Define env['NS3_MODULE_PATH'] in configure rather than build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 693
diff changeset
    33
928
218063b19458 WAF: derive the variable NS3_MODULES from the 'all_modules' list in src/wscript, instead of requiring every module to define a configure function to register themselves. This way module registration is done in one place only: src/wscript. Requires module naming conventions, though.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 770
diff changeset
    34
    ## Used to link the 'run-tests' program with all of ns-3 code
218063b19458 WAF: derive the variable NS3_MODULES from the 'all_modules' list in src/wscript, instead of requiring every module to define a configure function to register themselves. This way module registration is done in one place only: src/wscript. Requires module naming conventions, though.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 770
diff changeset
    35
    conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules]
218063b19458 WAF: derive the variable NS3_MODULES from the 'all_modules' list in src/wscript, instead of requiring every module to define a configure function to register themselves. This way module registration is done in one place only: src/wscript. Requires module naming conventions, though.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 770
diff changeset
    36
600
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    37
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    38
def build(bld):
693
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    39
    Object.register('ns3header', Ns3Header)
954
a54d59850d03 WAF: use a separate 'waf task' for installing each public ns3 header to work around a dependency tracking bug in waf causing too many rebuilds when a single header file changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 928
diff changeset
    40
    Action.Action('ns3header', func=_ns3_headers_inst, color='BLUE')
600
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    41
    
fd944dbf33c6 WAF: simplify wscripts using the new chained uselib_local dependencies feature of WAF SVN; now build all samples and examples; add --disable-rpath configure option; add WAF build instructions.
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 537
diff changeset
    42
    bld.add_subdirs(all_modules)
693
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    43
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    44
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    45
class Ns3Header(Object.genobj):
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    46
    """A set of NS-3 header files"""
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    47
    def __init__(self, env=None):
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    48
        Object.genobj.__init__(self, 'other')
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    49
        self.inst_var = 'INCLUDEDIR'
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    50
        self.inst_dir = 'ns3'
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    51
        self.env = env
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    52
        if not self.env:
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    53
            self.env = Params.g_build.m_allenvs['default']
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    54
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    55
    def apply(self):
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    56
        ns3_dir_node = Params.g_build.m_srcnode.find_dir("ns3")
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    57
        for filename in self.to_list(self.source):
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    58
            src_node = self.path.find_source(filename)
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    59
            if src_node is None:
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    60
                Params.fatal("source ns3 header file %s not found" % (filename,))
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    61
            dst_node = ns3_dir_node.find_build(os.path.basename(filename))
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    62
            assert dst_node is not None
954
a54d59850d03 WAF: use a separate 'waf task' for installing each public ns3 header to work around a dependency tracking bug in waf causing too many rebuilds when a single header file changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 928
diff changeset
    63
            task = self.create_task('ns3header', self.env, 1)
a54d59850d03 WAF: use a separate 'waf task' for installing each public ns3 header to work around a dependency tracking bug in waf causing too many rebuilds when a single header file changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 928
diff changeset
    64
            task.set_inputs([src_node])
a54d59850d03 WAF: use a separate 'waf task' for installing each public ns3 header to work around a dependency tracking bug in waf causing too many rebuilds when a single header file changes.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 928
diff changeset
    65
            task.set_outputs([dst_node])
693
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    66
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    67
    def install(self):
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    68
        for i in self.m_tasks:
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    69
            current = Params.g_build.m_curdirnode
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    70
            lst = map(lambda a: a.relpath_gen(current), i.m_outputs)
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    71
            Common.install_files(self.inst_var, self.inst_dir, lst)
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    72
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    73
def _ns3_headers_inst(task):
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    74
    assert len(task.m_inputs) == len(task.m_outputs)
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    75
    inputs = [node.srcpath(task.m_env) for node in task.m_inputs]
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    76
    outputs = [node.bldpath(task.m_env) for node in task.m_outputs]
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    77
    for src, dst in zip(inputs, outputs):
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    78
        try:
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    79
            os.chmod(dst, 0600)
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    80
        except OSError:
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    81
            pass
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    82
        shutil.copy2(src, dst)
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    83
        ## make the headers in builddir read-only, to prevent
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    84
        ## accidental modification
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    85
        os.chmod(dst, 0400)
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
    86
    return 0