src/wscript
author Mitch Watrous <watrous@u.washington.edu>
Fri, 27 May 2011 14:48:14 -0700
changeset 7291 d39c09dbc3d9
parent 7237 dbcef20e3177
child 7293 0f574c532cee
permissions -rw-r--r--
Make emu and template modules not be built if not appropriate
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
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
     9
import TaskGen
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    10
import Task
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    11
import Options
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    12
import Build
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
    13
import Utils
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
    14
import Constants
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
    15
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
    16
import ccroot
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
    17
ccroot.USE_TOP_LEVEL = True
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
    18
6168
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    19
try:
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    20
    set
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    21
except NameError:
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    22
    from sets import Set as set # Python 2.3 fallback
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    23
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
    24
all_modules = [
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
    25
    'core',
6823
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6821
diff changeset
    26
    'network',
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6939
diff changeset
    27
    'config-store',
6834
036f9a0b9899 Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents: 6825
diff changeset
    28
    'internet',
6794
5dce93cfc499 create propagation module; move files from common module
Tom Henderson <tomh@tomh.org>
parents: 6717
diff changeset
    29
    'propagation',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    30
    'point-to-point',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    31
    'csma',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    32
    'emu',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    33
    'bridge',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    34
    'tap-bridge',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    35
    'virtual-net-device',
6847
138f00c56381 Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents: 6834
diff changeset
    36
    'applications',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    37
    'nix-vector-routing',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    38
    'olsr',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    39
    'aodv',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    40
    'dsdv',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    41
    'click',
6890
e5da7045526e Merge OpenFlow
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
    42
    'openflow',
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 955
diff changeset
    43
    'mobility',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    44
    'wifi',
6864
7a1f57da547e Add netanim module
Tom Henderson <tomh@tomh.org>
parents: 6855
diff changeset
    45
    'netanim',
6855
104f16f72979 Modularize stats module and move it to src
Mitch Watrous <watrous@u.washington.edu>
parents: 6854
diff changeset
    46
    'stats',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    47
    'uan',
6801
f07f7f809160 created spectrum module
Nicola Baldo <nicola@baldo.biz>
parents: 6794
diff changeset
    48
    'spectrum',
6851
7fdad61b88f1 Modularize mesh module and move it to src
Mitch Watrous <watrous@u.washington.edu>
parents: 6850
diff changeset
    49
    'mesh',   
5270
4b888ac54977 Add sample test suite file
Tom Henderson <tomh@tomh.org>
parents: 5252
diff changeset
    50
    'test',
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4750
diff changeset
    51
    'test/ns3tcp',
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4750
diff changeset
    52
    'test/ns3wifi',
6939
9fe35f79fd8f Move flow-monitor module out of contrib directory
Mitch Watrous <watrous@u.washington.edu>
parents: 6938
diff changeset
    53
    'flow-monitor',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    54
    'wimax',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    55
    'lte',
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 6111
diff changeset
    56
    'mpi',
6854
dc1057c9879d Modularize topology-read module and move it to src
Mitch Watrous <watrous@u.washington.edu>
parents: 6852
diff changeset
    57
    'topology-read',
6938
85d201f1c67f Move energy module out of contrib directory
Mitch Watrous <watrous@u.washington.edu>
parents: 6934
diff changeset
    58
    'energy',
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6939
diff changeset
    59
    'tools',
6946
4804469564cf Move visualizer module out of tools directory
Mitch Watrous <watrous@u.washington.edu>
parents: 6942
diff changeset
    60
    'visualizer',
7089
ebe626d82692 Bug 1105 Move topology helpers into separate per-device modules
John Abraham<john.abraham@gatech.edu>
parents: 7070
diff changeset
    61
    'point-to-point-layout',
ebe626d82692 Bug 1105 Move topology helpers into separate per-device modules
John Abraham<john.abraham@gatech.edu>
parents: 7070
diff changeset
    62
    'csma-layout',
7134
40b3cffdda99 Create a template module
Mitch Watrous <watrous@u.washington.edu>
parents: 7098
diff changeset
    63
    'template',
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
    64
    ]
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
    65
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    66
def set_options(opt):
6821
203367ae7433 merge src/simulator into src/core; move src/core to new module layout
Tom Henderson <tomh@tomh.org>
parents: 6801
diff changeset
    67
    opt.sub_options('core')
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    68
    opt.sub_options('click')
6890
e5da7045526e Merge OpenFlow
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
    69
    opt.sub_options('openflow')
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
    70
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
    71
    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
    72
                   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
    73
                         " (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
    74
                         " --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
    75
                         " 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
    76
                   action="store_true", dest='enable_rpath', default=False)
4164
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4163
diff changeset
    77
    
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
    78
    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
    79
                   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
    80
                   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
    81
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    82
def configure(conf):
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    83
    conf.sub_config('core')
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    84
    conf.sub_config('emu')
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    85
    conf.sub_config('tap-bridge')
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6939
diff changeset
    86
    conf.sub_config('config-store')
6834
036f9a0b9899 Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents: 6825
diff changeset
    87
    conf.sub_config('internet')
6864
7a1f57da547e Add netanim module
Tom Henderson <tomh@tomh.org>
parents: 6855
diff changeset
    88
    conf.sub_config('netanim')
6034
de2824cc388d add a place for perf tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 6029
diff changeset
    89
    conf.sub_config('test')
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    90
    conf.sub_config('click')
6890
e5da7045526e Merge OpenFlow
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
    91
    conf.sub_config('openflow')
7237
dbcef20e3177 Bug 1101 - Sqlite stats disappeared from configuration file src/wscript
Tommaso Pecorella
parents: 7134
diff changeset
    92
    conf.sub_config('stats')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    93
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    94
    blddir = os.path.abspath(os.path.join(conf.blddir, conf.env.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
    95
    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
    96
    if Options.options.enable_rpath:
1306
8834e434187f Build the ns3 library in the build/<variant> root, not in build/<variant>/src.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1272
diff changeset
    97
        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
    98
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5270
diff changeset
    99
    ## 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
   100
    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
   101
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
   102
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   103
def create_ns3_module(bld, name, dependencies=(), test=False):
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   104
    # Create a separate library for this module.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   105
    if bld.env['ENABLE_STATIC_NS3']:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   106
        module = bld.new_task_gen('cxx', 'cstaticlib')
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   107
    else:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   108
        module = bld.new_task_gen('cxx', 'cshlib')
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   109
    if not test:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   110
        pcfile = bld.new_task_gen('ns3pcfile')
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   111
        pcfile.module = module
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   112
7023
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   113
    # 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
   114
    # 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
   115
    module.uselib = ''
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   116
6639
e09e8803df26 (missing from last commit)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6429
diff changeset
   117
    module.is_ns3_module = True
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
   118
    module.name = 'ns3-' + name
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   119
    # Add the proper path to the module's name.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   120
    module.target = '%s/ns3-%s' % (bld.srcnode.relpath_gen(bld.path), name)
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   121
    # Set the libraries this module depends on.  
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   122
    module.uselib_local = ['ns3-' + dep for dep in dependencies]
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
   123
    module.module_deps = list(dependencies)
4392
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4389
diff changeset
   124
    if not module.env['ENABLE_STATIC_NS3']:
25d38a0c9851 bug 537: no support to build static ns-3 binaries
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4389
diff changeset
   125
        module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS'])
5996
84c404ad1d26 WAF: allow NS-3 modules to compile pure C code sources mixed with the C++ ones
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5942
diff changeset
   126
        module.env.append_value('CCFLAGS', module.env['shlib_CXXFLAGS'])
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   127
        # Turn on the link flags for shared libraries if we have the
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   128
        # proper compiler and platform.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   129
        if module.env['CXX_NAME'] in ['gcc', 'icc'] and module.env['WL_SONAME_SUPPORTED']:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   130
            # Get the module library name without any relative paths
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   131
            # at its beginning because all of the libraries will end
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   132
            # up in the same directory.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   133
            module_library_name = os.path.basename(ccroot.get_target_name(module))
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   134
            module.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % module_library_name)
5252
481053e0cd10 Bug 681: wrong compilation options for icpc (Intel C/C++ Compiler)
Andrey Mazo <mazo@iitp.ru>
parents: 5230
diff changeset
   135
    elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \
4395
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4392
diff changeset
   136
            os.uname()[4] == 'x86_64' and \
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4392
diff changeset
   137
            module.env['ENABLE_PYTHON_BINDINGS']:
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4392
diff changeset
   138
        # enable that flag for static builds only on x86-64 platforms
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4392
diff changeset
   139
        # when gcc is present and only when we want python bindings
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4392
diff changeset
   140
        # (it's more efficient to not use this option if we can avoid it)
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4392
diff changeset
   141
        module.env.append_value('CXXFLAGS', '-mcmodel=large')
5996
84c404ad1d26 WAF: allow NS-3 modules to compile pure C code sources mixed with the C++ ones
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5942
diff changeset
   142
        module.env.append_value('CCFLAGS', '-mcmodel=large')
4395
489abe44ed7e enable static builds, even when python is enabled
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 4392
diff changeset
   143
        
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
   144
    module.env.append_value('CXXDEFINES', "NS3_MODULE_COMPILATION")
5996
84c404ad1d26 WAF: allow NS-3 modules to compile pure C code sources mixed with the C++ ones
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5942
diff changeset
   145
    module.env.append_value('CCDEFINES', "NS3_MODULE_COMPILATION")
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
   146
    return module
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   147
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   148
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
   149
    # 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
   150
    # the module being tested.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   151
    library_name = name + "-test"
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   152
    library = bld.create_ns3_module(library_name, [name], test = True)
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.
43d9c7eedf7b Test implicitly dependent modules
Mitch Watrous <watrous@u.washington.edu>
parents: 6921
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. 
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   164
    relative_path_from_build_to_here = bld.path.relpath_gen(bld.bldnode)
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   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):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   172
    warnings.warn("(in %s) Use bld.new_task_gen(...) now, instead of bld.create_obj(...)" % str(bld.path),
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   173
                  DeprecationWarning, stacklevel=2)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   174
    return bld.new_task_gen(*args)
955
c9be0df711d2 WAF: add back the --enable-rpath option, per Mathieu's request, though disabled by default.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 954
diff changeset
   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):
6933
4bbaa92c3220 ./waf --apiscan=all: now only scans modules that have bld.ns3_python_bindings() in their wscript
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6925
diff changeset
   178
    # 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
   179
    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
   180
    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
   181
    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
   182
    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
   183
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   184
    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
   185
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   186
    if env['BINDINGS_TYPE'] not in ('modular', 'both'):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   187
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   188
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
   189
    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
   190
    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
   191
        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
   192
                      "=> 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
   193
                      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
   194
        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
   195
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
   196
    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
   197
        #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
   198
        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
   199
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
   200
    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
   201
    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
   202
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   203
    #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
   204
    debug = True # XXX
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   205
    source = [bld.srcnode.find_resource('bindings/python/ns3modulegen-modular.py').relpath_gen(bld.path),
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   206
              "bindings/modulegen__%s.py" % apidefs]
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   207
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
   208
    if bindings_dir.find_resource("modulegen_customizations.py") is not None:
4a3bb1ba53fb Modular bindings: add missing dep on the modulegen_customizations.py file, when found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6946
diff changeset
   209
        source.append("bindings/modulegen_customizations.py")
4a3bb1ba53fb Modular bindings: add missing dep on the modulegen_customizations.py file, when found
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6946
diff changeset
   210
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   211
    # the local customization file may or not exist
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   212
    if bld.path.find_resource("bindings/modulegen_local.py"):
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   213
        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
   214
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
   215
    module_py_name = module.replace('-', '_')
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   216
    module_target_dir = bld.srcnode.find_dir("bindings/python/ns").relpath_gen(bld.path)
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   217
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   218
    # 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
   219
    if bld.path.find_resource("bindings/%s.py" % (module_py_name,)) is not None:
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   220
        bld.new_task_gen(
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   221
            features='copy',
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   222
            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
   223
            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
   224
        extension_name = '_%s' % (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
   225
    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
   226
        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
   227
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   228
    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
   229
    #if not debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   230
    #    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
   231
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   232
    argv = ['NS3_ENABLED_FEATURES=${FEATURES}', '${PYTHON}']
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   233
    #if debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   234
    #    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
   235
    
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
   236
    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
   237
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   238
    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
   239
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   240
    features = []
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   241
    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
   242
        if was_enabled:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   243
            features.append(name)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   244
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   245
    bindgen = bld.new_task_gen('command', source=source, target=target, command=argv)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   246
    bindgen.env['FEATURES'] = ','.join(features)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   247
    bindgen.dep_vars = ['FEATURES']
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   248
    bindgen.before = 'cxx'
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   249
    bindgen.after = 'gen_ns3_module_header_task'
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   250
    bindgen.name = "pybindgen(ns3 module %s)" % module
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   251
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
   252
    # generate the extension module
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   253
    pymod = bld.new_task_gen(features='cxx cshlib 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
   254
    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
   255
    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
   256
    pymod.name = 'ns3module_%s' % module
7098
bb919b08a773 Link Python bindings modules to all enabled ns-3 module libraries. Fixes #1117.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7089
diff changeset
   257
    pymod.uselib_local = 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
   258
    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
   259
        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
   260
            pymod.env.append_value('LINKFLAGS', '-Wl,-all_load')
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   261
            for mod in pymod.uselib_local:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   262
                pymod.env.append_value('LINKFLAGS', '-l' + mod)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   263
        else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   264
            pymod.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   265
            for mod in pymod.uselib_local:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   266
                pymod.env.append_value('LINKFLAGS', '-l' + mod)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   267
            pymod.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   268
    defines = list(pymod.env['CXXDEFINES'])
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   269
    defines.extend(['NS_DEPRECATED=', 'NS3_DEPRECATED_H'])
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   270
    if Options.platform == 'win32':
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   271
        try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   272
            defines.remove('_DEBUG') # causes undefined symbols on win32
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   273
        except ValueError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   274
            pass
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   275
    pymod.env['CXXDEFINES'] = defines
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   276
    pymod.includes = 'bindings'
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   277
    return pymod
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   278
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   279
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   280
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
   281
    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
   282
    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
   283
    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
   284
    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
   285
    
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   286
    # Remove the emu module from the list of all modules if it
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   287
    # is there and emu is not enabled.
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   288
    emu_module_name = 'emu'
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   289
    if emu_module_name in all_modules:
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   290
        if not bld.env['ENABLE_EMU']:
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   291
            all_modules.remove(emu_module_name)
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   292
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   293
    # Remove the template module from the list of all modules if this
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   294
    # is a static build on Darwin because they don't work there for
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   295
    # the template module.  This is probably because it is empty.
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   296
    template_module_name = 'template'
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   297
    if template_module_name in all_modules:
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   298
        if bld.env['ENABLE_STATIC_NS3'] and sys.platform == 'darwin':
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   299
            all_modules.remove(template_module_name)
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   300
969
3c3ce40492a6 WAF: make list of modules (all_modules) a tuple instead of list, because it is hashable, and this way newer WAF is able to notice changes in it and automatically trigger a reconfiguration.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 968
diff changeset
   301
    bld.add_subdirs(list(all_modules))
693
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
   302
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
   303
    for module in all_modules:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   304
        modheader = bld.new_task_gen('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
   305
        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
   306
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   307
class ns3pcfile_task(Task.Task):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   308
    after = 'cc cxx'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   309
    def __str__(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   310
        "string to display to the user"
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   311
        tgt_str = ' '.join([a.nice_path(self.env) for a in self.outputs])
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   312
        return 'pcfile: %s\n' % (tgt_str)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   313
    def runnable_status(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   314
        return super(ns3pcfile_task, self).runnable_status()
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   315
    def _self_libs(self, env, name, libdir):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   316
        if env['ENABLE_STATIC_NS3']:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   317
            path_st = 'STATICLIBPATH_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   318
            lib_st = 'STATICLIB_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   319
            lib_marker = 'STATICLIB_MARKER'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   320
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   321
            path_st = 'LIBPATH_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   322
            lib_st = 'LIB_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   323
            lib_marker = 'SHLIB_MARKER'
7070
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   324
        retval = [env[path_st] % libdir,
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   325
                  env[lib_marker],
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   326
                  env[lib_st] % name]
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   327
        return retval
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   328
    def _lib(self, env, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   329
        libpath = env['LIBPATH_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   330
        linkflags = env['LINKFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   331
        libs = env['LIB_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   332
        retval = []
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   333
        for path in libpath:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   334
            retval.append(env['LIBPATH_ST'] % path)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   335
            retval = retval + linkflags
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   336
        for lib in libs:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   337
            retval.append(env['LIB_ST'] % lib)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   338
        return retval
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   339
    def _listify(self, v):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   340
        if isinstance(v, list):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   341
            return v
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   342
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   343
            return [v]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   344
    def _cflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   345
        flags = self.env['CFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   346
        return self._listify(flags)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   347
    def _cxxflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   348
        return self._listify(self.env['CXXFLAGS_%s' % dep])
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   349
    def _defines(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   350
        defines = self.env['CCDEFINES_%s' % dep] + self.env['CXXDEFINES_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   351
        return [self.env['CCDEFINES_ST'] % define for define in self.env['CCDEFINES_%s' % dep]] + \
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   352
            [self.env['CXXDEFINES_ST'] % define for define in self.env['CXXDEFINES_%s' % dep]] 
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   353
    def _includes(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   354
        includes = self.env['CPPPATH_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   355
        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
   356
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   357
    def _generate_pcfile(self, name, use, uselib_local, prefix, outfilename):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   358
        outfile = open(outfilename, 'w')
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   359
        includedir = os.path.join(prefix, 'include')
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   360
        libdir = os.path.join(prefix, 'lib')
7070
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   361
        libs = self._self_libs(self.env, name, '${libdir}')
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   362
        for dep in use:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   363
            libs = libs + self._lib(self.env, dep)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   364
        for dep in uselib_local:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   365
            libs = libs + [self.env['LIB_ST'] % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   366
        cflags = [self.env['CPPPATH_ST'] % '${includedir}']
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   367
        for dep in use:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   368
            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
   369
                self._defines(dep) + self._includes(dep)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   370
        print >> outfile, """
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   371
prefix=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   372
libdir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   373
includedir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   374
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   375
Name: lib%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   376
Description: ns-3 module %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   377
Version: devel
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   378
Libs: %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   379
Cflags: %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   380
""" % (prefix, libdir, includedir,
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   381
       name, name, ' '.join(libs), ' '.join(cflags))
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   382
        outfile.close()
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   383
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   384
    def run(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   385
        output_filename = self.outputs[0].bldpath(self.env)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   386
        self._generate_pcfile(self.module.name, self.module.uselib, 
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   387
                              self.module.uselib_local,
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   388
                              self.env['PREFIX'], output_filename)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   389
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   390
class ns3pcfile_taskgen(TaskGen.task_gen):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   391
    def __init__(self, *args, **kwargs):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   392
        super(ns3pcfile_taskgen, self).__init__(*args, **kwargs)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   393
    def apply(self):
7021
ba5f71c6ef58 Fix a waf problem when generating pkgconfig files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7016
diff changeset
   394
        output_filename = 'lib%s.pc' % self.module.name
ba5f71c6ef58 Fix a waf problem when generating pkgconfig files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7016
diff changeset
   395
        output_node = self.path.find_or_declare(output_filename)
ba5f71c6ef58 Fix a waf problem when generating pkgconfig files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7016
diff changeset
   396
        assert output_node is not None, str(self)
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   397
        task = self.create_task('ns3pcfile', env=self.env)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   398
        self.bld.install_files(os.path.join('${PREFIX}', 'lib', 'pkgconfig'),
7021
ba5f71c6ef58 Fix a waf problem when generating pkgconfig files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7016
diff changeset
   399
                               output_node)
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   400
        task.set_outputs([output_node])
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   401
        task.module = self.module
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   402
1220
4933e0890acd Build all modules as a single ns3 shared library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1217
diff changeset
   403
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   404
class ns3header_taskgen(TaskGen.task_gen):
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
   405
    """A set of NS-3 header files"""
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   406
    COLOR = 'BLUE'
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   407
    def __init__(self, *args, **kwargs):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   408
        super(ns3header_taskgen, self).__init__(*args, **kwargs)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   409
        self.install_path = None
1877
b2ebc493cd58 Add support for publishing ns3 headers in a subdir of ns3/ (we probably won't be needing this, but since it was implemented it might as well be commited, in case we ever need it)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   410
        self.sub_dir = None # if not None, header files will be published as ns3/sub_dir/file.h
2609
931d59bb1303 Add a 'module' attribute to the ns3header object specifying which module each set of headers belongs to.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2603
diff changeset
   411
        self.module = None # module name
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
   412
        self.mode = 'install'
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
   413
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
   414
    def apply(self):
7006
16e179df944f install ns-3 headers in include/ns-3 upon 'waf install'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6957
diff changeset
   415
        for filename in set(self.to_list(self.source)):
16e179df944f install ns-3 headers in include/ns-3 upon 'waf install'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6957
diff changeset
   416
            src_node = self.path.find_resource(filename)
16e179df944f install ns-3 headers in include/ns-3 upon 'waf install'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6957
diff changeset
   417
            self.bld.install_files('${PREFIX}/include/ns3', [src_node])
2609
931d59bb1303 Add a 'module' attribute to the ns3header object specifying which module each set of headers belongs to.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2603
diff changeset
   418
        if self.module is None:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   419
            raise Utils.WafError("'module' missing on ns3headers object %s" % self)
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
   420
        ns3_dir_node = self.bld.path.find_dir("ns3")
1877
b2ebc493cd58 Add support for publishing ns3 headers in a subdir of ns3/ (we probably won't be needing this, but since it was implemented it might as well be commited, in case we ever need it)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   421
        if self.sub_dir is not None:
b2ebc493cd58 Add support for publishing ns3 headers in a subdir of ns3/ (we probably won't be needing this, but since it was implemented it might as well be commited, in case we ever need it)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1858
diff changeset
   422
            ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir)
6168
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
   423
        for filename in set(self.to_list(self.source)):
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   424
            src_node = self.path.find_resource(filename)
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
   425
            if src_node is None:
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   426
                raise Utils.WafError("source ns3 header file %s not found" % (filename,))
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   427
            dst_node = ns3_dir_node.find_or_declare(os.path.basename(filename))
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
   428
            assert dst_node is not None
5942
7c66549b828d Upgrade waf from 1.5.9 to 1.5.11
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5781
diff changeset
   429
            task = self.create_task('ns3header', env=self.env)
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
   430
            task.mode = self.mode
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
   431
            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
   432
                task.set_inputs([src_node])
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
   433
                task.set_outputs([dst_node])
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
   434
            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
   435
                task.header_to_remove = dst_node
693
c8fc89076aa2 WAF: cleanup the main wscript file by moving the definition of the ns3header object type into src/wscript
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 672
diff changeset
   436
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   437
class ns3header_task(Task.Task):
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   438
    before = 'cc cxx gen_ns3_module_header_task'
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   439
    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
   440
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
   441
    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
   442
        "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
   443
        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
   444
        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
   445
        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
   446
        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
   447
        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
   448
        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
   449
            return 'rm-ns3-header %s\n' % (self.header_to_remove.bldpath(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
   450
        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
   451
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
   452
    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
   453
        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
   454
            if os.path.exists(self.header_to_remove.bldpath(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
   455
                return Constants.RUN_ME
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   456
            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
   457
                return Constants.SKIP_ME
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   458
        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
   459
            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
   460
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   461
    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
   462
        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
   463
            assert len(self.inputs) == len(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
   464
            inputs = [node.srcpath(self.env) for node 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
   465
            outputs = [node.bldpath(self.env) for node 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
   466
            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
   467
                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
   468
                    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
   469
                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
   470
                    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
   471
                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
   472
                ## 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
   473
                ## 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
   474
                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
   475
            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
   476
        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
   477
            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
   478
            assert len(self.outputs) == 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
   479
            out_file_name = self.header_to_remove.bldpath(self.env)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   480
            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
   481
                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
   482
            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
   483
                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
   484
                    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
   485
            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
   486
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
   487
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   488
class gen_ns3_module_header_task(Task.Task):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   489
    before = 'cc cxx'
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   490
    after = 'ns3header_task'
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   491
    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
   492
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   493
    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
   494
        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
   495
            if os.path.exists(self.header_to_remove.bldpath(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
   496
                return Constants.RUN_ME
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 Constants.SKIP_ME
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
        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
   500
            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
   501
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
    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
   503
        "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
   504
        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
   505
        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
   506
        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
   507
        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
   508
        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
   509
        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
   510
            return 'rm-module-header %s\n' % (self.header_to_remove.bldpath(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
   511
        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
   512
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   513
    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
   514
        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
   515
            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
   516
            assert len(self.outputs) == 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
            out_file_name = self.header_to_remove.bldpath(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
   518
            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
   519
                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
   520
            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
   521
                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
   522
                    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
   523
            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
   524
        
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   525
        assert len(self.outputs) == 1
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
   526
        out_file_name = self.outputs[0].bldpath(self.env)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   527
        header_files = [os.path.basename(node.abspath(self.env)) 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
   528
        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
   529
        header_files.sort()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   530
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   531
        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
   532
#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
   533
# 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
   534
#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
   535
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
   536
#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
   537
    """ % (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
   538
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   539
    #     if self.module_deps:
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   540
    #         print >> outfile, "// Module dependencies:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   541
    #     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
   542
    #         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
   543
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   544
        print >> outfile
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   545
        print >> outfile, "// Module headers:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   546
        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
   547
            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
   548
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   549
        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
   550
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   551
        outfile.close()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   552
        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
   553
4126
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   554
    def sig_explicit_deps(self):
6671
b3d5193a2f94 Bug 1004 - module header not rebuilt
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   555
        self.m.update('\n'.join([node.abspath(self.env) for node in self.inputs]))
b3d5193a2f94 Bug 1004 - module header not rebuilt
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   556
        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
   557
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   558
    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
   559
        try:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   560
            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
   561
        except AttributeError:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   562
            "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
   563
            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
   564
            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
   565
            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
   566
            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
   567
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   568
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   569
class ns3moduleheader_taskgen(TaskGen.task_gen):
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
    """
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
    Generates a 'ns3/foo-module.h' header file that includes all
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
    public ns3 headers of a certain module.
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   573
    """
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   574
    COLOR = 'BLUE'
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   575
    def __init__(self, *args, **kwargs):
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   576
        super(ns3moduleheader_taskgen, self).__init__(*args, **kwargs)
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
   577
        self.mode = 'install'
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   578
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
   579
    def apply(self):
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   580
        ## get all of the ns3 headers
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
   581
        ns3_dir_node = self.bld.path.find_dir("ns3")
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
   582
        all_headers_inputs = []
4750
7dd4ad5ac045 Allow ns3moduleheader taskgen with empty list of source headers (for completely optional ns-3 modules)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4731
diff changeset
   583
        found_the_module = False
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
   584
        for ns3headers in self.bld.all_task_gen:
3001
f7aa2796627f WAF: convert code to WAF 1.4 API; the 'waf' script bundle will be updated later, for now has been disabled.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2750
diff changeset
   585
            if isinstance(ns3headers, ns3header_taskgen):
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
                if ns3headers.module != self.module:
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
   587
                    continue
4750
7dd4ad5ac045 Allow ns3moduleheader taskgen with empty list of source headers (for completely optional ns-3 modules)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4731
diff changeset
   588
                found_the_module = True
6168
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
   589
                for source in set(ns3headers.to_list(ns3headers.source)):
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
   590
                    source = os.path.basename(source)
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   591
                    node = ns3_dir_node.find_or_declare(os.path.basename(source))
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
   592
                    if node is None:
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
   593
                        fatal("missing header file %s" % (source,))
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
   594
                    all_headers_inputs.append(node)
4750
7dd4ad5ac045 Allow ns3moduleheader taskgen with empty list of source headers (for completely optional ns-3 modules)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4731
diff changeset
   595
        if not found_the_module:
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
   596
            raise Utils.WscriptError("error finding headers for module %s" % self.module)
4750
7dd4ad5ac045 Allow ns3moduleheader taskgen with empty list of source headers (for completely optional ns-3 modules)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4731
diff changeset
   597
        if not all_headers_inputs:
7dd4ad5ac045 Allow ns3moduleheader taskgen with empty list of source headers (for completely optional ns-3 modules)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4731
diff changeset
   598
            return
7006
16e179df944f install ns-3 headers in include/ns-3 upon 'waf install'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6957
diff changeset
   599
        self.bld.install_files('${PREFIX}/include/ns3', 
16e179df944f install ns-3 headers in include/ns-3 upon 'waf install'
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6957
diff changeset
   600
                               ns3_dir_node.find_or_declare("%s-module.h" % self.module))
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   601
        all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)]
5942
7c66549b828d Upgrade waf from 1.5.9 to 1.5.11
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 5781
diff changeset
   602
        task = self.create_task('gen_ns3_module_header', env=self.env)
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
   603
        task.module = self.module
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
   604
        task.mode = self.mode
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
   605
        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
   606
            task.set_inputs(all_headers_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
   607
            task.set_outputs(all_headers_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
   608
            module_obj = self.bld.name_to_obj("ns3-" + self.module, 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
   609
            assert module_obj is not None, self.module
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
   610
            task.module_deps = module_obj.module_deps
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
   611
        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
   612
            task.header_to_remove = all_headers_outputs[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
   613
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
   614
    def install(self):
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
   615
        pass