wscript
author Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
Mon, 09 Jul 2007 14:36:40 +0100
changeset 921 37b54ed96b09
parent 919 a9c7effce441
child 923 f5d38217e7a2
permissions -rw-r--r--
WAF: ignore errors on shutil.rmtree in dist_hook, so that waf dist works even when no docs were previously generated.
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
import os
647
04f34a8befb8 In WAF win32 builds, add -Wl,--enable-runtime-pseudo-reloc to LINKFLAGS to solve dll linking problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 642
diff changeset
     3
import sys
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
     4
import shlex
695
90a68c1c4328 WAF: add a dist_hook function to exclude the generated documentation from waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 694
diff changeset
     5
import shutil
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     6
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     7
import Params
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
     8
import Object
649
1d12fb509a0d WAF: import the WAF subprocess replacement module 'pproc', to make it work on Python 2.3.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 647
diff changeset
     9
import pproc as subprocess
787
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    10
import optparse
918
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
    11
import os.path
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    12
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    13
Params.g_autoconfig = 1
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    14
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    15
# the following two variables are used by the target "waf dist"
694
bfad4514a789 WAF: correct values of VERSION and APPNAME, for waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 693
diff changeset
    16
VERSION = file("VERSION").read().strip()
bfad4514a789 WAF: correct values of VERSION and APPNAME, for waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 693
diff changeset
    17
APPNAME = 'ns'
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    18
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    19
# these variables are mandatory ('/' are converted automatically)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    20
srcdir = '.'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    21
blddir = 'build'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    22
695
90a68c1c4328 WAF: add a dist_hook function to exclude the generated documentation from waf dist
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents: 694
diff changeset
    23
def dist_hook(srcdir, blddir):
921
37b54ed96b09 WAF: ignore errors on shutil.rmtree in dist_hook, so that waf dist works even when no docs were previously generated.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 919
diff changeset
    24
    shutil.rmtree("doc/html", True)
37b54ed96b09 WAF: ignore errors on shutil.rmtree in dist_hook, so that waf dist works even when no docs were previously generated.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 919
diff changeset
    25
    shutil.rmtree("doc/latex", True)
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    26
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    27
def set_options(opt):
787
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    28
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    29
    def debug_option_callback(option, opt, value, parser):
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    30
        if value == 'debug':
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    31
            setattr(parser.values, option.dest, 'ultradebug')
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    32
        elif value == 'optimized':
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    33
            setattr(parser.values, option.dest, 'optimized')
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    34
        else:
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    35
            raise optparse.OptionValueError("allowed --debug-level values"
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    36
                                            " are debug, optimized.")
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    37
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    38
    opt.add_option('-d', '--debug-level',
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    39
                   action='callback',
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    40
                   type=str, dest='debug_level', default='debug',
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    41
                   help=('Specify the debug level, does nothing if CFLAGS is set'
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    42
                         ' in the environment. [Allowed Values: debug, optimized].'
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    43
                         ' WARNING: this option only has effect '
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    44
                         'with the configure command.'),
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    45
                   callback=debug_option_callback)
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    46
    
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    47
    # options provided by the modules
642
033f1f4891ab Make WAF check for the abstract tool 'compiler_cxx', instead of manually checking for multiple compilers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 600
diff changeset
    48
    opt.tool_options('compiler_cxx')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    49
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    50
    opt.add_option('--enable-gcov',
787
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    51
                   help=('Enable code coverage analysis.'
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    52
                         ' WARNING: this option only has effect '
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    53
                         'with the configure command.'),
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    54
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    55
                   dest='enable_gcov')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    56
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    57
    opt.add_option('--lcov-report',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    58
                   help=('Generate a code coverage report '
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    59
                         '(use this option at build time, not in configure)'),
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    60
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    61
                   dest='lcov_report')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    62
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    63
    opt.add_option('--doxygen',
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    64
                   help=('Run doxygen to generate html documentation from source comments'),
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    65
                   action="store_true", default=False,
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    66
                   dest='doxygen')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    67
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    68
    opt.add_option('--run',
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    69
                   help=('Run a locally built program'),
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    70
                   type="string", default='', dest='run')
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    71
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    72
    opt.add_option('--shell',
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    73
                   help=('Run a shell with an environment suitably modified to run locally built programs'),
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    74
                   action="store_true", default=False,
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    75
                   dest='shell')
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
    76
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    77
    # options provided in a script in a subdirectory named "src"
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    78
    opt.sub_options('src')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    79
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    80
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    81
def configure(conf):
642
033f1f4891ab Make WAF check for the abstract tool 'compiler_cxx', instead of manually checking for multiple compilers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 600
diff changeset
    82
    if not conf.check_tool('compiler_cxx'):
033f1f4891ab Make WAF check for the abstract tool 'compiler_cxx', instead of manually checking for multiple compilers.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 600
diff changeset
    83
        Params.fatal("No suitable compiler found")
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    84
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    85
    # create the second environment, set the variant and set its name
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    86
    variant_env = conf.env.copy()
787
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    87
    debug_level = Params.g_options.debug_level.lower()
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    88
    if debug_level == 'ultradebug':
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    89
        variant_name = 'debug'
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    90
    else:
778784e6bd8d WAF: simplify --debug-level option to only have debug and optimized as possible values (debug becomes the former ultradebug); Add a warning to some options help text saying they only work in configure.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 786
diff changeset
    91
        variant_name = debug_level
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    92
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    93
    if Params.g_options.enable_gcov:
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    94
        variant_name += '-gcov'
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    95
        variant_env.append_value('CCFLAGS', '-fprofile-arcs')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    96
        variant_env.append_value('CCFLAGS', '-ftest-coverage')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    97
        variant_env.append_value('CXXFLAGS', '-fprofile-arcs')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    98
        variant_env.append_value('CXXFLAGS', '-ftest-coverage')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
    99
        variant_env.append_value('LINKFLAGS', '-fprofile-arcs')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   100
    
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   101
    conf.env['NS3_ACTIVE_VARIANT'] = variant_name
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   102
    variant_env['NS3_ACTIVE_VARIANT'] = variant_name
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   103
    variant_env.set_variant(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   104
    conf.set_env_name(variant_name, variant_env)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   105
    conf.setenv(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   106
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   107
    variant_env.append_value('CXXDEFINES', 'RUN_SELF_TESTS')
786
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   108
    
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   109
    if os.path.basename(conf.env['CXX']).startswith("g++"):
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   110
        variant_env.append_value('CXXFLAGS', ['-Wall', '-Werror'])
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   111
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   112
    if 'debug' in Params.g_options.debug_level.lower():
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   113
        variant_env.append_value('CXXDEFINES', 'NS3_DEBUG_ENABLE')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   114
        variant_env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   115
647
04f34a8befb8 In WAF win32 builds, add -Wl,--enable-runtime-pseudo-reloc to LINKFLAGS to solve dll linking problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 642
diff changeset
   116
    if sys.platform == 'win32':
786
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   117
        if os.path.basename(conf.env['CXX']).startswith("g++"):
78982ea24359 WAF: be careful not to set gcc-specific flags (like -Werror) when using a non-gcc compiler.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 785
diff changeset
   118
            variant_env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc")
647
04f34a8befb8 In WAF win32 builds, add -Wl,--enable-runtime-pseudo-reloc to LINKFLAGS to solve dll linking problems.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 642
diff changeset
   119
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   120
    conf.sub_config('src')
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   121
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   122
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   123
def build(bld):
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   124
    variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   125
    variant_env = bld.env_of_name(variant_name)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   126
    bld.m_allenvs['default'] = variant_env # switch to the active variant
762
b64b1d4eadc0 WAF: process --run and --shell command-line options sooner, before running the build, since we may need a shell before the build finishes, in case the program to debug is part of the build itself.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 695
diff changeset
   127
915
9006896544b3 WAF: make the --run option work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 787
diff changeset
   128
    if Params.g_options.shell:
762
b64b1d4eadc0 WAF: process --run and --shell command-line options sooner, before running the build, since we may need a shell before the build finishes, in case the program to debug is part of the build itself.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 695
diff changeset
   129
        run_shell()
b64b1d4eadc0 WAF: process --run and --shell command-line options sooner, before running the build, since we may need a shell before the build finishes, in case the program to debug is part of the build itself.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 695
diff changeset
   130
        return
b64b1d4eadc0 WAF: process --run and --shell command-line options sooner, before running the build, since we may need a shell before the build finishes, in case the program to debug is part of the build itself.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 695
diff changeset
   131
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   132
    # process subfolders from here
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   133
    bld.add_subdirs('src')
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
   134
    bld.add_subdirs('samples utils examples')
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   135
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   136
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   137
def shutdown():
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   138
    #import UnitTest
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   139
    #ut = UnitTest.unit_test()
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   140
    #ut.change_to_testfile_dir = True
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   141
    #ut.want_to_see_test_output = True
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   142
    #ut.want_to_see_test_error = True
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   143
    #ut.run()
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   144
    #ut.print_results()
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   145
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   146
    if Params.g_commands['check']:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   147
        run_program('run-tests')
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   148
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   149
    if Params.g_options.lcov_report:
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   150
        lcov_report()
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   151
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   152
    if Params.g_options.doxygen:
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   153
        doxygen()
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   154
915
9006896544b3 WAF: make the --run option work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 787
diff changeset
   155
    if Params.g_options.run:
9006896544b3 WAF: make the --run option work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 787
diff changeset
   156
        run_program(Params.g_options.run)
9006896544b3 WAF: make the --run option work again
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 787
diff changeset
   157
918
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   158
def _find_program(program_name, env):
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   159
    launch_dir = os.path.abspath(Params.g_cwd_launch)
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   160
    found_programs = []
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   161
    for obj in Object.g_allobjs:
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   162
        if obj.m_type != 'program' or not obj.target:
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   163
            continue
918
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   164
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   165
        ## filter out programs not in the subtree starting at the launch dir
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   166
        if not (obj.path.abspath().startswith(launch_dir)
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   167
                or obj.path.abspath(env).startswith(launch_dir)):
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   168
            continue
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   169
        
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   170
        found_programs.append(obj.target)
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   171
        if obj.target == program_name:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   172
            return obj
917
aed7f1b9e783 WAF: fix simple typo in error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 916
diff changeset
   173
    raise ValueError("program '%s' not found; available programs are: %r"
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   174
                     % (program_name, found_programs))
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   175
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   176
def _run_argv(argv):
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   177
    env = Params.g_build.env_of_name('default')
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   178
    if sys.platform == 'linux2':
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   179
        pathvar = 'LD_LIBRARY_PATH'
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   180
        pathsep = ':'
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   181
    elif sys.platform == 'darwin':
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   182
        pathvar = 'DYLD_LIBRARY_PATH'
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   183
        pathsep = ':'
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   184
    elif sys.platform == 'win32':
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   185
        pathvar = 'PATH'
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   186
        pathsep = ';'
785
bf8e7773836a WAF: configure dynamic path for the cygwin platform.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 764
diff changeset
   187
    elif sys.platform == 'cygwin':
bf8e7773836a WAF: configure dynamic path for the cygwin platform.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 764
diff changeset
   188
        pathvar = 'PATH'
bf8e7773836a WAF: configure dynamic path for the cygwin platform.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 764
diff changeset
   189
        pathsep = ':'
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   190
    else:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   191
        Params.warning(("Don't know how to configure "
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   192
                        "dynamic library path for the platform '%s'") % (sys.platform,))
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   193
        pathvar = None
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   194
        pathsep = None
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   195
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   196
    os_env = dict(os.environ)
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   197
    if pathvar is not None:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   198
        if pathvar in os_env:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   199
            os_env[pathvar] = pathsep.join([os_env[pathvar]] + list(env['NS3_MODULE_PATH']))
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   200
        else:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   201
            os_env[pathvar] = pathsep.join(list(env['NS3_MODULE_PATH']))
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   202
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   203
    retval = subprocess.Popen(argv, env=os_env).wait()
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   204
    if retval:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   205
        raise SystemExit(retval)
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   206
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   207
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   208
def run_program(program_string):
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   209
    env = Params.g_build.env_of_name('default')
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   210
    argv = shlex.split(program_string)
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   211
    program_name = argv[0]
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   212
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   213
    try:
918
1ecec08ba4ba WAF: option --run now filters out programs not in the subtree starting at the launch dir
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 917
diff changeset
   214
        program_obj = _find_program(program_name, env)
916
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   215
    except ValueError, ex:
1eca7915ca9e WAF: when the program specified by --run is not found, print a list of all available program names in the error message.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 915
diff changeset
   216
        Params.fatal(str(ex))
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   217
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   218
    try:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   219
        program_node, = program_obj.m_linktask.m_outputs
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   220
    except AttributeError:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   221
        Params.fatal("%s does not appear to be a program" % (program_name,))
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   222
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   223
    execvec = [program_node.abspath(env)] + argv[1:]
919
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   224
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   225
    former_cwd = os.getcwd()
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   226
    os.chdir(Params.g_cwd_launch)
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   227
    try:
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   228
        return _run_argv(execvec)
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   229
    finally:
a9c7effce441 WAF: --run now runs the specified program from the directory where waf was invoked.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 918
diff changeset
   230
        os.chdir(former_cwd)
672
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   231
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   232
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   233
def run_shell():
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   234
    if sys.platform == 'win32':
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   235
        shell = os.environ.get("COMSPEC", "cmd.exe")
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   236
    else:
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   237
        shell = os.environ.get("SHELL", "/bin/sh")
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   238
    _run_argv([shell])
184d5a505279 WAF: remove the rpath options, and add --run and --shell as replacements; additionally, the new options "should" work on Mac OS X, as well as linux2 and win32.
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 671
diff changeset
   239
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   240
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   241
def doxygen():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   242
    doxygen_config = os.path.join('doc', 'doxygen.conf')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   243
    if subprocess.Popen(['doxygen', doxygen_config]).wait():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   244
        raise SystemExit(1)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   245
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   246
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   247
def lcov_report():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   248
    env = Params.g_build.env_of_name('default')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   249
    variant_name = env['NS3_ACTIVE_VARIANT']
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   250
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   251
    if 'gcov' not in variant_name:
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   252
        Params.fatal("project not configured for code coverage;"
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   253
                     " reconfigure with --enable-gcov")
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   254
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   255
    os.chdir(blddir)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   256
    try:
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   257
        lcov_report_dir = os.path.join(variant_name, 'lcov-report')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   258
        create_dir_command = "rm -rf " + lcov_report_dir
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   259
        create_dir_command += " && mkdir " + lcov_report_dir + ";"
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   260
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   261
        if subprocess.Popen(create_dir_command, shell=True).wait():
537
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   262
            raise SystemExit(1)
e8a4183dfe00 Add support for building with WAF
Gustavo J. A. M. Carneiro <gjcarneiro@gmail.com>
parents:
diff changeset
   263
671
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   264
        info_file = os.path.join(lcov_report_dir, variant_name + '.info')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   265
        lcov_command = "../utils/lcov/lcov -c -d . -o " + info_file
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   266
        lcov_command += " --source-dirs=" + os.getcwd()
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   267
        lcov_command += ":" + os.path.join(
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   268
            os.getcwd(), variant_name, 'include')
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   269
        if subprocess.Popen(lcov_command, shell=True).wait():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   270
            raise SystemExit(1)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   271
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   272
        genhtml_command = "../utils/lcov/genhtml -o " + lcov_report_dir
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   273
        genhtml_command += " " + info_file
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   274
        if subprocess.Popen(genhtml_command, shell=True).wait():
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   275
            raise SystemExit(1)
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   276
    finally:
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   277
        os.chdir("..")
4bec4600950c WAF: cleanup code by putting lcov and doxygen handling into their own separate functions
Gustavo J. A. M. Carneiro <gjc@inescporto.pt>
parents: 649
diff changeset
   278