src/wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Sun, 26 Jun 2011 13:40:27 +0100
changeset 7319 175c382cfab0
parent 7303 8359b3ac1ab0
child 7320 7334aa839e46
permissions -rw-r--r--
Bug 1175 - the shared libraries is not versioned, based on patch by YunQiang Su
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
7319
175c382cfab0 Bug 1175 - the shared libraries is not versioned, based on patch by YunQiang Su
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7303
diff changeset
    19
import wutils
175c382cfab0 Bug 1175 - the shared libraries is not versioned, based on patch by YunQiang Su
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7303
diff changeset
    20
6168
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    21
try:
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    22
    set
c737d0a0e9a0 Bug 860: waf dies while executing ns3header task in case of parallel jobs.
Andrey Mazo <mazo@iitp.ru>
parents: 6127
diff changeset
    23
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
    24
    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
    25
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
    26
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
    27
    'core',
6823
a27f86fb4e55 Merge node and common modules into new network module
Tom Henderson <tomh@tomh.org>
parents: 6821
diff changeset
    28
    'network',
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6939
diff changeset
    29
    'config-store',
6834
036f9a0b9899 Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents: 6825
diff changeset
    30
    'internet',
6794
5dce93cfc499 create propagation module; move files from common module
Tom Henderson <tomh@tomh.org>
parents: 6717
diff changeset
    31
    'propagation',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    32
    'point-to-point',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    33
    'csma',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    34
    'emu',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    35
    'bridge',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    36
    'tap-bridge',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    37
    'virtual-net-device',
6847
138f00c56381 Move applications to a single module
Mitch Watrous <watrous@u.washington.edu>
parents: 6834
diff changeset
    38
    'applications',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    39
    'nix-vector-routing',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    40
    'olsr',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    41
    'aodv',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    42
    'dsdv',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    43
    'click',
6890
e5da7045526e Merge OpenFlow
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
    44
    'openflow',
968
70d02500c9d5 mobility models
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 955
diff changeset
    45
    'mobility',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    46
    'wifi',
6864
7a1f57da547e Add netanim module
Tom Henderson <tomh@tomh.org>
parents: 6855
diff changeset
    47
    'netanim',
6855
104f16f72979 Modularize stats module and move it to src
Mitch Watrous <watrous@u.washington.edu>
parents: 6854
diff changeset
    48
    'stats',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    49
    'uan',
6801
f07f7f809160 created spectrum module
Nicola Baldo <nicola@baldo.biz>
parents: 6794
diff changeset
    50
    'spectrum',
6851
7fdad61b88f1 Modularize mesh module and move it to src
Mitch Watrous <watrous@u.washington.edu>
parents: 6850
diff changeset
    51
    'mesh',   
5270
4b888ac54977 Add sample test suite file
Tom Henderson <tomh@tomh.org>
parents: 5252
diff changeset
    52
    'test',
4772
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4750
diff changeset
    53
    'test/ns3tcp',
7b6ae6bf0055 add test and validation framework
Craig Dowell <craigdo@ee.washington.edu>
parents: 4750
diff changeset
    54
    'test/ns3wifi',
6939
9fe35f79fd8f Move flow-monitor module out of contrib directory
Mitch Watrous <watrous@u.washington.edu>
parents: 6938
diff changeset
    55
    'flow-monitor',
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    56
    'wimax',
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    57
    'lte',
6113
0ce37bf4f1c1 Merge distributed simulation code
Josh Pelkey <jpelkey@gatech.edu>
parents: 6111
diff changeset
    58
    'mpi',
6854
dc1057c9879d Modularize topology-read module and move it to src
Mitch Watrous <watrous@u.washington.edu>
parents: 6852
diff changeset
    59
    'topology-read',
6938
85d201f1c67f Move energy module out of contrib directory
Mitch Watrous <watrous@u.washington.edu>
parents: 6934
diff changeset
    60
    'energy',
6941
9d2c79c992d7 Split contrib module into config-store and tools
Mitch Watrous <watrous@u.washington.edu>
parents: 6939
diff changeset
    61
    'tools',
6946
4804469564cf Move visualizer module out of tools directory
Mitch Watrous <watrous@u.washington.edu>
parents: 6942
diff changeset
    62
    'visualizer',
7089
ebe626d82692 Bug 1105 Move topology helpers into separate per-device modules
John Abraham<john.abraham@gatech.edu>
parents: 7070
diff changeset
    63
    '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
    64
    'csma-layout',
7134
40b3cffdda99 Create a template module
Mitch Watrous <watrous@u.washington.edu>
parents: 7098
diff changeset
    65
    'template',
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
    66
    ]
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
    67
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    68
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
    69
    opt.sub_options('core')
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    70
    opt.sub_options('click')
6890
e5da7045526e Merge OpenFlow
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
    71
    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
    72
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
    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
    74
                   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
    75
                         " (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
    76
                         " --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
    77
                         " 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
    78
                   action="store_true", dest='enable_rpath', default=False)
4164
1f6ae48061a9 checkpoint tap bridge
Craig Dowell <craigdo@ee.washington.edu>
parents: 4163
diff changeset
    79
    
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
    80
    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
    81
                   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
    82
                   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
    83
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    84
def configure(conf):
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    85
    conf.sub_config('core')
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    86
    conf.sub_config('emu')
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    87
    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
    88
    conf.sub_config('config-store')
6834
036f9a0b9899 Rename internet-stack to internet, and organize module
Tom Henderson <tomh@tomh.org>
parents: 6825
diff changeset
    89
    conf.sub_config('internet')
6864
7a1f57da547e Add netanim module
Tom Henderson <tomh@tomh.org>
parents: 6855
diff changeset
    90
    conf.sub_config('netanim')
6034
de2824cc388d add a place for perf tests
Craig Dowell <craigdo@ee.washington.edu>
parents: 6029
diff changeset
    91
    conf.sub_config('test')
6852
8f1a53d3f6ca Moves devices/* and routing/* to src/
Lalith Suresh <suresh.lalith@gmail.com>
parents: 6851
diff changeset
    92
    conf.sub_config('click')
6890
e5da7045526e Merge OpenFlow
Josh Pelkey <jpelkey@gatech.edu>
parents: 6882
diff changeset
    93
    conf.sub_config('openflow')
7237
dbcef20e3177 Bug 1101 - Sqlite stats disappeared from configuration file src/wscript
Tommaso Pecorella
parents: 7134
diff changeset
    94
    conf.sub_config('stats')
7297
e552e9840a14 Make ns3tcp, ns3wifi, and visualizer modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7293
diff changeset
    95
    conf.sub_config('visualizer')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    96
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
    97
    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
    98
    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
    99
    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
   100
        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
   101
5361
e8989b44bffb Doxygen and wscript messages point to test.py
Craig Dowell <craigdo@ee.washington.edu>
parents: 5270
diff changeset
   102
    ## 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
   103
    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
   104
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
   105
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   106
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
   107
    # 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
   108
    if bld.env['ENABLE_STATIC_NS3']:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   109
        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
   110
    else:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   111
        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
   112
    if not test:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   113
        pcfile = bld.new_task_gen('ns3pcfile')
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   114
        pcfile.module = module
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   115
7023
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   116
    # Initially create an empty value for this because the pcfile
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   117
    # writing task assumes every module has a uselib attribute.
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   118
    module.uselib = ''
af9c5ac72f2c Make examples and tests be enabled from the .ns3rc file
Mitch Watrous <watrous@u.washington.edu>
parents: 7021
diff changeset
   119
6639
e09e8803df26 (missing from last commit)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6429
diff changeset
   120
    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
   121
    module.name = 'ns3-' + name
7319
175c382cfab0 Bug 1175 - the shared libraries is not versioned, based on patch by YunQiang Su
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 7303
diff changeset
   122
    module.vnum = wutils.VERSION
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   123
    # 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
   124
    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
   125
    # 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
   126
    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
   127
    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
   128
    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
   129
        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
   130
        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
   131
        # 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
   132
        # proper compiler and platform.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   133
        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
   134
            # 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
   135
            # 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
   136
            # up in the same directory.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   137
            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
   138
            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
   139
    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
   140
            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
   141
            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
   142
        # 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
   143
        # 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
   144
        # (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
   145
        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
   146
        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
   147
        
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
   148
    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
   149
    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
   150
    return module
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   151
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   152
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
   153
    # 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
   154
    # the module being tested.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   155
    library_name = name + "-test"
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   156
    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
   157
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   158
    # 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
   159
    # normal module.
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   160
    del library.is_ns3_module
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   161
    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
   162
    library.module_name = 'ns3-' + name
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   163
6925
43d9c7eedf7b Test implicitly dependent modules
Mitch Watrous <watrous@u.washington.edu>
parents: 6921
diff changeset
   164
    # Add this module and test library to the list.
43d9c7eedf7b Test implicitly dependent modules
Mitch Watrous <watrous@u.washington.edu>
parents: 6921
diff changeset
   165
    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
   166
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   167
    # 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
   168
    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
   169
    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
   170
    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
   171
    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
   172
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   173
    return library
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   174
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   175
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
   176
    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
   177
                  DeprecationWarning, stacklevel=2)
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   178
    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
   179
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   180
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   181
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
   182
    # 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
   183
    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
   184
    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
   185
    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
   186
    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
   187
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   188
    if not env['ENABLE_PYTHON_BINDINGS']:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   189
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   190
    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
   191
        return
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   192
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
   193
    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
   194
    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
   195
        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
   196
                      "=> 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
   197
                      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
   198
        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
   199
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
   200
    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
   201
        #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
   202
        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
   203
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
   204
    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
   205
    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
   206
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   207
    #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
   208
    debug = True # XXX
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   209
    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
   210
              "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
   211
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
   212
    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
   213
        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
   214
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   215
    # the local customization file may or not exist
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   216
    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
   217
        source.append("bindings/modulegen_local.py")
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   218
6957
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   219
    module_py_name = module.replace('-', '_')
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
    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
   221
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   222
    # if bindings/<module>.py exists, it becomes the module frontend, and the C extension befomes _<module>
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   223
    if bld.path.find_resource("bindings/%s.py" % (module_py_name,)) is not None:
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
        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
   225
            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
   226
            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
   227
            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
   228
        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
   229
    else:
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   230
        extension_name = module_py_name
5f49d23b4a74 Modular bindings: add support for <module>.py and _<module>.so layout, for extending modules in Python
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6956
diff changeset
   231
6893
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   232
    target = ['bindings/ns3module.cc', 'bindings/ns3module.h', 'bindings/ns3modulegen.log']
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   233
    #if not debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   234
    #    target.append('ns3modulegen.log')
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   235
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   236
    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
   237
    #if debug:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   238
    #    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
   239
    
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
   240
    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
   241
5dccd86f90cf Modular Python bindings work (many bug fixes, more modules tested)
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6882
diff changeset
   242
    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
   243
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   244
    features = []
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   245
    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
   246
        if was_enabled:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   247
            features.append(name)
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   248
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   249
    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
   250
    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
   251
    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
   252
    bindgen.before = 'cxx'
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   253
    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
   254
    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
   255
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
   256
    # 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
   257
    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
   258
    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
   259
    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
   260
    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
   261
    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
   262
    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
   263
        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
   264
            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
   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
        else:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   268
            pymod.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
6913
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   269
            for mod in pymod.uselib_local:
54679ab32585 Create separate module and test-module libraries
Mitch Watrous <watrous@u.washington.edu>
parents: 6902
diff changeset
   270
                pymod.env.append_value('LINKFLAGS', '-l' + mod)
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   271
            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
   272
    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
   273
    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
   274
    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
   275
        try:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   276
            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
   277
        except ValueError:
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   278
            pass
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   279
    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
   280
    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
   281
    return pymod
6874
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   282
c7537e62f2fa Start of work on modular Python bindings, unstable
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6647
diff changeset
   283
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   284
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
   285
    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
   286
    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
   287
    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
   288
    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
   289
    
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   290
    # Remove these modules from the list of all modules.
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   291
    for not_built in bld.env['MODULES_NOT_BUILT']:
7303
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   292
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   293
        # XXX Becaue these modules are located in subdirectories of
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   294
        # test, their names in the all_modules list include the extra
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   295
        # relative path "test/".  If these modules are moved into the
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   296
        # src directory, then this if block should be removed.
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   297
        if not_built == 'ns3tcp' or not_built == 'ns3wifi':
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   298
            not_built = 'test/' + not_built
8359b3ac1ab0 Handle extra relative paths for ns3tcp and ns3wifi modules
Mitch Watrous <watrous@u.washington.edu>
parents: 7297
diff changeset
   299
7293
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   300
        if not_built in all_modules:
0f574c532cee Make test module not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7291
diff changeset
   301
            all_modules.remove(not_built)
7291
d39c09dbc3d9 Make emu and template modules not be built if not appropriate
Mitch Watrous <watrous@u.washington.edu>
parents: 7237
diff changeset
   302
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
   303
    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
   304
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
    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
   306
        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
   307
        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
   308
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   309
class ns3pcfile_task(Task.Task):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   310
    after = 'cc cxx'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   311
    def __str__(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   312
        "string to display to the user"
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   313
        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
   314
        return 'pcfile: %s\n' % (tgt_str)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   315
    def runnable_status(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   316
        return super(ns3pcfile_task, self).runnable_status()
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   317
    def _self_libs(self, env, name, libdir):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   318
        if env['ENABLE_STATIC_NS3']:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   319
            path_st = 'STATICLIBPATH_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   320
            lib_st = 'STATICLIB_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   321
            lib_marker = 'STATICLIB_MARKER'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   322
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   323
            path_st = 'LIBPATH_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   324
            lib_st = 'LIB_ST'
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   325
            lib_marker = 'SHLIB_MARKER'
7070
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   326
        retval = [env[path_st] % libdir,
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   327
                  env[lib_marker],
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   328
                  env[lib_st] % name]
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   329
        return retval
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   330
    def _lib(self, env, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   331
        libpath = env['LIBPATH_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   332
        linkflags = env['LINKFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   333
        libs = env['LIB_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   334
        retval = []
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   335
        for path in libpath:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   336
            retval.append(env['LIBPATH_ST'] % path)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   337
            retval = retval + linkflags
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   338
        for lib in libs:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   339
            retval.append(env['LIB_ST'] % lib)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   340
        return retval
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   341
    def _listify(self, v):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   342
        if isinstance(v, list):
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
        else:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   345
            return [v]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   346
    def _cflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   347
        flags = self.env['CFLAGS_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   348
        return self._listify(flags)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   349
    def _cxxflags(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   350
        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
   351
    def _defines(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   352
        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
   353
        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
   354
            [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
   355
    def _includes(self, dep):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   356
        includes = self.env['CPPPATH_%s' % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   357
        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
   358
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   359
    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
   360
        outfile = open(outfilename, 'w')
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   361
        includedir = os.path.join(prefix, 'include')
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   362
        libdir = os.path.join(prefix, 'lib')
7070
5635f2667e08 fix typo: % should be $
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 7053
diff changeset
   363
        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
   364
        for dep in use:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   365
            libs = libs + self._lib(self.env, dep)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   366
        for dep in uselib_local:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   367
            libs = libs + [self.env['LIB_ST'] % dep]
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   368
        cflags = [self.env['CPPPATH_ST'] % '${includedir}']
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   369
        for dep in use:
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   370
            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
   371
                self._defines(dep) + self._includes(dep)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   372
        print >> outfile, """
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   373
prefix=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   374
libdir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   375
includedir=%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   376
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   377
Name: lib%s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   378
Description: ns-3 module %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   379
Version: devel
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   380
Libs: %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   381
Cflags: %s
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   382
""" % (prefix, libdir, includedir,
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   383
       name, name, ' '.join(libs), ' '.join(cflags))
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   384
        outfile.close()
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   385
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   386
    def run(self):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   387
        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
   388
        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
   389
                              self.module.uselib_local,
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   390
                              self.env['PREFIX'], output_filename)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   391
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   392
class ns3pcfile_taskgen(TaskGen.task_gen):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   393
    def __init__(self, *args, **kwargs):
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   394
        super(ns3pcfile_taskgen, self).__init__(*args, **kwargs)
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   395
    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
   396
        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
   397
        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
   398
        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
   399
        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
   400
        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
   401
                               output_node)
7016
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   402
        task.set_outputs([output_node])
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   403
        task.module = self.module
eab6710a6346 generate pkg-config files for installation.
Mathieu Lacage <mathieu.lacage@inria.fr>
parents: 7006
diff changeset
   404
1220
4933e0890acd Build all modules as a single ns3 shared library.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 1217
diff changeset
   405
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   406
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
   407
    """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
   408
    COLOR = 'BLUE'
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   409
    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
   410
        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
   411
        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
   412
        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
   413
        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
   414
        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
   415
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
   416
    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
   417
        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
   418
            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
   419
            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
   420
        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
   421
            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
   422
        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
   423
        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
   424
            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
   425
        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
   426
            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
   427
            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
   428
                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
   429
            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
   430
            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
   431
            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
   432
            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
   433
            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
   434
                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
   435
                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
   436
            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
   437
                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
   438
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   439
class ns3header_task(Task.Task):
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   440
    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
   441
    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
   442
bdbbfbc6bda7 When a module is disabled, 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
    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
   444
        "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
   445
        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
   446
        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
   447
        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
   448
        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
   449
        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
   450
        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
   451
            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
   452
        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
   453
bdbbfbc6bda7 When a module is disabled, remove xxx-module.h and module header files from build/variant/ns3
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 6639
diff changeset
   454
    def 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
   455
        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
   456
            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
   457
                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
   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 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
   460
        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
   461
            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
   462
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   463
    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
   464
        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
   465
            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
   466
            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
   467
            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
   468
            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
   469
                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
   470
                    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
   471
                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
   472
                    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
   473
                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
   474
                ## 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
   475
                ## 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
   476
                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
   477
            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
   478
        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
   479
            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
   480
            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
   481
            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
   482
            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
   483
                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
   484
            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
   485
                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
   486
                    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
   487
            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
   488
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
   489
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   490
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
   491
    before = 'cc cxx'
4066
d2309cf765d8 Fix --python-scan
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4064
diff changeset
   492
    after = 'ns3header_task'
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   493
    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
   494
bdbbfbc6bda7 When a module is disabled, 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
    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
   496
        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
   497
            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
   498
                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
   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 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
   501
        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
   502
            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
   503
bdbbfbc6bda7 When a module is disabled, 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
    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
   505
        "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
   506
        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
   507
        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
   508
        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
   509
        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
   510
        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
   511
        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
   512
            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
   513
        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
   514
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   515
    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
   516
        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
   517
            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
   518
            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
   519
            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
   520
            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
   521
                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
   522
            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
   523
                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
   524
                    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
   525
            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
   526
        
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   527
        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
   528
        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
   529
        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
   530
        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
   531
        header_files.sort()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   532
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   533
        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
   534
#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
   535
# 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
   536
#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
   537
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
#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
   539
    """ % (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
   540
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   541
    #     if 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, "// Module dependencies:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   543
    #     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
   544
    #         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
   545
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   546
        print >> outfile
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   547
        print >> outfile, "// Module headers:"
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   548
        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
   549
            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
   550
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   551
        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
   552
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   553
        outfile.close()
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   554
        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
   555
4126
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   556
    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
   557
        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
   558
        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
   559
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   560
    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
   561
        try:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   562
            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
   563
        except AttributeError:
0ba0346d655b Workaround WAF issue 325 for generating module header files
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4066
diff changeset
   564
            "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
   565
            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
   566
            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
   567
            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
   568
            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
   569
2611
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   570
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   571
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
   572
    """
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
    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
   574
    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
   575
    """
4064
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   576
    COLOR = 'BLUE'
10222f483860 Upgrade to new WAF, work in progress
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 3854
diff changeset
   577
    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
   578
        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
   579
        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
   580
79b1c42fef3e Generate foo-module.h module aggreator header files, for use in user scripts.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 2609
diff changeset
   581
    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
   582
        ## 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
   583
        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
   584
        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
   585
        found_the_module = False
4326
179f86838e62 Upgrade to WAF 1.5.4
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 4164
diff changeset
   586
        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
   587
            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
   588
                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
   589
                    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
   590
                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
   591
                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
   592
                    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
   593
                    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
   594
                    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
   595
                        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
   596
                    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
   597
        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
   598
            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
   599
        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
   600
            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
   601
        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
   602
                               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
   603
        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
   604
        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
   605
        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
   606
        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
   607
        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
   608
            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
   609
            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
   610
            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
   611
            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
   612
            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
   613
        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
   614
            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
   615
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
   616
    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
   617
        pass