src/wscript
author Tommaso Pecorella <tommaso.pecorella@unifi.it>
Wed, 17 Jul 2013 23:34:17 +0200
changeset 9955 d97de2f9fbe5
parent 9278 0a749c0f1afd
child 10658 2a407999964e
permissions -rw-r--r--
Fix address parsing from Mac[16,48.64]Address
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
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
     9
from waflib import TaskGen, Task, Options, Build, Utils
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    10
from waflib.Errors import WafError
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
    11
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
    12
6168
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    13
try:
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    14
    set
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    15
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
    16
    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
    17
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
    18
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
    19
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
    20
for dirname in os.listdir('src'):
7675
ed27d2555ec5 fix nit in wscript
Tom Henderson <tomh@tomh.org>
parents: 7673
diff changeset
    21
    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
    22
        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
    23
    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
    24
    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
    25
        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
    26
    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
    27
        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
    28
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
    29
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
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
    31
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    32
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
    33
    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
    34
                   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
    35
                         " (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
    36
                         " --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
    37
                         " 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
    38
                   action="store_true", dest='enable_rpath', default=False)
4164
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4163
diff changeset
    39
    
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
    40
    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
    41
                   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
    42
                   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
    43
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    44
    opt.load('boost', tooldir=['waf-tools'])
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    45
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
    46
    for module in all_modules:
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    47
        opt.recurse(module, mandatory=False)
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
    48
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    49
def configure(conf):
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    50
    conf.env['REQUIRED_BOOST_LIBS'] = []
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
    51
    for module in all_modules:
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    52
        conf.recurse (module, name="required_boost_libs", mandatory=False)
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    53
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    54
    if conf.env['REQUIRED_BOOST_LIBS'] is not []:
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    55
        conf.load('boost')
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    56
        conf.check_boost(lib=' '.join (conf.env['REQUIRED_BOOST_LIBS']), mandatory=False)
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    57
        if not conf.env['LIB_BOOST']:
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    58
            conf.check_boost(lib=' '.join (conf.env['REQUIRED_BOOST_LIBS']), libpath="/usr/lib64", mandatory=False)
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    59
            if not conf.env['LIB_BOOST']:
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    60
                conf.env['LIB_BOOST'] = []
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    61
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    62
    for module in all_modules:
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    63
        conf.recurse(module, mandatory=False)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    64
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    65
    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
    66
    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
    67
    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
    68
        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
    69
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5270
diff changeset
    70
    ## 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
    71
    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
    72
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
    73
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
    74
7492
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
    75
# 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
    76
# 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
    77
@TaskGen.feature('ns3module')
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    78
def _add_test_code(module):
7492
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
    79
    pass
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
    80
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
    81
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
    82
    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
    83
    # 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
    84
    if static:
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    85
        module = bld(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
    86
    else:
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    87
        module = bld(features='cxx cxxshlib ns3module')
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
    88
    module.target = '%s/ns%s-%s%s' % (bld.srcnode.path_from(module.path), wutils.VERSION,
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
    89
                                       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
    90
    linkflags = []
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    91
    cxxflags = []
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    92
    ccflags = []
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
    93
    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
    94
        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
    95
        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
    96
        # 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
    97
        # 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
    98
        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
    99
            # 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
   100
            # 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
   101
            # 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
   102
            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
   103
            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
   104
    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
   105
    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
   106
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   107
    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
   108
    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
   109
    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
   110
    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
   111
    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
   112
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   113
    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
   114
    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
   115
    # 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
   116
    # 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
   117
    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
   118
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   119
    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
   120
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   121
    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
   122
    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
   123
    # 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
   124
    # 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
   125
    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
   126
    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
   127
    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
   128
    module.is_ns3_module = True
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   129
    module.ns3_dir_location = bld.path.path_from(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
   130
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   131
    module.env.append_value("INCLUDES", '#')
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   132
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   133
    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
   134
    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
   135
    
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   136
    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
   137
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   138
@TaskGen.feature("ns3testlib")
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   139
@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
   140
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
   141
    if not self.source:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   142
        return
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   143
    testdir = self.source[-1].parent.path_from(self.bld.srcnode)
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   144
    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
   145
7331
827246e3bc4c Bug 1174 - Ns-3 does not generate static libraries
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7320
diff changeset
   146
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   147
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
   148
    # 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
   149
    # the module being tested.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   150
    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
   151
    library = bld.create_ns3_module(library_name, [name], test=True)
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   152
    library.features += " ns3testlib"
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   153
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   154
    # 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
   155
    # normal module.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   156
    del library.is_ns3_module
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   157
    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
   158
    library.module_name = 'ns3-' + name
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   159
6925
43d9c7eedf7b Test implicitly dependent modules
Mitch Watrous <watrous@u.washington.edu>
parents: 6921
diff changeset
   160
    # 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
   161
    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
   162
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   163
    # Set the include path from the build directory to modules. 
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   164
    relative_path_from_build_to_here = bld.path.path_from(bld.bldnode)
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   165
    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
   166
    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
   167
    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
   168
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   169
    return library
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   170
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   171
def create_obj(bld, *args):
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   172
    warnings.warn("(in %s) Use bld(...) call now, instead of bld.create_obj(...)" % str(bld.path),
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   173
                  DeprecationWarning, stacklevel=2)
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   174
    return bld(*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
   175
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   176
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   177
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
   178
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
   179
    # 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
   180
    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
   181
    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
   182
    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
   183
    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
   184
7583
e42004e38839 Fix issue with waf --apiscan=all
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   185
    if Options.options.apiscan:
e42004e38839 Fix issue with waf --apiscan=all
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   186
        return
e42004e38839 Fix issue with waf --apiscan=all
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7545
diff changeset
   187
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   188
    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
   189
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   190
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
   191
    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
   192
    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
   193
        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
   194
                      "=> 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
   195
                      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
   196
        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
   197
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
   198
    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
   199
        #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
   200
        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
   201
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
   202
    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
   203
    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
   204
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   205
    #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
   206
    debug = True # XXX
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   207
    source = [bld.srcnode.find_resource('bindings/python/ns3modulegen-modular.py'),
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   208
              bld.path.find_resource("bindings/modulegen__%s.py" % apidefs)]
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   209
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   210
    modulegen_customizations = bindings_dir.find_resource("modulegen_customizations.py")
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   211
    if modulegen_customizations is not None:
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   212
        source.append(modulegen_customizations)
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
   213
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   214
    modulegen_local = bld.path.find_resource("bindings/modulegen_local.py")
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   215
    # the local customization file may or not exist
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   216
    if modulegen_local is not None:
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   217
        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
   218
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
   219
    module_py_name = module.replace('-', '_')
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   220
    module_target_dir = bld.srcnode.find_dir("bindings/python/ns").path_from(bld.path)
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
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
    # 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
   223
    if bld.path.find_resource("bindings/%s.py" % (module_py_name,)) is not None:
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   224
        bld(features='copy',
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
   225
            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
   226
            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
   227
        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
   228
        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
   229
    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
   230
        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
   231
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   232
    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
   233
    #if not debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   234
    #    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
   235
7408
4f1f961b6cdc Bug 1224 - Ns-3-allinone fails to compile on Lion
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7384
diff changeset
   236
    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
   237
            '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
   238
            '${PYTHON}']
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   239
    #if debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   240
    #    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
   241
    
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
   242
    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
   243
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   244
    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
   245
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   246
    features = []
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   247
    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
   248
        if was_enabled:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   249
            features.append(name)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   250
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   251
    bindgen = bld(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
   252
    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
   253
    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
   254
    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
   255
    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
   256
    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
   257
    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
   258
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
   259
    # generate the extension module
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   260
    pymod = bld(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
   261
    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
   262
    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
   263
    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
   264
    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
   265
    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
   266
        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
   267
            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
   268
            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
   269
                #mod = mod.split("--lib")[0]
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   270
                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
   271
        else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   272
            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
   273
            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
   274
                #mod = mod.split("--lib")[0]
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   275
                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
   276
            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
   277
    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
   278
    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
   279
    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
   280
        try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   281
            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
   282
        except ValueError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   283
            pass
7494
d93f5e8e0a59 waf-1.6: Mac OSX and other fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7492
diff changeset
   284
    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
   285
    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
   286
    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
   287
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
   288
    # 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
   289
    # 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
   290
    # 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
   291
    if Utils.unversioned_sys_platform() == 'darwin':
5a9a0a21b553 Bug #1335 postfix
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7678
diff changeset
   292
        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
   293
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   294
    return pymod
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   295
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   296
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   297
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
   298
    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
   299
    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
   300
    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
   301
    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
   302
    
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   303
    # 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
   304
    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
   305
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   306
        # 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
   307
        # 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
   308
        # 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
   309
        # 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
   310
        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
   311
            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
   312
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   313
        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
   314
            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
   315
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   316
    bld.recurse(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
   317
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
   318
    for module in all_modules:
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   319
        modheader = bld(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
   320
        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
   321
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   322
class ns3pcfile_task(Task.Task):
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   323
    after = 'cxx'
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 __str__(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   326
        "string to display to the user"
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   327
        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
   328
        return 'pcfile: %s\n' % (tgt_str)
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   329
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   330
    def runnable_status(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   331
        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
   332
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   333
    def _self_libs(self, env, name, libdir):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   334
        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
   335
            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
   336
            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
   337
            lib_marker = 'STLIB_MARKER'
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   338
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   339
            path_st = 'LIBPATH_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   340
            lib_st = 'LIB_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   341
            lib_marker = 'SHLIB_MARKER'
7523
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   342
        retval = [env[path_st] % libdir]
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   343
        if env[lib_marker]:
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   344
            retval.append(env[lib_marker])
7c6a89520349 Fix .pc file generation on OSX
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7522
diff changeset
   345
        retval.append(env[lib_st] % name)
7070
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   346
        return retval
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   347
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   348
    def _lib(self, env, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   349
        libpath = env['LIBPATH_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   350
        linkflags = env['LINKFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   351
        libs = env['LIB_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   352
        retval = []
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   353
        for path in libpath:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   354
            retval.append(env['LIBPATH_ST'] % path)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   355
            retval = retval + linkflags
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   356
        for lib in libs:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   357
            retval.append(env['LIB_ST'] % lib)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   358
        return retval
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   359
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   360
    def _listify(self, v):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   361
        if isinstance(v, list):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   362
            return v
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   363
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   364
            return [v]
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   365
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   366
    def _cflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   367
        flags = self.env['CFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   368
        return self._listify(flags)
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   369
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   370
    def _cxxflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   371
        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
   372
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   373
    def _defines(self, dep):
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   374
        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
   375
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   376
    def _includes(self, dep):
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   377
        includes = self.env['INCLUDES_%s' % dep]
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   378
        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
   379
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   380
    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
   381
        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
   382
        prefix = env.PREFIX
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   383
        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
   384
        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
   385
        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
   386
        for dep in use:
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   387
            libs += self._lib(env, dep)
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   388
        for dep in env.LIBS:
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   389
            libs += self.env['LIB_ST'] % dep
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   390
        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
   391
        requires = []
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   392
        for dep in use:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   393
            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
   394
                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
   395
            if dep.startswith('ns3-'):
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   396
                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
   397
                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
   398
        print >> outfile, """\
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   399
prefix=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   400
libdir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   401
includedir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   402
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   403
Name: lib%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   404
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
   405
Version: %s
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   406
Libs: %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   407
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
   408
Requires: %s\
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   409
""" % (prefix, libdir, includedir,
7688
6f5c9b870e45 Still Bug 1327: disable VNUM in libraries, fix the .pc file deps
Vedran Miletić
parents: 7681
diff changeset
   410
       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
   411
        outfile.close()
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   412
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   413
    def run(self):
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   414
        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
   415
        self._generate_pcfile(self.module.name, 
7512
bbdfcec0d97d More pc file fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7511
diff changeset
   416
                              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
   417
                              self.env, output_filename)
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   418
7511
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   419
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   420
@TaskGen.feature('ns3pcfile')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   421
@TaskGen.after_method('process_rule')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   422
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
   423
    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
   424
    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
   425
    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
   426
    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
   427
    task = self.create_task('ns3pcfile')
6d03bec01c5c Fix .pc file generation
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7496
diff changeset
   428
    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
   429
    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
   430
    task.module = module
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   431
1220
4933e0890acd Build all modules as a single ns3 shared library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1217
diff changeset
   432
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
   433
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   434
@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
   435
@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
   436
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
   437
    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
   438
        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
   439
    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
   440
    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
   441
        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
   442
        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
   443
            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
   444
        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
   445
        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
   446
        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
   447
        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
   448
        if task.mode == 'install':
7681
0873edb445e8 Bug 1327 - Version installed ns-3 files
Gustavo Carneiro / Vedran Miletić
parents: 7679
diff changeset
   449
            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
   450
            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
   451
            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
   452
        else:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   453
            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
   454
    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
   455
    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
   456
7492
5299fc683dfa Clean some dead waf code
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7490
diff changeset
   457
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   458
class ns3header_task(Task.Task):
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   459
    before = '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
   460
    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
   461
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
   462
    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
   463
        "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
   464
        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
   465
        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
   466
        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
   467
        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
   468
        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
   469
        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
   470
            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
   471
        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
   472
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   473
    def __repr__(self):
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   474
        return str(self)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   475
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   476
    def uid(self):
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   477
        try:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   478
            return self.uid_
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   479
        except AttributeError:
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   480
            m = Utils.md5()
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   481
            up = m.update
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   482
            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
   483
            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
   484
                up(x.abspath().encode())
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   485
            up(self.mode)
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   486
            if self.mode == 'remove':
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   487
                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
   488
            self.uid_ = m.digest()
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   489
            return self.uid_
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   490
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
   491
    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
   492
        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
   493
            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
   494
                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
   495
            else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   496
                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
   497
        else:
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   498
            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
   499
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   500
    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
   501
        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
   502
            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
   503
            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
   504
            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
   505
            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
   506
                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
   507
                    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
   508
                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
   509
                    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
   510
                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
   511
                ## 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
   512
                ## 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
   513
                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
   514
            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
   515
        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
   516
            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
   517
            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
   518
            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
   519
            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
   520
                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
   521
            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
   522
                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
   523
                    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
   524
            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
   525
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
   526
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   527
class gen_ns3_module_header_task(Task.Task):
9278
0a749c0f1afd Fix Python bindings and openflow for waf 1.7.10 upgrade and take care about boost requirements globally
Alexander Afanasyev <alexander.afanasyev@ucla.edu>
parents: 9173
diff changeset
   528
    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
   529
    after = 'ns3header'
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   530
    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
   531
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
    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
   533
        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
   534
            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
   535
                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
   536
            else:
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   537
                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
   538
        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
   539
            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
   540
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   541
    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
   542
        "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
   543
        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
   544
        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
   545
        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
   546
        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
   547
        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
   548
        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
   549
            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
   550
        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
   551
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   552
    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
   553
        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
   554
            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
   555
            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
   556
            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
   557
            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
   558
                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
   559
            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
   560
                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
   561
                    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
   562
            return 0
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   563
        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
   564
        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
   565
        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
   566
        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
   567
        header_files.sort()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   568
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   569
        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
   570
#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
   571
# 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
   572
#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
   573
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
   574
#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
   575
    """ % (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
   576
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   577
    #     if self.module_deps:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   578
    #         print >> outfile, "// Module dependencies:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   579
    #     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
   580
    #         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
   581
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   582
        print >> outfile
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   583
        print >> outfile, "// Module headers:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   584
        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
   585
            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
   586
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   587
        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
   588
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   589
        outfile.close()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   590
        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
   591
4126
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   592
    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
   593
        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
   594
        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
   595
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   596
    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
   597
        try:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   598
            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
   599
        except AttributeError:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   600
            "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
   601
            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
   602
            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
   603
            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
   604
            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
   605
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
   606
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   607
# 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
   608
# 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
   609
@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
   610
@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
   611
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
   612
    ## 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
   613
    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
   614
    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
   615
    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
   616
    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
   617
        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
   618
            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
   619
                continue
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   620
            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
   621
            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
   622
                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
   623
                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
   624
                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
   625
                    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
   626
                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
   627
    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
   628
        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
   629
    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
   630
        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
   631
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   632
    try:
7488
72d0c878f3c7 More waf 1.6.7 build fixes
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7487
diff changeset
   633
        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
   634
    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
   635
        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
   636
7487
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   637
    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
   638
    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
   639
    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
   640
    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
   641
    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
   642
        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
   643
        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
   644
                               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
   645
        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
   646
        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
   647
        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
   648
    else:
82cd20da9650 Upgrade to waf-1.6.7, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7467
diff changeset
   649
        task.header_to_remove = all_headers_outputs[0]