src/wscript
author Nicola Baldo <nbaldo@cttc.es>
Mon, 10 Oct 2011 18:05:18 +0200
changeset 8253 6faee3d1d1d0
parent 8248 986f7db9f056
parent 7545 ac0569e8cb7d
child 8339 bfa05e51eecf
permissions -rw-r--r--
merge ns-3-dev
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
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
     4
import sys
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
     5
import shutil
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1214
diff changeset
     6
import types
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
     7
import warnings
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
     8
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
     9
from waflib.Errors import WafError
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    10
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    11
import TaskGen
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    12
import Task
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    13
import Options
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    14
import Build
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
    15
import Utils
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
    16
7319
175c382cfab0 Bug 1175 - the shared libraries is not versioned, based on patch by YunQiang Su
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7303
diff changeset
    17
import wutils
175c382cfab0 Bug 1175 - the shared libraries is not versioned, based on patch by YunQiang Su
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7303
diff changeset
    18
6168
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    19
try:
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    20
    set
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    21
except NameError:
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    22
    from sets import Set as set # Python 2.3 fallback
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    23
7496
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    24
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    25
all_modules = []
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    26
for dirname in os.listdir('src'):
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    27
    if dirname.startswith('.') or dir == 'CVS':
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    28
        continue
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    29
    path = os.path.join('src', dirname)
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    30
    if not os.path.isdir(path):
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    31
        continue
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    32
    if os.path.exists(os.path.join(path, 'wscript')):
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    33
        all_modules.append(dirname)
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    34
all_modules.sort()
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    35
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
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
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    38
def options(opt):
955
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
    39
    opt.add_option('--enable-rpath',
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
    40
                   help=("Link programs with rpath"
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
    41
                         " (normally not needed, see "
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
    42
                         " --run and --shell; moreover, only works in some"
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
    43
                         " specific platforms, such as Linux and Solaris)"),
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
    44
                   action="store_true", dest='enable_rpath', default=False)
4164
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4163
diff changeset
    45
    
1858
68e1964c19e8 WAF: add a new --enable-modules configure option, to tell WAF to build only the specified set of ns-3 modules and its dependencies; programs depending on those modules are automatically excluded from the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1747
diff changeset
    46
    opt.add_option('--enable-modules',
68e1964c19e8 WAF: add a new --enable-modules configure option, to tell WAF to build only the specified set of ns-3 modules and its dependencies; programs depending on those modules are automatically excluded from the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1747
diff changeset
    47
                   help=("Build only these modules (and dependencies)"),
68e1964c19e8 WAF: add a new --enable-modules configure option, to tell WAF to build only the specified set of ns-3 modules and its dependencies; programs depending on those modules are automatically excluded from the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1747
diff changeset
    48
                   dest='enable_modules')
68e1964c19e8 WAF: add a new --enable-modules configure option, to tell WAF to build only the specified set of ns-3 modules and its dependencies; programs depending on those modules are automatically excluded from the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1747
diff changeset
    49
7496
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    50
    for module in all_modules:
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    51
        opt.sub_options(module, mandatory=False)
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    52
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    53
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    54
def configure(conf):
7496
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    55
    for module in all_modules:
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
    56
        conf.sub_config(module, mandatory=False)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    57
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    58
    blddir = os.path.abspath(os.path.join(conf.bldnode.abspath(), conf.variant))
3498
ce35418645e9 bug 266: src/wscript unconditionally sets conf.env['NS3_MODULE_PATH']
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 3439
diff changeset
    59
    conf.env.append_value('NS3_MODULE_PATH', blddir)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    60
    if Options.options.enable_rpath:
1306
8834e434187f Build the ns3 library in the build/<variant> root, not in build/<variant>/src.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1272
diff changeset
    61
        conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (os.path.join(blddir),))
761
0ffbc9fa8ef0 Define env['NS3_MODULE_PATH'] in configure rather than build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 693
diff changeset
    62
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5270
diff changeset
    63
    ## Used to link the 'test-runner' program with all of ns-3 code
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
    64
    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
    65
1858
68e1964c19e8 WAF: add a new --enable-modules configure option, to tell WAF to build only the specified set of ns-3 modules and its dependencies; programs depending on those modules are automatically excluded from the build.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1747
diff changeset
    66
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
    67
7492
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
    68
# we need the 'ns3module' waf "feature" to be created because code
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
    69
# elsewhere looks for it to find the ns3 module objects.
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    70
@TaskGen.feature('ns3module')
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    71
def _add_test_code(module):
7492
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
    72
    pass
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    73
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
    74
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
    75
def create_ns3_module(bld, name, dependencies=(), test=False):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    76
    static = bool(bld.env.ENABLE_STATIC_NS3)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    77
    # Create a separate library for this module.
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    78
    if static:
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    79
        module = bld.new_task_gen(features=['cxx', 'cxxstlib', 'ns3module'])
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    80
    else:
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    81
        module = bld.new_task_gen(features=['cxx', 'cxxshlib', 'ns3module'])
7489
994360413f55 waf 1.6: bring back -Wl,--soname, fix waf warnings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7488
diff changeset
    82
    module.target = '%s/ns3-%s' % (bld.srcnode.relpath_gen(module.path), name)
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    83
    linkflags = []
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    84
    cxxflags = []
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    85
    ccflags = []
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    86
    if not static:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    87
        cxxflags = module.env['shlib_CXXFLAGS']
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    88
        ccflags = module.env['shlib_CXXFLAGS']
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    89
        # Turn on the link flags for shared libraries if we have the
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    90
        # proper compiler and platform.
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    91
        if module.env['CXX_NAME'] in ['gcc', 'icc'] and module.env['WL_SONAME_SUPPORTED']:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    92
            # Get the module library name without any relative paths
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    93
            # at its beginning because all of the libraries will end
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    94
            # up in the same directory.
7489
994360413f55 waf 1.6: bring back -Wl,--soname, fix waf warnings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7488
diff changeset
    95
            module_library_name = module.env.cshlib_PATTERN % (os.path.basename(module.target),)
994360413f55 waf 1.6: bring back -Wl,--soname, fix waf warnings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7488
diff changeset
    96
            linkflags = '-Wl,--soname=' + module_library_name
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    97
    cxxdefines = ["NS3_MODULE_COMPILATION"]
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    98
    ccdefines = ["NS3_MODULE_COMPILATION"]
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    99
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   100
    module.env.append_value('CXXFLAGS', cxxflags)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   101
    module.env.append_value('CCFLAGS', ccflags)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   102
    module.env.append_value('LINKFLAGS', linkflags)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   103
    module.env.append_value('CXXDEFINES', cxxdefines)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   104
    module.env.append_value('CCDEFINES', ccdefines)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   105
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   106
    module.is_static = static
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   107
    module.vnum = wutils.VNUM
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   108
    # Add the proper path to the module's name.
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   109
    # Set the libraries this module depends on.  
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   110
    module.module_deps = list(dependencies)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   111
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   112
    module.install_path = "${LIBDIR}"
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   113
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   114
    module.name = "ns3-" + name
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   115
    module.dependencies = dependencies
7023
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   116
    # Initially create an empty value for this because the pcfile
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   117
    # writing task assumes every module has a uselib attribute.
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   118
    module.uselib = ''
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   119
    module.use = ['ns3-' + dep for dep in dependencies]
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   120
    module.test = test
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   121
    module.is_ns3_module = True
7379
ff0d074f885a add support for --update-data to test.py, move test runner code to library for modular build, add support for hierarchical tests beyond the previous two-level hierarchy.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7354
diff changeset
   122
    module.ns3_dir_location = bld.path.relpath_gen(bld.srcnode)
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   123
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   124
    module.env.append_value("INCLUDES", '#')
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   125
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   126
    pcfilegen = bld(features='ns3pcfile')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   127
    pcfilegen.module = module
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   128
    
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   129
    return module
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   130
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   131
@TaskGen.feature("ns3testlib")
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   132
@TaskGen.before_method("apply_incpaths")
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   133
def apply_incpaths_ns3testlib(self):
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   134
    if not self.source:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   135
        return
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   136
    testdir = self.source[-1].parent.relpath_gen(self.bld.srcnode)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   137
    self.env.append_value("DEFINES", 'NS_TEST_SOURCEDIR="%s"' % (testdir,))
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   138
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   139
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   140
def create_ns3_module_test_library(bld, name):
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   141
    # Create an ns3 module for the test library that depends only on
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   142
    # the module being tested.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   143
    library_name = name + "-test"
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   144
    library = bld.create_ns3_module(library_name, [name], test=True)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   145
    library.features.append("ns3testlib")
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   146
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   147
    # Modify attributes for the test library that are different from a
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   148
    # normal module.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   149
    del library.is_ns3_module
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   150
    library.is_ns3_module_test_library = True
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   151
    library.module_name = 'ns3-' + name
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   152
6925
43d9c7eedf7b Test implicitly dependent modules
Mitch Watrous <watrous@u.washington.edu>
parents: 6921
diff changeset
   153
    # Add this module and test library to the list.
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   154
    bld.env.append_value('NS3_MODULES_WITH_TEST_LIBRARIES', [(library.module_name, library.name)])
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   155
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   156
    # Set the include path from the build directory to modules. 
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   157
    relative_path_from_build_to_here = bld.path.relpath_gen(bld.bldnode)
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   158
    include_flag = '-I' + relative_path_from_build_to_here
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   159
    library.env.append_value('CXXFLAGS', include_flag)
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   160
    library.env.append_value('CCFLAGS',  include_flag)
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   161
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   162
    return library
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   163
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   164
def create_obj(bld, *args):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   165
    warnings.warn("(in %s) Use bld.new_task_gen(...) now, instead of bld.create_obj(...)" % str(bld.path),
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   166
                  DeprecationWarning, stacklevel=2)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   167
    return bld.new_task_gen(*args)
955
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
   168
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   169
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   170
def ns3_python_bindings(bld):
7490
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   171
    if Options.options.apiscan:
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   172
        return
886cf992ade6 waf 1.6: fix python bindings apiscan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7489
diff changeset
   173
6933
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6925
diff changeset
   174
    # this method is called from a module wscript, so remember bld.path is not bindings/python!
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6925
diff changeset
   175
    module_abs_src_path = bld.path.abspath()
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6925
diff changeset
   176
    module = os.path.basename(module_abs_src_path)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   177
    env = bld.env
6933
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6925
diff changeset
   178
    env.append_value("MODULAR_BINDINGS_MODULES", "ns3-"+module)
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6925
diff changeset
   179
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   180
    if not env['ENABLE_PYTHON_BINDINGS']:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   181
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   182
6942
3b9ce3a727a5 ./waf --apiscan: fix bug in detection of whether the per-module bindings dir exists
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6941
diff changeset
   183
    bindings_dir = bld.path.find_dir("bindings")
3b9ce3a727a5 ./waf --apiscan: fix bug in detection of whether the per-module bindings dir exists
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6941
diff changeset
   184
    if bindings_dir is None or not os.path.exists(bindings_dir.abspath()):
6876
9ac9bd55541d Make ns3_python_bindings skip bindings with warning if apidefs dir not found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
   185
        warnings.warn("(in %s) Requested to build modular python bindings, but apidefs dir not found "
9ac9bd55541d Make ns3_python_bindings skip bindings with warning if apidefs dir not found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
   186
                      "=> skipped the bindings." % str(bld.path),
9ac9bd55541d Make ns3_python_bindings skip bindings with warning if apidefs dir not found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
   187
                      Warning, stacklevel=2)
9ac9bd55541d Make ns3_python_bindings skip bindings with warning if apidefs dir not found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
   188
        return
9ac9bd55541d Make ns3_python_bindings skip bindings with warning if apidefs dir not found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6875
diff changeset
   189
6920
b1b821ae64c1 Modular bindings: skip a binding module if the corresponding ns-3 module is not enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6913
diff changeset
   190
    if ("ns3-%s" % (module,)) not in env.NS3_ENABLED_MODULES:
b1b821ae64c1 Modular bindings: skip a binding module if the corresponding ns-3 module is not enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6913
diff changeset
   191
        #print "bindings for module %s which is not enabled, skip" % module
b1b821ae64c1 Modular bindings: skip a binding module if the corresponding ns-3 module is not enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6913
diff changeset
   192
        return
b1b821ae64c1 Modular bindings: skip a binding module if the corresponding ns-3 module is not enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6913
diff changeset
   193
6897
f338f17b0238 Modular bindings: generate a compatibility 'ns3' module that imports the modular bindings
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6894
diff changeset
   194
    env.append_value('PYTHON_MODULES_BUILT', module)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   195
    apidefs = env['PYTHON_BINDINGS_APIDEFS'].replace("-", "_")
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   196
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   197
    #debug = ('PYBINDGEN_DEBUG' in os.environ)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   198
    debug = True # XXX
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   199
    source = [bld.srcnode.find_resource('bindings/python/ns3modulegen-modular.py').relpath_gen(bld.path),
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   200
              "bindings/modulegen__%s.py" % apidefs]
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   201
6956
4a3bb1ba53fb Modular bindings: add missing dep on the modulegen_customizations.py file, when found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6946
diff changeset
   202
    if bindings_dir.find_resource("modulegen_customizations.py") is not None:
4a3bb1ba53fb Modular bindings: add missing dep on the modulegen_customizations.py file, when found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6946
diff changeset
   203
        source.append("bindings/modulegen_customizations.py")
4a3bb1ba53fb Modular bindings: add missing dep on the modulegen_customizations.py file, when found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6946
diff changeset
   204
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   205
    # the local customization file may or not exist
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   206
    if bld.path.find_resource("bindings/modulegen_local.py"):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   207
        source.append("bindings/modulegen_local.py")
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   208
6957
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   209
    module_py_name = module.replace('-', '_')
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   210
    module_target_dir = bld.srcnode.find_dir("bindings/python/ns").relpath_gen(bld.path)
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   211
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   212
    # if bindings/<module>.py exists, it becomes the module frontend, and the C extension befomes _<module>
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   213
    if bld.path.find_resource("bindings/%s.py" % (module_py_name,)) is not None:
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   214
        bld.new_task_gen(
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   215
            features='copy',
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   216
            source=("bindings/%s.py" % (module_py_name,)),
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   217
            target=('%s/%s.py' % (module_target_dir, module_py_name)))
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   218
        extension_name = '_%s' % (module_py_name,)
7349
30af4f227b21 Missing install of <module>.py files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7348
diff changeset
   219
        bld.install_files('${PYTHONDIR}/ns', ["bindings/%s.py" % (module_py_name,)])
6957
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   220
    else:
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   221
        extension_name = module_py_name
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   222
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   223
    target = ['bindings/ns3module.cc', 'bindings/ns3module.h', 'bindings/ns3modulegen.log']
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   224
    #if not debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   225
    #    target.append('ns3modulegen.log')
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   226
7408
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7384
diff changeset
   227
    argv = ['NS3_ENABLED_FEATURES=${FEATURES}',
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7384
diff changeset
   228
            'GCC_RTTI_ABI_COMPLETE=${GCC_RTTI_ABI_COMPLETE}',
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7384
diff changeset
   229
            '${PYTHON}']
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   230
    #if debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   231
    #    argv.extend(["-m", "pdb"])
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   232
    
6957
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   233
    argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, extension_name, '${TGT[0]}'])
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   234
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   235
    argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   236
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   237
    features = []
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   238
    for (name, caption, was_enabled, reason_not_enabled) in env['NS3_OPTIONAL_FEATURES']:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   239
        if was_enabled:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   240
            features.append(name)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   241
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   242
    bindgen = bld.new_task_gen(features=['command'], source=source, target=target, command=argv)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   243
    bindgen.env['FEATURES'] = ','.join(features)
7408
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7384
diff changeset
   244
    bindgen.dep_vars = ['FEATURES', "GCC_RTTI_ABI_COMPLETE"]
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   245
    bindgen.before = 'cxx'
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   246
    bindgen.after = 'gen_ns3_module_header'
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   247
    bindgen.name = "pybindgen(ns3 module %s)" % module
7545
ac0569e8cb7d Avoid installation of ns3modulegen-modular.py as a python module
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7541
diff changeset
   248
    bindgen.install_path = None
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   249
6957
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   250
    # generate the extension module
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   251
    pymod = bld.new_task_gen(features='cxx cxxshlib pyext')
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   252
    pymod.source = ['bindings/ns3module.cc']
6957
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   253
    pymod.target = '%s/%s' % (module_target_dir, extension_name)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   254
    pymod.name = 'ns3module_%s' % module
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   255
    pymod.use = ["%s" % mod for mod in pymod.env['NS3_ENABLED_MODULES']] #  Should be '"ns3-"+module', but see bug 1117
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   256
    if pymod.env['ENABLE_STATIC_NS3']:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   257
        if sys.platform == 'darwin':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   258
            pymod.env.append_value('LINKFLAGS', '-Wl,-all_load')
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   259
            for mod in pymod.usel:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   260
                #mod = mod.split("--lib")[0]
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   261
                pymod.env.append_value('LINKFLAGS', '-l' + mod)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   262
        else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   263
            pymod.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   264
            for mod in pymod.use:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   265
                #mod = mod.split("--lib")[0]
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   266
                pymod.env.append_value('LINKFLAGS', '-l' + mod)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   267
            pymod.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7492
diff changeset
   268
    defines = list(pymod.env['DEFINES'])
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   269
    defines.extend(['NS_DEPRECATED=', 'NS3_DEPRECATED_H'])
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   270
    if Options.platform == 'win32':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   271
        try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   272
            defines.remove('_DEBUG') # causes undefined symbols on win32
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   273
        except ValueError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   274
            pass
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7492
diff changeset
   275
    pymod.env['DEFINES'] = defines
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   276
    pymod.includes = '# bindings'
7348
9372b57a6ce4 Bug 1200 - ./waf install doesn't install Python bindings properly
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7345
diff changeset
   277
    pymod.install_path = '${PYTHONDIR}/ns'
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   278
    return pymod
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   279
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   280
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   281
def build(bld):
1217
2f7791ae388d WAF: add new bld.create_ns3_module() and bld.create_ns3_program() methods to make declaration of modules and programs simpler, and allowing us to change how ns-3 is built in a centralized way, without needing to change every module wscript file.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1214
diff changeset
   282
    bld.create_ns3_module = types.MethodType(create_ns3_module, bld)
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   283
    bld.create_ns3_module_test_library = types.MethodType(create_ns3_module_test_library, bld)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   284
    bld.create_obj = types.MethodType(create_obj, bld)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   285
    bld.ns3_python_bindings = types.MethodType(ns3_python_bindings, bld)
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
   286
    
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   287
    # Remove these modules from the list of all modules.
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   288
    for not_built in bld.env['MODULES_NOT_BUILT']:
7303
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   289
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   290
        # XXX Becaue these modules are located in subdirectories of
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   291
        # test, their names in the all_modules list include the extra
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   292
        # relative path "test/".  If these modules are moved into the
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   293
        # src directory, then this if block should be removed.
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   294
        if not_built == 'ns3tcp' or not_built == 'ns3wifi':
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   295
            not_built = 'test/' + not_built
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   296
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   297
        if not_built in all_modules:
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   298
            all_modules.remove(not_built)
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   299
969
3c3ce40492a6 WAF: make list of modules (all_modules) a tuple instead of list, because it is hashable, and this way newer WAF is able to notice changes in it and automatically trigger a reconfiguration.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 968
diff changeset
   300
    bld.add_subdirs(list(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
   301
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   302
    for module in all_modules:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   303
        modheader = bld.new_task_gen(features=['ns3moduleheader'])
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   304
        modheader.module = module.split('/')[-1]
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   305
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   306
class ns3pcfile_task(Task.Task):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   307
    after = 'cc cxx'
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   308
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   309
    def __str__(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   310
        "string to display to the user"
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   311
        tgt_str = ' '.join([a.nice_path(self.env) for a in self.outputs])
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   312
        return 'pcfile: %s\n' % (tgt_str)
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   313
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   314
    def runnable_status(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   315
        return super(ns3pcfile_task, self).runnable_status()
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   316
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   317
    def _self_libs(self, env, name, libdir):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   318
        if env['ENABLE_STATIC_NS3']:
7520
a61ef851d443 Fix issue with generating .pc file in static build
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7514
diff changeset
   319
            path_st = 'STLIBPATH_ST'
a61ef851d443 Fix issue with generating .pc file in static build
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7514
diff changeset
   320
            lib_st = 'STLIB_ST'
a61ef851d443 Fix issue with generating .pc file in static build
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7514
diff changeset
   321
            lib_marker = 'STLIB_MARKER'
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   322
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   323
            path_st = 'LIBPATH_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   324
            lib_st = 'LIB_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   325
            lib_marker = 'SHLIB_MARKER'
7523
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   326
        retval = [env[path_st] % libdir]
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   327
        if env[lib_marker]:
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   328
            retval.append(env[lib_marker])
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   329
        retval.append(env[lib_st] % name)
7070
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   330
        return retval
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   331
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   332
    def _lib(self, env, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   333
        libpath = env['LIBPATH_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   334
        linkflags = env['LINKFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   335
        libs = env['LIB_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   336
        retval = []
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   337
        for path in libpath:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   338
            retval.append(env['LIBPATH_ST'] % path)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   339
            retval = retval + linkflags
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   340
        for lib in libs:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   341
            retval.append(env['LIB_ST'] % lib)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   342
        return retval
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   343
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   344
    def _listify(self, v):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   345
        if isinstance(v, list):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   346
            return v
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   347
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   348
            return [v]
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   349
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   350
    def _cflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   351
        flags = self.env['CFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   352
        return self._listify(flags)
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   353
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   354
    def _cxxflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   355
        return self._listify(self.env['CXXFLAGS_%s' % dep])
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   356
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   357
    def _defines(self, dep):
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   358
        return [self.env['DEFINES_ST'] % define for define in self.env['DEFINES_%s' % dep]] 
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   359
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   360
    def _includes(self, dep):
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   361
        includes = self.env['INCLUDES_%s' % dep]
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   362
        return [self.env['CPPPATH_ST'] % include for include in includes]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   363
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   364
    def _generate_pcfile(self, name, use, env, outfilename):
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   365
        outfile = open(outfilename, 'wt')
7345
850237ab2111 Bug 1199 - waf install doesn't work on x86_64
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7331
diff changeset
   366
        prefix = env.PREFIX
7379
ff0d074f885a add support for --update-data to test.py, move test runner code to library for modular build, add support for hierarchical tests beyond the previous two-level hierarchy.
Mathieu Lacage <mathieu.lacage@gmail.com>
parents: 7354
diff changeset
   367
        includedir = env.INCLUDEDIR
7345
850237ab2111 Bug 1199 - waf install doesn't work on x86_64
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7331
diff changeset
   368
        libdir = env.LIBDIR
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   369
        libs = self._self_libs(env, name, '${libdir}')
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   370
        for dep in use:
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   371
            libs += self._lib(env, dep)
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   372
        for dep in env.LIBS:
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   373
            libs += self.env['LIB_ST'] % dep
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   374
        cflags = [self.env['CPPPATH_ST'] % '${includedir}']
7514
cac200ed9c0a Add Requires: to the .pc file indicating inter-module dependencies
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7512
diff changeset
   375
        requires = []
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   376
        for dep in use:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   377
            cflags = cflags + self._cflags(dep) + self._cxxflags(dep) + \
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   378
                self._defines(dep) + self._includes(dep)
7514
cac200ed9c0a Add Requires: to the .pc file indicating inter-module dependencies
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7512
diff changeset
   379
            if dep.startswith('ns3-'):
cac200ed9c0a Add Requires: to the .pc file indicating inter-module dependencies
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7512
diff changeset
   380
                requires.append("lib"+dep)
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   381
        print >> outfile, """
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   382
prefix=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   383
libdir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   384
includedir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   385
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   386
Name: lib%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   387
Description: ns-3 module %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   388
Version: devel
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   389
Libs: %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   390
Cflags: %s
7514
cac200ed9c0a Add Requires: to the .pc file indicating inter-module dependencies
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7512
diff changeset
   391
Requires: %s
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   392
""" % (prefix, libdir, includedir,
7514
cac200ed9c0a Add Requires: to the .pc file indicating inter-module dependencies
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7512
diff changeset
   393
       name, name, ' '.join(libs), ' '.join(cflags), ' '.join(requires))
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   394
        outfile.close()
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   395
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   396
    def run(self):
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   397
        output_filename = self.outputs[0].abspath()
7522
8a7aec72d793 Don't pass first name in list when generating the pc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7521
diff changeset
   398
        self._generate_pcfile(self.module.name, 
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   399
                              self.module.to_list(self.module.use),
7345
850237ab2111 Bug 1199 - waf install doesn't work on x86_64
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7331
diff changeset
   400
                              self.env, output_filename)
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   401
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   402
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   403
@TaskGen.feature('ns3pcfile')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   404
@TaskGen.after_method('process_rule')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   405
def apply(self):
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   406
    output_filename = 'lib%s.pc' % self.module.name
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   407
    output_node = self.path.find_or_declare(output_filename)
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   408
    assert output_node is not None, str(self)
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   409
    task = self.create_task('ns3pcfile')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   410
    self.bld.install_files('${LIBDIR}/pkgconfig', output_node)
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   411
    task.set_outputs([output_node])
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   412
    task.module = self.module
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   413
1220
4933e0890acd Build all modules as a single ns3 shared library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1217
diff changeset
   414
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   415
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   416
@TaskGen.feature('ns3header')
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   417
@TaskGen.after_method('process_rule')
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   418
def apply_ns3header(self):
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   419
    if self.module is None:
7496
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
   420
        raise WafError("'module' missing on ns3headers object %s" % self)
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   421
    ns3_dir_node = self.bld.path.find_dir("ns3")
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   422
    for filename in set(self.to_list(self.source)):
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   423
        src_node = self.path.find_resource(filename)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   424
        if src_node is None:
7496
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
   425
            raise WafError("source ns3 header file %s not found" % (filename,))
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   426
        dst_node = ns3_dir_node.find_or_declare(src_node.name)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   427
        assert dst_node is not None
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   428
        task = self.create_task('ns3header')
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   429
        task.mode = getattr(self, 'mode', 'install')
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   430
        if task.mode == 'install':
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   431
            self.bld.install_files('${PREFIX}/include/ns3', [src_node])
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   432
            task.set_inputs([src_node])
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   433
            task.set_outputs([dst_node])
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   434
        else:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   435
            task.header_to_remove = dst_node
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   436
    self.headers = set(self.to_list(self.source))
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   437
    self.source = '' # tell WAF not to process these files further
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
   438
7492
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   439
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   440
class ns3header_task(Task.Task):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   441
    before = 'cc cxx gen_ns3_module_header'
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   442
    color = 'BLUE'
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   443
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   444
    def __str__(self):
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   445
        "string to display to the user"
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   446
        env = self.env
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   447
        src_str = ' '.join([a.nice_path(env) for a in self.inputs])
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   448
        tgt_str = ' '.join([a.nice_path(env) for a in self.outputs])
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   449
        if self.outputs: sep = ' -> '
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   450
        else: sep = ''
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   451
        if self.mode == 'remove':
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   452
            return 'rm-ns3-header %s\n' % (self.header_to_remove.abspath(),)
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   453
        return 'install-ns3-header: %s%s%s\n' % (src_str, sep, tgt_str)
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   454
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   455
    def __repr__(self):
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   456
        return str(self)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   457
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   458
    def uid(self):
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   459
        try:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   460
            return self.uid_
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   461
        except AttributeError:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   462
            m = Utils.md5()
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   463
            up = m.update
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   464
            up(self.__class__.__name__.encode())
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   465
            for x in self.inputs + self.outputs:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   466
                up(x.abspath().encode())
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   467
            up(self.mode)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   468
            if self.mode == 'remove':
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   469
                up(self.header_to_remove.abspath().encode())
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   470
            self.uid_ = m.digest()
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   471
            return self.uid_
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   472
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   473
    def runnable_status(self):
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   474
        if self.mode == 'remove':
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   475
            if os.path.exists(self.header_to_remove.abspath()):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   476
                return Task.RUN_ME
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   477
            else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   478
                return Task.SKIP_ME
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   479
        else:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   480
            return super(ns3header_task, self).runnable_status()
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   481
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   482
    def run(self):
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   483
        if self.mode == 'install':
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   484
            assert len(self.inputs) == len(self.outputs)
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   485
            inputs = [node.abspath() for node in self.inputs]
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   486
            outputs = [node.abspath() for node in self.outputs]
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   487
            for src, dst in zip(inputs, outputs):
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   488
                try:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   489
                    os.chmod(dst, 0600)
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   490
                except OSError:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   491
                    pass
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   492
                shutil.copy2(src, dst)
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   493
                ## make the headers in builddir read-only, to prevent
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   494
                ## accidental modification
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   495
                os.chmod(dst, 0400)
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   496
            return 0
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   497
        else:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   498
            assert len(self.inputs) == 0
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   499
            assert len(self.outputs) == 0
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   500
            out_file_name = self.header_to_remove.abspath()
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   501
            try:
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   502
                os.unlink(out_file_name)
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   503
            except OSError, ex:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   504
                if ex.errno != 2:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   505
                    raise
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   506
            return 0
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   507
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   508
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   509
class gen_ns3_module_header_task(Task.Task):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   510
    before = 'cc cxx'
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   511
    after = 'ns3header'
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   512
    color = 'BLUE'
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   513
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   514
    def runnable_status(self):
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   515
        if self.mode == 'remove':
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   516
            if os.path.exists(self.header_to_remove.abspath()):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   517
                return Task.RUN_ME
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   518
            else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   519
                return Task.SKIP_ME
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   520
        else:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   521
            return super(gen_ns3_module_header_task, self).runnable_status()
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   522
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   523
    def __str__(self):
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   524
        "string to display to the user"
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   525
        env = self.env
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   526
        src_str = ' '.join([a.nice_path(env) for a in self.inputs])
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   527
        tgt_str = ' '.join([a.nice_path(env) for a in self.outputs])
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   528
        if self.outputs: sep = ' -> '
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   529
        else: sep = ''
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   530
        if self.mode == 'remove':
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   531
            return 'rm-module-header %s\n' % (self.header_to_remove.abspath(),)
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   532
        return 'gen-module-header: %s%s%s\n' % (src_str, sep, tgt_str)
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   533
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   534
    def run(self):
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   535
        if self.mode == 'remove':
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   536
            assert len(self.inputs) == 0
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   537
            assert len(self.outputs) == 0
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   538
            out_file_name = self.header_to_remove.abspath()
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   539
            try:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   540
                os.unlink(out_file_name)
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   541
            except OSError, ex:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   542
                if ex.errno != 2:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   543
                    raise
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   544
            return 0
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   545
        assert len(self.outputs) == 1
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   546
        out_file_name = self.outputs[0].get_bld().abspath()#self.env)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   547
        header_files = [os.path.basename(node.abspath()) for node in self.inputs]
6647
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   548
        outfile = file(out_file_name, "w")
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   549
        header_files.sort()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   550
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   551
        print >> outfile, """
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   552
#ifdef NS3_MODULE_COMPILATION
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   553
# error "Do not include ns3 module aggregator headers from other modules; these are meant only for end user scripts."
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   554
#endif
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   555
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   556
#ifndef NS3_MODULE_%s
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   557
    """ % (self.module.upper().replace('-', '_'),)
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   558
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   559
    #     if self.module_deps:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   560
    #         print >> outfile, "// Module dependencies:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   561
    #     for dep in self.module_deps:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   562
    #         print >> outfile, "#include \"%s-module.h\"" % dep
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   563
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   564
        print >> outfile
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   565
        print >> outfile, "// Module headers:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   566
        for header in header_files:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   567
            print >> outfile, "#include \"%s\"" % (header,)
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   568
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   569
        print >> outfile, "#endif"
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   570
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   571
        outfile.close()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   572
        return 0
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   573
4126
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   574
    def sig_explicit_deps(self):
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   575
        self.m.update('\n'.join([node.abspath() for node in self.inputs]))
6671
b3d5193a2f94 Bug 1004 - module header not rebuilt
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   576
        return self.m.digest()
4126
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   577
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   578
    def unique_id(self):
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   579
        try:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   580
            return self.uid
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   581
        except AttributeError:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   582
            "this is not a real hot zone, but we want to avoid surprizes here"
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
   583
            m = Utils.md5()
4126
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   584
            m.update("ns-3-module-header-%s" % self.module)
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   585
            self.uid = m.digest()
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   586
            return self.uid
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   587
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   588
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   589
# Generates a 'ns3/foo-module.h' header file that includes all public
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   590
# ns3 headers of a certain module.
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   591
@TaskGen.feature('ns3moduleheader')
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   592
@TaskGen.after_method('process_rule')
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   593
def apply_ns3moduleheader(self):
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   594
    ## get all of the ns3 headers
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   595
    ns3_dir_node = self.bld.path.find_dir("ns3")
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   596
    all_headers_inputs = []
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   597
    found_the_module = False
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   598
    for ns3headers in self.bld.all_task_gen:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   599
        if 'ns3header' in getattr(ns3headers, "features", []):
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   600
            if ns3headers.module != self.module:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   601
                continue
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   602
            found_the_module = True
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   603
            for source in ns3headers.headers:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   604
                source = os.path.basename(source)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   605
                node = ns3_dir_node.find_or_declare(os.path.basename(source))
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   606
                if node is None:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   607
                    fatal("missing header file %s" % (source,))
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   608
                all_headers_inputs.append(node)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   609
    if not found_the_module:
7496
ce1ec79d488c waf1.6: make the all_modules in src/wscript be automatically discovered
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7494
diff changeset
   610
        raise WafError("error finding headers for module %s" % self.module)
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   611
    if not all_headers_inputs:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   612
        return
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   613
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   614
    try:
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   615
        module_obj = self.bld.get_tgen_by_name("ns3-" + self.module)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   616
    except WafError: # maybe the module was disabled, and therefore removed
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   617
        return
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   618
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   619
    all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)]
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   620
    task = self.create_task('gen_ns3_module_header')
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   621
    task.module = self.module
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   622
    task.mode = getattr(self, "mode", "install")
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   623
    if task.mode == 'install':
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   624
        assert module_obj is not None, self.module
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   625
        self.bld.install_files('${PREFIX}/include/ns3', 
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   626
                               ns3_dir_node.find_or_declare("%s-module.h" % self.module))
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   627
        task.set_inputs(all_headers_inputs)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   628
        task.set_outputs(all_headers_outputs)
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   629
        task.module_deps = module_obj.module_deps
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   630
    else:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   631
        task.header_to_remove = all_headers_outputs[0]