src/wscript
author Tom Henderson <tomh@tomh.org>
Fri, 21 Dec 2012 14:41:04 -0800
changeset 9206 49d343e55cae
parent 9173 513f8ec65729
child 9278 0a749c0f1afd
permissions -rw-r--r--
update release notes
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'):
7675
ed27d2555ec5 fix nit in wscript
Tom Henderson <tomh@tomh.org>
parents: 7673
diff changeset
    27
    if dirname.startswith('.') or dirname == 'CVS':
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
    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:
9173
513f8ec65729 bug 1525 Linker error with mpi on Mac 10.8
Brian Swenson <bswenson3@gatech.edu>
parents: 8894
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
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
    74
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
    75
    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
    76
    # 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
    77
    if static:
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    78
        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
    79
    else:
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    80
        module = bld.new_task_gen(features=['cxx', 'cxxshlib', 'ns3module'])
8894
90d67c5e8255 Bug 1445 - When build with "-d release", don't suffix "-release"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8702
diff changeset
    81
    module.target = '%s/ns%s-%s%s' % (bld.srcnode.relpath_gen(module.path), wutils.VERSION,
90d67c5e8255 Bug 1445 - When build with "-d release", don't suffix "-release"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8702
diff changeset
    82
                                       name, bld.env.BUILD_SUFFIX)
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
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   126
    module.pcfilegen = bld(features='ns3pcfile')
7821
270a2b7f82ad Bug 1406 - waf exits with maximum recursion depth exceeded while calling a Python object if wscript has wrong filename
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7688
diff changeset
   127
    module.pcfilegen.module = module.name
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
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
   172
    # 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
   173
    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
   174
    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
   175
    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
   176
    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
   177
7583
e42004e38839 Fix issue with waf --apiscan=all
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   178
    if Options.options.apiscan:
e42004e38839 Fix issue with waf --apiscan=all
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   179
        return
e42004e38839 Fix issue with waf --apiscan=all
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   180
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   181
    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
   182
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   183
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
   184
    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
   185
    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
   186
        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
   187
                      "=> 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
   188
                      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
   189
        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
   190
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
   191
    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
   192
        #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
   193
        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
   194
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
   195
    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
   196
    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
   197
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   198
    #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
   199
    debug = True # XXX
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   200
    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
   201
              "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
   202
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
   203
    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
   204
        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
   205
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   206
    # 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
   207
    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
   208
        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
   209
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
   210
    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
   211
    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
   212
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 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
   214
    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
   215
        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
   216
            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
   217
            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
   218
            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
   219
        extension_name = '_%s' % (module_py_name,)
7673
1997b1a91020 Install python modules to PYTHONARCHDIR instead of PYTHONDIR; should fix #1329.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7667
diff changeset
   220
        bld.install_files('${PYTHONARCHDIR}/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
   221
    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
   222
        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
   223
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   224
    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
   225
    #if not debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   226
    #    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
   227
7408
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7384
diff changeset
   228
    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
   229
            '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
   230
            '${PYTHON}']
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   231
    #if debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   232
    #    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
   233
    
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
   234
    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
   235
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   236
    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
   237
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   238
    features = []
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   239
    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
   240
        if was_enabled:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   241
            features.append(name)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   242
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   243
    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
   244
    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
   245
    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
   246
    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
   247
    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
   248
    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
   249
    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
   250
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
   251
    # 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
   252
    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
   253
    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
   254
    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
   255
    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
   256
    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
   257
    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
   258
        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
   259
            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
   260
            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
   261
                #mod = mod.split("--lib")[0]
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   262
                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
   263
        else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   264
            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
   265
            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
   266
                #mod = mod.split("--lib")[0]
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   267
                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
   268
            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
   269
    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
   270
    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
   271
    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
   272
        try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   273
            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
   274
        except ValueError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   275
            pass
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7492
diff changeset
   276
    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
   277
    pymod.includes = '# bindings'
7673
1997b1a91020 Install python modules to PYTHONARCHDIR instead of PYTHONDIR; should fix #1329.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7667
diff changeset
   278
    pymod.install_path = '${PYTHONARCHDIR}/ns'
7678
a4c56ef461ba Bug 1335 - waf 1.6.10 upgrade breaks OS X build when Python enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7675
diff changeset
   279
a4c56ef461ba Bug 1335 - waf 1.6.10 upgrade breaks OS X build when Python enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7675
diff changeset
   280
    # Workaround to a WAF bug, remove this when ns-3 upgrades to WAF > 1.6.10
a4c56ef461ba Bug 1335 - waf 1.6.10 upgrade breaks OS X build when Python enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7675
diff changeset
   281
    # https://www.nsnam.org/bugzilla/show_bug.cgi?id=1335
a4c56ef461ba Bug 1335 - waf 1.6.10 upgrade breaks OS X build when Python enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7675
diff changeset
   282
    # http://code.google.com/p/waf/issues/detail?id=1098
7679
5a9a0a21b553 Bug #1335 postfix
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7678
diff changeset
   283
    if Utils.unversioned_sys_platform() == 'darwin':
5a9a0a21b553 Bug #1335 postfix
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7678
diff changeset
   284
        pymod.mac_bundle = True
7678
a4c56ef461ba Bug 1335 - waf 1.6.10 upgrade breaks OS X build when Python enabled
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7675
diff changeset
   285
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   286
    return pymod
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   287
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   288
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   289
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
   290
    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
   291
    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
   292
    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
   293
    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
   294
    
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   295
    # 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
   296
    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
   297
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   298
        # 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
   299
        # 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
   300
        # 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
   301
        # 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
   302
        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
   303
            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
   304
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   305
        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
   306
            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
   307
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
   308
    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
   309
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
   310
    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
   311
        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
   312
        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
   313
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   314
class ns3pcfile_task(Task.Task):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   315
    after = 'cc cxx'
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 __str__(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   318
        "string to display to the user"
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   319
        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
   320
        return 'pcfile: %s\n' % (tgt_str)
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   321
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   322
    def runnable_status(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   323
        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
   324
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   325
    def _self_libs(self, env, name, libdir):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   326
        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
   327
            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
   328
            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
   329
            lib_marker = 'STLIB_MARKER'
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   330
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   331
            path_st = 'LIBPATH_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   332
            lib_st = 'LIB_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   333
            lib_marker = 'SHLIB_MARKER'
7523
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   334
        retval = [env[path_st] % libdir]
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   335
        if env[lib_marker]:
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   336
            retval.append(env[lib_marker])
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   337
        retval.append(env[lib_st] % name)
7070
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   338
        return retval
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   339
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   340
    def _lib(self, env, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   341
        libpath = env['LIBPATH_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   342
        linkflags = env['LINKFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   343
        libs = env['LIB_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   344
        retval = []
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   345
        for path in libpath:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   346
            retval.append(env['LIBPATH_ST'] % path)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   347
            retval = retval + linkflags
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   348
        for lib in libs:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   349
            retval.append(env['LIB_ST'] % lib)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   350
        return retval
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   351
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   352
    def _listify(self, v):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   353
        if isinstance(v, list):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   354
            return v
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   355
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   356
            return [v]
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   357
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   358
    def _cflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   359
        flags = self.env['CFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   360
        return self._listify(flags)
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   361
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   362
    def _cxxflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   363
        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
   364
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   365
    def _defines(self, dep):
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   366
        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
   367
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   368
    def _includes(self, dep):
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   369
        includes = self.env['INCLUDES_%s' % dep]
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   370
        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
   371
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   372
    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
   373
        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
   374
        prefix = env.PREFIX
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   375
        includedir = Utils.subst_vars('${INCLUDEDIR}/%s%s' % (wutils.APPNAME, wutils.VERSION), env)
7345
850237ab2111 Bug 1199 - waf install doesn't work on x86_64
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7331
diff changeset
   376
        libdir = env.LIBDIR
8894
90d67c5e8255 Bug 1445 - When build with "-d release", don't suffix "-release"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8702
diff changeset
   377
        libs = self._self_libs(env, "%s%s-%s%s" % (wutils.APPNAME, wutils.VERSION, name[4:], env.BUILD_SUFFIX), '${libdir}')
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   378
        for dep in use:
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   379
            libs += self._lib(env, dep)
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   380
        for dep in env.LIBS:
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   381
            libs += self.env['LIB_ST'] % dep
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   382
        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
   383
        requires = []
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   384
        for dep in use:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   385
            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
   386
                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
   387
            if dep.startswith('ns3-'):
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   388
                dep_name = dep[4:]
8894
90d67c5e8255 Bug 1445 - When build with "-d release", don't suffix "-release"
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 8702
diff changeset
   389
                requires.append("libns%s-%s%s" % (wutils.VERSION, dep_name, env.BUILD_SUFFIX))
7667
42dda4375d79 Bug 1332 - Generated .pc files have blank line above and below the text
Vedran Miletić <rivanvx@gmail.com>
parents: 7583
diff changeset
   390
        print >> outfile, """\
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   391
prefix=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   392
libdir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   393
includedir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   394
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   395
Name: lib%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   396
Description: ns-3 module %s
7688
6f5c9b870e45 Still Bug 1327: disable VNUM in libraries, fix the .pc file deps
Vedran Miletić
parents: 7681
diff changeset
   397
Version: %s
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   398
Libs: %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   399
Cflags: %s
7667
42dda4375d79 Bug 1332 - Generated .pc files have blank line above and below the text
Vedran Miletić <rivanvx@gmail.com>
parents: 7583
diff changeset
   400
Requires: %s\
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   401
""" % (prefix, libdir, includedir,
7688
6f5c9b870e45 Still Bug 1327: disable VNUM in libraries, fix the .pc file deps
Vedran Miletić
parents: 7681
diff changeset
   402
       name, name, wutils.VERSION, ' '.join(libs), ' '.join(cflags), ' '.join(requires))
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   403
        outfile.close()
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   404
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   405
    def run(self):
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   406
        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
   407
        self._generate_pcfile(self.module.name, 
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   408
                              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
   409
                              self.env, output_filename)
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   410
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   411
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   412
@TaskGen.feature('ns3pcfile')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   413
@TaskGen.after_method('process_rule')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   414
def apply(self):
7821
270a2b7f82ad Bug 1406 - waf exits with maximum recursion depth exceeded while calling a Python object if wscript has wrong filename
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7688
diff changeset
   415
    module = self.bld.find_ns3_module(self.module)
270a2b7f82ad Bug 1406 - waf exits with maximum recursion depth exceeded while calling a Python object if wscript has wrong filename
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7688
diff changeset
   416
    output_filename = 'lib%s.pc' % os.path.basename(module.target)
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   417
    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
   418
    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
   419
    task = self.create_task('ns3pcfile')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   420
    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
   421
    task.set_outputs([output_node])
7821
270a2b7f82ad Bug 1406 - waf exits with maximum recursion depth exceeded while calling a Python object if wscript has wrong filename
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7688
diff changeset
   422
    task.module = module
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   423
1220
4933e0890acd Build all modules as a single ns3 shared library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1217
diff changeset
   424
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
   425
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   426
@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
   427
@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
   428
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
   429
    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
   430
        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
   431
    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
   432
    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
   433
        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
   434
        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
   435
            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
   436
        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
   437
        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
   438
        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
   439
        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
   440
        if task.mode == 'install':
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   441
            self.bld.install_files('${INCLUDEDIR}/%s%s/ns3' % (wutils.APPNAME, wutils.VERSION), [src_node])
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   442
            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
   443
            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
   444
        else:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   445
            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
   446
    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
   447
    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
   448
7492
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   449
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   450
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
   451
    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
   452
    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
   453
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
    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
   455
        "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
   456
        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
   457
        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
   458
        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
   459
        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
   460
        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
   461
        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
   462
            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
   463
        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
   464
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   465
    def __repr__(self):
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   466
        return str(self)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   467
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   468
    def uid(self):
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   469
        try:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   470
            return self.uid_
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   471
        except AttributeError:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   472
            m = Utils.md5()
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   473
            up = m.update
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   474
            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
   475
            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
   476
                up(x.abspath().encode())
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   477
            up(self.mode)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   478
            if self.mode == 'remove':
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   479
                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
   480
            self.uid_ = m.digest()
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   481
            return self.uid_
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   482
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
    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
   484
        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
   485
            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
   486
                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
   487
            else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   488
                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
   489
        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
   490
            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
   491
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   492
    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
   493
        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
   494
            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
   495
            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
   496
            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
   497
            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
   498
                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
   499
                    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
   500
                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
   501
                    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
   502
                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
   503
                ## 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
   504
                ## 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
   505
                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
   506
            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
   507
        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
   508
            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
   509
            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
   510
            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
   511
            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
   512
                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
   513
            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
   514
                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
   515
                    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
   516
            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
   517
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
   518
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   519
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
   520
    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
   521
    after = 'ns3header'
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   522
    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
   523
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
    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
   525
        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
   526
            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
   527
                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
   528
            else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   529
                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
   530
        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
   531
            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
   532
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
    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
   534
        "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
   535
        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
   536
        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
   537
        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
   538
        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
   539
        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
   540
        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
   541
            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
   542
        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
   543
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   544
    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
   545
        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
   546
            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
   547
            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
   548
            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
   549
            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
   550
                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
   551
            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
   552
                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
   553
                    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
   554
            return 0
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   555
        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
   556
        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
   557
        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
   558
        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
   559
        header_files.sort()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   560
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   561
        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
   562
#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
   563
# 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
   564
#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
   565
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
   566
#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
   567
    """ % (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
   568
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   569
    #     if self.module_deps:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   570
    #         print >> outfile, "// Module dependencies:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   571
    #     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
   572
    #         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
   573
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   574
        print >> outfile
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   575
        print >> outfile, "// Module headers:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   576
        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
   577
            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
   578
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   579
        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
   580
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   581
        outfile.close()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   582
        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
   583
4126
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   584
    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
   585
        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
   586
        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
   587
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   588
    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
   589
        try:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   590
            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
   591
        except AttributeError:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   592
            "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
   593
            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
   594
            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
   595
            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
   596
            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
   597
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
   598
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   599
# 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
   600
# 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
   601
@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
   602
@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
   603
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
   604
    ## 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
   605
    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
   606
    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
   607
    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
   608
    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
   609
        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
   610
            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
   611
                continue
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   612
            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
   613
            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
   614
                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
   615
                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
   616
                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
   617
                    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
   618
                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
   619
    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
   620
        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
   621
    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
   622
        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
   623
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   624
    try:
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   625
        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
   626
    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
   627
        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
   628
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   629
    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
   630
    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
   631
    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
   632
    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
   633
    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
   634
        assert module_obj is not None, self.module
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   635
        self.bld.install_files('${INCLUDEDIR}/%s%s/ns3' % (wutils.APPNAME, wutils.VERSION),
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   636
                               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
   637
        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
   638
        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
   639
        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
   640
    else:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   641
        task.header_to_remove = all_headers_outputs[0]