wscript
author Josh Pelkey <jpelkey@gatech.edu>
Wed, 11 Aug 2010 11:37:37 -0400
changeset 6553 fb5ad9c7755a
parent 6274 3e8b3f2306c9
permissions -rw-r--r--
update release notes and fix doxygen warnings
gjcarneiro@537
     1
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
gjc@4064
     2
gjc@4064
     3
# python lib modules
gjc@647
     4
import sys
gjcarneiro@695
     5
import shutil
gjc@1217
     6
import types
gjc@1217
     7
import optparse
gjc@1217
     8
import os.path
ahippo@4450
     9
import re
gjcarneiro@537
    10
gjc@4064
    11
# WAF modules
gjc@3001
    12
import pproc as subprocess
gjc@4064
    13
import Options
gjc@4326
    14
gjc@4064
    15
import Logs
gjc@4064
    16
import TaskGen
gjc@4195
    17
import Constants
gjc@4076
    18
gjc@3001
    19
import ccroot
gjc@4076
    20
ccroot.USE_TOP_LEVEL = True
gjc@4076
    21
craigdo@3826
    22
import Task
gjc@4195
    23
Task.algotype = Constants.JOBCONTROL # so that Task.maxjobs=1 takes effect
gjc@4195
    24
gjc@4064
    25
import Utils
gjc@4064
    26
import Build
gjc@4064
    27
import Configure
gjc@4326
    28
import Scripting
gjcarneiro@537
    29
gjc@5447
    30
sys.path.insert(0, os.path.abspath('waf-tools'))
gjc@6274
    31
try:
gjc@6274
    32
    import cflags # override the build profiles from waf
gjc@6274
    33
finally:
gjc@6274
    34
    sys.path.pop(0)
gjc@5447
    35
gjc@4069
    36
cflags.profiles = {
gjc@4069
    37
	# profile name: [optimization_level, warnings_level, debug_level]
gjc@4069
    38
	'debug':     [0, 2, 3],
gjc@4069
    39
	'optimized': [3, 2, 1],
mazo@5452
    40
	'release':   [3, 2, 0],
gjc@4069
    41
	}
gjc@4069
    42
cflags.default_profile = 'debug'
gjc@4069
    43
gjc@4064
    44
# local modules
gjc@3866
    45
import wutils
gjc@3866
    46
import regression
gjc@3866
    47
gjc@4070
    48
Configure.autoconfig = 1
gjcarneiro@537
    49
gjcarneiro@537
    50
# the following two variables are used by the target "waf dist"
gjc@4064
    51
VERSION = file("VERSION", "rt").read().strip()
gjcarneiro@694
    52
APPNAME = 'ns'
gjcarneiro@537
    53
gjc@3866
    54
wutils.VERSION = VERSION
gjc@3866
    55
wutils.APPNAME = APPNAME
gjc@3866
    56
gjc@4115
    57
#
gjc@4115
    58
# The last part of the path name to use to find the regression traces.  The
gjc@4115
    59
# path will be APPNAME + '-' + VERSION + REGRESSION_SUFFIX, e.g.,
gjc@4115
    60
# ns-3-dev-ref-traces
gjc@4115
    61
#
gjc@4115
    62
REGRESSION_SUFFIX = "-ref-traces"
gjc@4115
    63
gjc@4115
    64
gjcarneiro@537
    65
# these variables are mandatory ('/' are converted automatically)
gjcarneiro@537
    66
srcdir = '.'
gjcarneiro@537
    67
blddir = 'build'
gjcarneiro@537
    68
mathieu@4594
    69
def load_env():
mathieu@4594
    70
    bld_cls = getattr(Utils.g_module, 'build_context', Utils.Context)
mathieu@4594
    71
    bld_ctx = bld_cls()
mathieu@4594
    72
    bld_ctx.load_dirs(os.path.abspath(os.path.join (srcdir,'..')),
mathieu@4594
    73
                      os.path.abspath(os.path.join (srcdir,'..', blddir)))
mathieu@4594
    74
    bld_ctx.load_envs()
mathieu@4594
    75
    env = bld_ctx.get_env()
mathieu@4594
    76
    return env
mathieu@4594
    77
mathieu@4594
    78
def get_files(base_dir):
mathieu@4594
    79
    retval = []
mathieu@4594
    80
    reference=os.path.dirname(base_dir)
mathieu@4594
    81
    for root, dirs, files in os.walk(base_dir):
mathieu@4594
    82
        if root.find('.hg') != -1:
mathieu@4594
    83
            continue
mathieu@4594
    84
        for file in files:
mathieu@4594
    85
            if file.find('.hg') != -1:
mathieu@4594
    86
                continue
mathieu@4594
    87
            fullname = os.path.join(root,file)
mathieu@4594
    88
            # we can't use os.path.relpath because it's new in python 2.6
mathieu@4594
    89
            relname = fullname.replace(reference + '/','')
mathieu@4594
    90
            retval.append([fullname,relname])
mathieu@4594
    91
    return retval
mathieu@4594
    92
gjc@2881
    93
gjc@1531
    94
def dist_hook():
gjc@2886
    95
    import tarfile
gjc@921
    96
    shutil.rmtree("doc/html", True)
gjc@921
    97
    shutil.rmtree("doc/latex", True)
gjc@3627
    98
    shutil.rmtree("nsc", True)
gjcarneiro@537
    99
craigdo@3284
   100
    ## build the name of the traces subdirectory.  Will be something like
craigdo@3284
   101
    ## ns-3-dev-ref-traces
mathieu@4594
   102
    traces_name = APPNAME + '-' + VERSION + REGRESSION_SUFFIX
gjc@2886
   103
    ## Create a tar.bz2 file with the traces
mathieu@4594
   104
    env = load_env()
mathieu@4594
   105
    regression_dir = env['REGRESSION_TRACES']
mathieu@4594
   106
    if not os.path.isdir(regression_dir):
mathieu@4594
   107
        Logs.warn("Not creating traces archive: the %s directory does not exist" % regression_dir)
gjc@2886
   108
    else:
gjc@3866
   109
        traceball = traces_name + wutils.TRACEBALL_SUFFIX
craigdo@3284
   110
        tar = tarfile.open(os.path.join("..", traceball), 'w:bz2')
mathieu@4594
   111
        files = get_files(regression_dir)
mathieu@4594
   112
        for fullfilename,relfilename in files:
mathieu@4594
   113
            tar.add(fullfilename,arcname=relfilename)
gjc@2886
   114
        tar.close()
gjc@2886
   115
gjcarneiro@537
   116
def set_options(opt):
gjcarneiro@537
   117
    # options provided by the modules
gjc@5996
   118
    opt.tool_options('compiler_cc')
gjc@642
   119
    opt.tool_options('compiler_cxx')
gjc@4069
   120
    opt.tool_options('cflags')
gjcarneiro@537
   121
craigdo@2846
   122
    opt.add_option('--cwd',
craigdo@2846
   123
                   help=('Set the working directory for a program.'),
craigdo@2846
   124
                   action="store", type="string", default=None,
craigdo@2846
   125
                   dest='cwd_launch')
craigdo@2846
   126
gjcarneiro@537
   127
    opt.add_option('--enable-gcov',
gjc@787
   128
                   help=('Enable code coverage analysis.'
gjc@787
   129
                         ' WARNING: this option only has effect '
gjc@787
   130
                         'with the configure command.'),
gjcarneiro@537
   131
                   action="store_true", default=False,
gjcarneiro@537
   132
                   dest='enable_gcov')
gjcarneiro@537
   133
gjc@2866
   134
    opt.add_option('--no-task-lines',
gjc@2866
   135
                   help=("Don't print task lines, i.e. messages saying which tasks are being executed by WAF."
gjc@2866
   136
                         "  Coupled with a single -v will cause WAF to output only the executed commands,"
gjc@2866
   137
                         " just like 'make' does by default."),
gjc@2866
   138
                   action="store_true", default=False,
gjc@2866
   139
                   dest='no_task_lines')
gjc@2866
   140
gjcarneiro@537
   141
    opt.add_option('--lcov-report',
gjcarneiro@537
   142
                   help=('Generate a code coverage report '
gjcarneiro@537
   143
                         '(use this option at build time, not in configure)'),
gjcarneiro@537
   144
                   action="store_true", default=False,
gjcarneiro@537
   145
                   dest='lcov_report')
gjcarneiro@537
   146
gjc@672
   147
    opt.add_option('--run',
gjc@935
   148
                   help=('Run a locally built program; argument can be a program name,'
gjc@935
   149
                         ' or a command starting with the program name.'),
gjc@672
   150
                   type="string", default='', dest='run')
gjc@935
   151
    opt.add_option('--command-template',
gjc@935
   152
                   help=('Template of the command used to run the program given by --run;'
gjc@935
   153
                         ' It should be a shell command string containing %s inside,'
gjc@935
   154
                         ' which will be replaced by the actual program.'),
gjc@935
   155
                   type="string", default=None, dest='command_template')
gjc@3419
   156
    opt.add_option('--pyrun',
gjc@3419
   157
                   help=('Run a python program using locally built ns3 python module;'
gjc@3419
   158
                         ' argument is the path to the python program, optionally followed'
gjc@3419
   159
                         ' by command-line options that are passed to the program.'),
gjc@3419
   160
                   type="string", default='', dest='pyrun')
gjc@2207
   161
    opt.add_option('--valgrind',
gjc@2207
   162
                   help=('Change the default command template to run programs and unit tests with valgrind'),
gjc@2207
   163
                   action="store_true", default=False,
gjc@2207
   164
                   dest='valgrind')
gjc@672
   165
    opt.add_option('--shell',
gjc@4326
   166
                   help=('DEPRECATED (run ./waf shell)'),
gjc@672
   167
                   action="store_true", default=False,
gjc@672
   168
                   dest='shell')
craigdo@4164
   169
    opt.add_option('--enable-sudo',
craigdo@4164
   170
                   help=('Use sudo to setup suid bits on ns3 executables.'),
craigdo@4164
   171
                   dest='enable_sudo', action='store_true',
craigdo@4164
   172
                   default=False)
craigdo@5369
   173
    opt.add_option('--enable-examples',
craigdo@5369
   174
                   help=('Build the ns-3 examples and samples.'),
craigdo@5369
   175
                   dest='enable_examples', action='store_true',
craigdo@5369
   176
                   default=True)
craigdo@5369
   177
    opt.add_option('--disable-examples',
craigdo@5369
   178
                   help=('Do not build the ns-3 examples and samples.'),
craigdo@5369
   179
                   dest='enable_examples', action='store_false')
gjc@2881
   180
    opt.add_option('--regression',
gjc@2881
   181
                   help=("Enable regression testing; only used for the 'check' target"),
gjc@2881
   182
                   default=False, dest='regression', action="store_true")
gjc@4531
   183
    opt.add_option('--check',
craigdo@5361
   184
                   help=('DEPRECATED (run ./test.py)'),
gjc@4531
   185
                   default=False, dest='check', action="store_true")
gjc@2881
   186
    opt.add_option('--regression-generate',
gjc@2884
   187
                   help=("Generate new regression test traces."),
gjc@2881
   188
                   default=False, dest='regression_generate', action="store_true")
gjc@2881
   189
    opt.add_option('--regression-tests',
gjc@2881
   190
                   help=('For regression testing, only run/generate the indicated regression tests, '
gjc@2881
   191
                         'specified as a comma separated list of test names'),
gjc@2881
   192
                   dest='regression_tests', type="string")
gjc@3872
   193
    opt.add_option('--with-regression-traces',
gjc@3872
   194
                   help=('Path to the regression reference traces directory'),
gjc@3872
   195
                   default=None,
gjc@3872
   196
                   dest='regression_traces', type="string")
mathieu@4392
   197
    opt.add_option('--enable-static',
mathieu@4392
   198
                   help=('Compile NS-3 statically: works only on linux, without python'),
mathieu@4392
   199
                   dest='enable_static', action='store_true',
mathieu@4392
   200
                   default=False)
jpelkey@6113
   201
    opt.add_option('--enable-mpi',
jpelkey@6113
   202
                   help=('Compile NS-3 with MPI and distributed simulation support'),
jpelkey@6113
   203
                   dest='enable_mpi', action='store_true',
jpelkey@6113
   204
                   default=False)
gjc@5468
   205
    opt.add_option('--doxygen-no-build',
gjc@5468
   206
                   help=('Run doxygen to generate html documentation from source comments, '
gjc@5468
   207
                         'but do not wait for ns-3 to finish the full build.'),
gjc@5468
   208
                   action="store_true", default=False,
gjc@5468
   209
                   dest='doxygen_no_build')
gjc@2881
   210
gjc@5468
   211
    # options provided in subdirectories
gjcarneiro@537
   212
    opt.sub_options('src')
gjc@3408
   213
    opt.sub_options('bindings/python')
gjc@3628
   214
    opt.sub_options('src/internet-stack')
gjcarneiro@537
   215
gjcarneiro@537
   216
gjc@6099
   217
def _check_compilation_flag(conf, flag, mode='cxx'):
gjc@3407
   218
    """
gjc@3407
   219
    Checks if the C++ compiler accepts a certain compilation flag or flags
gjc@3407
   220
    flag: can be a string or a list of strings
gjc@3407
   221
    """
gjc@3407
   222
gjc@4064
   223
    env = conf.env.copy()
gjc@6099
   224
    if mode == 'cxx':
gjc@6099
   225
        fname = 'test.cc'
gjc@6099
   226
        env.append_value('CXXFLAGS', flag)
gjc@6099
   227
    else:
gjc@6099
   228
        fname = 'test.c'
gjc@6099
   229
        env.append_value('CCFLAGS', flag)
gjc@4064
   230
    try:
gjc@4064
   231
        retval = conf.run_c_code(code='#include <stdio.h>\nint main() { return 0; }\n',
gjc@6099
   232
                                 env=env, compile_filename=fname,
gjc@6099
   233
                                 compile_mode=mode, type='cprogram', execute=False)
gjc@4064
   234
    except Configure.ConfigurationError:
gjc@4064
   235
        ok = False
gjc@4064
   236
    else:
gjc@4064
   237
        ok = (retval == 0)
gjc@4064
   238
    conf.check_message_custom(flag, 'support', (ok and 'yes' or 'no'))
gjc@4069
   239
    return ok
gjc@3407
   240
gjc@3407
   241
    
gjc@3625
   242
def report_optional_feature(conf, name, caption, was_enabled, reason_not_enabled):
gjc@3625
   243
    conf.env.append_value('NS3_OPTIONAL_FEATURES', (name, caption, was_enabled, reason_not_enabled))
gjc@3407
   244
gjcarneiro@537
   245
def configure(conf):
gjc@3625
   246
    # attach some extra methods
gjc@4326
   247
    conf.check_compilation_flag = types.MethodType(_check_compilation_flag, conf)
gjc@3625
   248
    conf.report_optional_feature = types.MethodType(report_optional_feature, conf)
gjc@3625
   249
    conf.env['NS3_OPTIONAL_FEATURES'] = []
gjc@3625
   250
gjc@4064
   251
    conf.env['NS3_BUILDDIR'] = conf.blddir
gjc@5996
   252
    conf.check_tool('compiler_cc')
gjc@1531
   253
    conf.check_tool('compiler_cxx')
gjc@6274
   254
    conf.check_tool('cflags', ['waf-tools'])
gjc@4075
   255
    try:
gjc@6274
   256
        conf.check_tool('pkgconfig', ['waf-tools'])
gjc@4075
   257
    except Configure.ConfigurationError:
gjc@4075
   258
        pass
gjc@6274
   259
    conf.check_tool('command', ['waf-tools'])
gjcarneiro@537
   260
gjc@4115
   261
    # Check for the location of regression reference traces
gjc@4064
   262
    if Options.options.regression_traces is not None:
gjc@4115
   263
        if os.path.isdir(Options.options.regression_traces):
gjc@4115
   264
            conf.check_message("regression traces location", '', True, ("%s (given)" % Options.options.regression_traces))
mathieu@4594
   265
            conf.env['REGRESSION_TRACES'] = os.path.abspath(Options.options.regression_traces)
gjc@4115
   266
    else:
gjc@4115
   267
        traces = os.path.join('..', "%s-%s%s" % (APPNAME, VERSION, REGRESSION_SUFFIX))
gjc@4115
   268
        if os.path.isdir(traces):
gjc@4115
   269
            conf.check_message("regression reference traces", '', True, ("%s (guessed)" % traces))
mathieu@4594
   270
            conf.env['REGRESSION_TRACES'] = os.path.abspath(traces)
gjc@4115
   271
        del traces
mathieu@4594
   272
    if not conf.env['REGRESSION_TRACES']:
gjc@4115
   273
        conf.check_message("regression reference traces", '', False)
gjc@3872
   274
mathieu@4594
   275
    # create the second environment, set the variant and set its name
mathieu@4594
   276
    variant_env = conf.env.copy()
mathieu@4594
   277
    variant_name = Options.options.build_profile
mathieu@4594
   278
gjc@4064
   279
    if Options.options.enable_gcov:
gjcarneiro@537
   280
        variant_name += '-gcov'
gjcarneiro@537
   281
        variant_env.append_value('CCFLAGS', '-fprofile-arcs')
gjcarneiro@537
   282
        variant_env.append_value('CCFLAGS', '-ftest-coverage')
gjcarneiro@537
   283
        variant_env.append_value('CXXFLAGS', '-fprofile-arcs')
gjcarneiro@537
   284
        variant_env.append_value('CXXFLAGS', '-ftest-coverage')
gjcarneiro@537
   285
        variant_env.append_value('LINKFLAGS', '-fprofile-arcs')
gjcarneiro@537
   286
    
gjcarneiro@537
   287
    conf.env['NS3_ACTIVE_VARIANT'] = variant_name
gjcarneiro@537
   288
    variant_env['NS3_ACTIVE_VARIANT'] = variant_name
gjcarneiro@537
   289
    variant_env.set_variant(variant_name)
gjcarneiro@537
   290
    conf.set_env_name(variant_name, variant_env)
gjcarneiro@537
   291
    conf.setenv(variant_name)
gjc@4069
   292
    env = variant_env
gjcarneiro@537
   293
gjc@4069
   294
    if Options.options.build_profile == 'debug':
gjc@4069
   295
        env.append_value('CXXDEFINES', 'NS3_ASSERT_ENABLE')
gjc@4069
   296
        env.append_value('CXXDEFINES', 'NS3_LOG_ENABLE')
gjc@1426
   297
craigdo@4190
   298
    env['PLATFORM'] = sys.platform
craigdo@4190
   299
mazo@5252
   300
    if conf.env['CXX_NAME'] in ['gcc', 'icc']:
mazo@5463
   301
        if Options.options.build_profile == 'release': 
mazo@5463
   302
            env.append_value('CXXFLAGS', '-fomit-frame-pointer') 
mazo@5463
   303
            if conf.check_compilation_flag('-march=native'):
mazo@5463
   304
                env.append_value('CXXFLAGS', '-march=native') 
mazo@5463
   305
gjc@4348
   306
        if sys.platform == 'win32':
gjc@4069
   307
            env.append_value("LINKFLAGS", "-Wl,--enable-runtime-pseudo-reloc")
gjc@4348
   308
        elif sys.platform == 'cygwin':
gjc@4348
   309
            env.append_value("LINKFLAGS", "-Wl,--enable-auto-import")
gjc@4446
   310
gjcarneiro@4386
   311
        cxx, = env['CXX']
gjc@4446
   312
gjcarneiro@4386
   313
        p = subprocess.Popen([cxx, '-print-file-name=libstdc++.so'], stdout=subprocess.PIPE)
gjc@4387
   314
        libstdcxx_location = os.path.dirname(p.stdout.read().strip())
gjcarneiro@4386
   315
        p.wait()
gjc@4387
   316
        if libstdcxx_location:
gjc@4387
   317
            conf.env.append_value('NS3_MODULE_PATH', libstdcxx_location)
gjc@647
   318
gjc@4447
   319
        if Options.platform in ['linux']:
gjc@4447
   320
            if conf.check_compilation_flag('-Wl,--soname=foo'):
gjc@4447
   321
                env['WL_SONAME_SUPPORTED'] = True
gjc@4446
   322
gjcarneiro@537
   323
    conf.sub_config('src')
gjc@3408
   324
    conf.sub_config('bindings/python')
gjcarneiro@537
   325
gjc@4064
   326
    if Options.options.enable_modules:
gjc@1880
   327
        conf.env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
gjc@4064
   328
                                           Options.options.enable_modules.split(',')]
jpelkey@6113
   329
    # for MPI
jpelkey@6113
   330
    conf.find_program('mpic++', var='MPI')
jpelkey@6113
   331
    if Options.options.enable_mpi and conf.env['MPI']:
jpelkey@6113
   332
        p = subprocess.Popen([conf.env['MPI'], '-showme:compile'], stdout=subprocess.PIPE)
jpelkey@6113
   333
        flags = p.stdout.read().rstrip().split()
jpelkey@6113
   334
        p.wait()
jpelkey@6113
   335
        env.append_value("CXXFLAGS_MPI", flags)
jpelkey@6113
   336
jpelkey@6113
   337
        p = subprocess.Popen([conf.env['MPI'], '-showme:link'], stdout=subprocess.PIPE)
jpelkey@6113
   338
        flags = p.stdout.read().rstrip().split()
jpelkey@6113
   339
        p.wait()
jpelkey@6113
   340
        env.append_value("LINKFLAGS_MPI", flags)
jpelkey@6113
   341
jpelkey@6113
   342
        env.append_value('CXXDEFINES', 'NS3_MPI')
jpelkey@6113
   343
        conf.report_optional_feature("mpi", "MPI Support", True, '')
jpelkey@6113
   344
        conf.env['ENABLE_MPI'] = True
jpelkey@6113
   345
    else:
jpelkey@6113
   346
        if Options.options.enable_mpi:
jpelkey@6113
   347
            conf.report_optional_feature("mpi", "MPI Support", False, 'mpic++ not found')
jpelkey@6113
   348
        else:
jpelkey@6113
   349
            conf.report_optional_feature("mpi", "MPI Support", False, 'option --enable-mpi not selected')
gjc@1880
   350
craigdo@3826
   351
    # for suid bits
craigdo@3826
   352
    conf.find_program('sudo', var='SUDO')
craigdo@3826
   353
craigdo@4171
   354
    why_not_sudo = "because we like it"
craigdo@4171
   355
    if Options.options.enable_sudo and conf.env['SUDO']:
craigdo@4171
   356
        env['ENABLE_SUDO'] = True
craigdo@4171
   357
    else:
craigdo@4171
   358
        env['ENABLE_SUDO'] = False
craigdo@4171
   359
        if Options.options.enable_sudo:
craigdo@4171
   360
            why_not_sudo = "program sudo not found"
craigdo@4171
   361
        else:
craigdo@4171
   362
            why_not_sudo = "option --enable-sudo not selected"
craigdo@4171
   363
craigdo@4171
   364
    conf.report_optional_feature("ENABLE_SUDO", "Use sudo to set suid bit", env['ENABLE_SUDO'], why_not_sudo)
craigdo@4171
   365
craigdo@5369
   366
    if Options.options.enable_examples:
craigdo@5369
   367
        env['ENABLE_EXAMPLES'] = True
craigdo@5369
   368
        why_not_examples = "defaults to enabled"
craigdo@5369
   369
    else:
craigdo@5369
   370
        env['ENABLE_EXAMPLES'] = False
craigdo@5369
   371
        why_not_examples = "option --disable-examples selected"
craigdo@5369
   372
craigdo@5369
   373
    conf.report_optional_feature("ENABLE_EXAMPLES", "Build examples and samples", env['ENABLE_EXAMPLES'], 
craigdo@5369
   374
                                 why_not_examples)
craigdo@5369
   375
gjc@3677
   376
    # we cannot pull regression traces without mercurial
gjc@3677
   377
    conf.find_program('hg', var='MERCURIAL')
gjc@3677
   378
gjc@4119
   379
    conf.find_program('valgrind', var='VALGRIND')
gjc@4119
   380
mathieu@4436
   381
    env['ENABLE_STATIC_NS3'] = False
mathieu@4436
   382
    if Options.options.enable_static:
mathieu@4436
   383
        if env['PLATFORM'].startswith('linux') and \
mazo@5252
   384
                env['CXX_NAME'] in ['gcc', 'icc']:
ahippo@4450
   385
            if re.match('i[3-6]86', os.uname()[4]):
mathieu@4438
   386
                conf.report_optional_feature("static", "Static build", True, '')
mathieu@4436
   387
                env['ENABLE_STATIC_NS3'] = True
mathieu@4436
   388
            elif os.uname()[4] == 'x86_64':
mathieu@4436
   389
                if env['ENABLE_PYTHON_BINDINGS'] and \
mathieu@4436
   390
                        not conf.check_compilation_flag('-mcmodel=large'):
mathieu@4436
   391
                    conf.report_optional_feature("static", "Static build", False,
mathieu@4436
   392
                                                 "Can't enable static builds because " + \
mathieu@4441
   393
                                                     "no -mcmodel=large compiler " \
mathieu@4436
   394
                                                     "option. Try --disable-python or upgrade your " \
mathieu@4441
   395
                                                     "compiler to at least gcc 4.3.x.")
mathieu@4436
   396
                else:
mathieu@4438
   397
                    conf.report_optional_feature("static", "Static build", True, '')
mathieu@4438
   398
                    env['ENABLE_STATIC_NS3'] = True                    
mathieu@4439
   399
        elif env['CXX_NAME'] == 'gcc' and \
mathieu@4439
   400
                (env['PLATFORM'].startswith('darwin') or \
mathieu@4439
   401
                     env['PLATFORM'].startswith('cygwin')):
mathieu@4438
   402
                conf.report_optional_feature("static", "Static build", True, '')
mathieu@4438
   403
                env['ENABLE_STATIC_NS3'] = True
mathieu@4436
   404
        else:
mathieu@4436
   405
            conf.report_optional_feature("static", "Static build", False,
mathieu@4436
   406
                                         "Unsupported platform")
mathieu@4436
   407
    else:
mathieu@4436
   408
        conf.report_optional_feature("static", "Static build", False,
mathieu@4436
   409
                                     "option --enable-static not selected")
craigdo@4773
   410
    have_gsl = conf.pkg_check_modules('GSL', 'gsl', mandatory=False)
craigdo@4773
   411
    conf.env['ENABLE_GSL'] = have_gsl
mathieu@4436
   412
craigdo@4773
   413
    conf.report_optional_feature("GSL", "GNU Scientific Library (GSL)",
craigdo@4773
   414
                                 conf.env['ENABLE_GSL'],
craigdo@4773
   415
                                 "GSL not found")
craigdo@4773
   416
    if have_gsl:
craigdo@4773
   417
        conf.env.append_value('CXXDEFINES', "ENABLE_GSL")
craigdo@4773
   418
        conf.env.append_value('CCDEFINES', "ENABLE_GSL")
mathieu@4392
   419
gjc@5996
   420
    # for compiling C code, copy over the CXX* flags
gjc@5996
   421
    conf.env.append_value('CCFLAGS', conf.env['CXXFLAGS'])
gjc@5996
   422
    conf.env.append_value('CCDEFINES', conf.env['CXXDEFINES'])
gjc@5996
   423
gjc@6362
   424
    def add_gcc_flag(flag):
gjc@6362
   425
        if env['COMPILER_CXX'] == 'g++' and 'CXXFLAGS' not in os.environ:
gjc@6362
   426
            if conf.check_compilation_flag(flag, mode='cxx'):
gjc@6362
   427
                env.append_value('CXXFLAGS', flag)
gjc@6362
   428
        if env['COMPILER_CC'] == 'gcc' and 'CCFLAGS' not in os.environ:
gjc@6362
   429
            if conf.check_compilation_flag(flag, mode='cc'):
gjc@6362
   430
                env.append_value('CCFLAGS', flag)
gjc@6362
   431
gjc@6362
   432
    add_gcc_flag('-Wno-error=deprecated-declarations')
gjc@6362
   433
    add_gcc_flag('-fstrict-aliasing')
gjc@6362
   434
    add_gcc_flag('-Wstrict-aliasing')
gjc@6362
   435
gjc@6099
   436
mazo@5454
   437
    # append user defined flags after all our ones
mazo@5454
   438
    for (confvar, envvar) in [['CCFLAGS', 'CCFLAGS_EXTRA'],
mazo@5454
   439
                              ['CXXFLAGS', 'CXXFLAGS_EXTRA'],
mazo@5454
   440
                              ['LINKFLAGS', 'LINKFLAGS_EXTRA'],
mazo@5454
   441
                              ['LINKFLAGS', 'LDFLAGS_EXTRA']]:
mazo@5454
   442
        if envvar in os.environ:
mazo@5454
   443
            conf.env.append_value(confvar, os.environ[envvar])
mazo@5454
   444
gjc@3625
   445
    # Write a summary of optional features status
gjc@3625
   446
    print "---- Summary of optional NS-3 features:"
gjc@3625
   447
    for (name, caption, was_enabled, reason_not_enabled) in conf.env['NS3_OPTIONAL_FEATURES']:
gjc@3625
   448
        if was_enabled:
gjc@3625
   449
            status = 'enabled'
gjc@3625
   450
        else:
gjc@3625
   451
            status = 'not enabled (%s)' % reason_not_enabled
gjc@3625
   452
        print "%-30s: %s" % (caption, status)
gjc@3625
   453
gjcarneiro@537
   454
craigdo@3826
   455
class SuidBuildTask(Task.TaskBase):
craigdo@3826
   456
    """task that makes a binary Suid
craigdo@3826
   457
    """
craigdo@4179
   458
    after = 'cxx_link cc_link'
craigdo@4179
   459
    maxjobs = 1
craigdo@3826
   460
    def __init__(self, bld, program):
gjc@4367
   461
        self.bld = bld
craigdo@3826
   462
        self.m_display = 'build-suid'
craigdo@3826
   463
        self.__program = program
craigdo@4164
   464
        self.__env = bld.env.copy ()
gjc@4367
   465
        super(SuidBuildTask, self).__init__(generator=self)
craigdo@3826
   466
        try:
gjc@3866
   467
            program_obj = wutils.find_program(self.__program.target, self.__env)
craigdo@3826
   468
        except ValueError, ex:
gjc@4064
   469
            raise Utils.WafError(str(ex))
craigdo@4179
   470
        program_node = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj))
craigdo@4179
   471
        self.filename = program_node.abspath(self.__env)
craigdo@3826
   472
craigdo@4179
   473
craigdo@4179
   474
    def run(self):
craigdo@4179
   475
        print >> sys.stderr, 'setting suid bit on executable ' + self.filename
craigdo@4179
   476
        if subprocess.Popen(['sudo', 'chown', 'root', self.filename]).wait():
craigdo@4179
   477
            return 1
craigdo@4179
   478
        if subprocess.Popen(['sudo', 'chmod', 'u+s', self.filename]).wait():
craigdo@4179
   479
            return 1
craigdo@4179
   480
        return 0
craigdo@4179
   481
craigdo@4179
   482
    def runnable_status(self):
craigdo@4179
   483
        "RUN_ME SKIP_ME or ASK_LATER"
craigdo@4179
   484
        st = os.stat(self.filename)
craigdo@4179
   485
        if st.st_uid == 0:
craigdo@4179
   486
            return Constants.SKIP_ME
craigdo@4179
   487
        else:
craigdo@4179
   488
            return Constants.RUN_ME
craigdo@4179
   489
craigdo@3826
   490
craigdo@3826
   491
def create_suid_program(bld, name):
gjc@4064
   492
    program = bld.new_task_gen('cxx', 'program')
craigdo@3826
   493
    program.is_ns3_program = True
craigdo@3826
   494
    program.module_deps = list()
craigdo@3826
   495
    program.name = name
craigdo@3826
   496
    program.target = name
craigdo@4164
   497
craigdo@4171
   498
    if bld.env['ENABLE_SUDO']:
gjc@4064
   499
        SuidBuildTask(bld, program)
craigdo@4171
   500
craigdo@3826
   501
    return program
craigdo@3826
   502
gjc@1217
   503
def create_ns3_program(bld, name, dependencies=('simulator',)):
gjc@4064
   504
    program = bld.new_task_gen('cxx', 'program')
gjc@3001
   505
    program.is_ns3_program = True
gjc@1217
   506
    program.name = name
gjc@1217
   507
    program.target = program.name
gjc@1220
   508
    program.uselib_local = 'ns3'
gjc@1858
   509
    program.ns3_module_dependencies = ['ns3-'+dep for dep in dependencies]
mathieu@4392
   510
    if program.env['ENABLE_STATIC_NS3']:
mathieu@4438
   511
        if sys.platform == 'darwin':
mathieu@4438
   512
            program.env.append_value('LINKFLAGS', '-Wl,-all_load')
mathieu@4438
   513
            program.env.append_value('LINKFLAGS', '-lns3')
mathieu@4438
   514
        else:
mathieu@4438
   515
            program.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
mathieu@4438
   516
            program.env.append_value('LINKFLAGS', '-lns3')
mathieu@4438
   517
            program.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
gjc@1217
   518
    return program
gjc@1217
   519
mathieu@5848
   520
def add_examples_programs(bld):
mathieu@5848
   521
    env = bld.env_of_name('default')
mathieu@5848
   522
    if env['ENABLE_EXAMPLES']:
mathieu@5848
   523
        for dir in os.listdir('examples'):
mazo@6214
   524
            if dir.startswith('.') or dir == 'CVS':
mazo@6214
   525
                continue
mathieu@5848
   526
            if os.path.isdir(os.path.join('examples', dir)):
mathieu@5848
   527
                bld.add_subdirs(os.path.join('examples', dir))
mathieu@5848
   528
mathieu@5848
   529
gjc@3275
   530
def add_scratch_programs(bld):
gjc@4064
   531
    all_modules = [mod[len("ns3-"):] for mod in bld.env['NS3_MODULES']]
gjc@3275
   532
    for filename in os.listdir("scratch"):
ahippo@3867
   533
        if filename.startswith('.') or filename == 'CVS':
ahippo@3867
   534
	    continue
gjc@3275
   535
        if os.path.isdir(os.path.join("scratch", filename)):
gjc@3275
   536
            obj = bld.create_ns3_program(filename, all_modules)
gjc@4108
   537
            obj.path = obj.path.find_dir('scratch').find_dir(filename)
gjc@4108
   538
            obj.find_sources_in_dirs('.')
gjc@4108
   539
            obj.target = filename
gjc@3927
   540
            obj.name = obj.target
gjc@3275
   541
        elif filename.endswith(".cc"):
gjc@3275
   542
            name = filename[:-len(".cc")]
gjc@3275
   543
            obj = bld.create_ns3_program(name, all_modules)
gjc@4108
   544
            obj.path = obj.path.find_dir('scratch')
gjc@4108
   545
            obj.source = filename
gjc@4108
   546
            obj.target = name
gjc@3927
   547
            obj.name = obj.target
gjc@1217
   548
gjc@3282
   549
gjcarneiro@537
   550
def build(bld):
gjc@4326
   551
    wutils.bld = bld
gjc@4064
   552
    if Options.options.no_task_lines:
gjc@2866
   553
        import Runner
gjc@2866
   554
        def null_printout(s):
gjc@2866
   555
            pass
gjc@2866
   556
        Runner.printout = null_printout
gjc@2866
   557
gjc@4064
   558
    Options.cwd_launch = bld.path.abspath()
gjc@1217
   559
    bld.create_ns3_program = types.MethodType(create_ns3_program, bld)
craigdo@3826
   560
    bld.create_suid_program = types.MethodType(create_suid_program, bld)
gjc@4064
   561
gjc@4064
   562
    # switch default variant to the one matching our debug level
gjcarneiro@537
   563
    variant_name = bld.env_of_name('default')['NS3_ACTIVE_VARIANT']
gjcarneiro@537
   564
    variant_env = bld.env_of_name(variant_name)
gjc@4064
   565
    bld.all_envs['default'] = variant_env
gjc@762
   566
gjcarneiro@537
   567
    # process subfolders from here
gjcarneiro@537
   568
    bld.add_subdirs('src')
craigdo@5369
   569
    bld.add_subdirs('samples')
craigdo@5369
   570
    bld.add_subdirs('utils')
gjcarneiro@537
   571
mathieu@5848
   572
    add_examples_programs(bld)
gjc@3275
   573
    add_scratch_programs(bld)
gjc@3275
   574
gjc@1880
   575
    ## if --enabled-modules option was given, we disable building the
gjc@1880
   576
    ## modules that were not enabled, and programs that depend on
gjc@1880
   577
    ## disabled modules.
gjc@4064
   578
    env = bld.env
gjc@1880
   579
gjc@4064
   580
    if Options.options.enable_modules:
gjc@4064
   581
        Logs.warn("the option --enable-modules is being applied to this build only;"
gjc@1880
   582
                       " to make it permanent it needs to be given to waf configure.")
gjc@1880
   583
        env['NS3_ENABLED_MODULES'] = ['ns3-'+mod for mod in
gjc@4064
   584
                                      Options.options.enable_modules.split(',')]
gjc@1880
   585
gjc@1880
   586
    if env['NS3_ENABLED_MODULES']:
gjc@1880
   587
        modules = env['NS3_ENABLED_MODULES']
gjc@1880
   588
        changed = True
gjc@1880
   589
        while changed:
gjc@1880
   590
            changed = False
gjc@1880
   591
            for module in modules:
gjc@1880
   592
                module_obj = Object.name_to_obj(module)
gjc@1880
   593
                if module_obj is None:
gjc@1880
   594
                    raise ValueError("module %s not found" % module)
gjc@1880
   595
                for dep in module_obj.add_objects:
gjc@1880
   596
                    if not dep.startswith('ns3-'):
gjc@1880
   597
                        continue
gjc@1880
   598
                    if dep not in modules:
gjc@1880
   599
                        modules.append(dep)
gjc@1880
   600
                        changed = True
gjc@1880
   601
gjc@1880
   602
        ## remove objects that depend on modules not listed
gjc@4326
   603
        for obj in list(bld.all_task_gen):
gjc@1880
   604
            if hasattr(obj, 'ns3_module_dependencies'):
gjc@1880
   605
                for dep in obj.ns3_module_dependencies:
gjc@1880
   606
                    if dep not in modules:
gjc@4326
   607
                        bld.all_task_gen.remove(obj)
gjc@1880
   608
                        break
gjc@1880
   609
            if obj.name in env['NS3_MODULES'] and obj.name not in modules:
gjc@4326
   610
                bld.all_task_gen.remove(obj)
gjc@1880
   611
gjc@1880
   612
    ## Create a single ns3 library containing all enabled modules
mathieu@4392
   613
    if env['ENABLE_STATIC_NS3']:
mathieu@4392
   614
        lib = bld.new_task_gen('cxx', 'staticlib')
gjc@4446
   615
        lib.name = 'ns3'
gjc@4446
   616
        lib.target = 'ns3'
mathieu@4392
   617
    else:
mathieu@4392
   618
        lib = bld.new_task_gen('cxx', 'shlib')
gjc@4446
   619
        lib.name = 'ns3'
gjc@4446
   620
        lib.target = 'ns3'
mazo@5252
   621
        if lib.env['CXX_NAME'] in ['gcc', 'icc'] and env['WL_SONAME_SUPPORTED']:
gjc@4446
   622
            lib.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % ccroot.get_target_name(lib))
gjc@4535
   623
        if sys.platform == 'cygwin':
gjc@4535
   624
            lib.features.append('implib') # workaround for WAF bug #472
mathieu@4392
   625
gjc@1880
   626
    if env['NS3_ENABLED_MODULES']:
gjc@1880
   627
        lib.add_objects = list(modules)
gjc@3408
   628
        env['NS3_ENABLED_MODULES'] = list(modules)
gjc@3014
   629
        lib.uselib_local = list(modules)
gjc@1880
   630
    else:
gjc@1880
   631
        lib.add_objects = list(env['NS3_MODULES'])
gjc@3014
   632
        lib.uselib_local = list(env['NS3_MODULES'])
gjc@1880
   633
gjc@3408
   634
    bld.add_subdirs('bindings/python')
gjc@1880
   635
gjc@4064
   636
    if Options.options.run:
gjc@3919
   637
        # Check that the requested program name is valid
gjc@4119
   638
        program_name, dummy_program_argv = wutils.get_run_program(Options.options.run, wutils.get_command_template(env))
gjc@3933
   639
gjc@3919
   640
        # When --run'ing a program, tell WAF to only build that program,
gjc@3919
   641
        # nothing more; this greatly speeds up compilation when all you
gjc@3919
   642
        # want to do is run a test program.
gjc@4760
   643
        Options.options.compile_targets += ',' + os.path.basename(program_name)
gjc@4760
   644
        for gen in bld.all_task_gen:
gjc@4760
   645
            if type(gen).__name__ in ['ns3header_taskgen', 'ns3moduleheader_taskgen']:
gjc@4760
   646
                gen.post()
gjc@3919
   647
gjc@4114
   648
    if Options.options.regression or Options.options.regression_generate:
gjc@4114
   649
        regression_traces = env['REGRESSION_TRACES']
gjc@4114
   650
        if not regression_traces:
gjc@4114
   651
            raise Utils.WafError("Cannot run regression tests: reference traces directory not given"
gjc@4114
   652
                                 " (--with-regression-traces configure option)")
gjc@3919
   653
craigdo@5369
   654
        if env['ENABLE_EXAMPLES'] == True:
craigdo@5369
   655
            regression.run_regression(bld, regression_traces)
craigdo@5369
   656
        else:
craigdo@5369
   657
            raise Utils.WafError("Cannot run regression tests: building the ns-3 examples is not enabled"
craigdo@5369
   658
                                 " (regression tests are based on examples)")
gjcarneiro@537
   659
gjc@5468
   660
gjc@5468
   661
    if Options.options.doxygen_no_build:
gjc@5468
   662
        _doxygen(bld)
gjc@5468
   663
        raise SystemExit(0)
gjc@5468
   664
gjc@4326
   665
def shutdown(ctx):
gjc@4326
   666
    bld = wutils.bld
gjc@4328
   667
    if wutils.bld is None:
gjc@4328
   668
        return
gjc@4326
   669
    env = bld.env
gjc@4326
   670
gjc@4064
   671
    if Options.options.lcov_report:
gjc@671
   672
        lcov_report()
gjcarneiro@537
   673
gjc@4064
   674
    if Options.options.run:
gjc@4332
   675
        wutils.run_program(Options.options.run, env, wutils.get_command_template(env))
gjc@935
   676
        raise SystemExit(0)
gjc@935
   677
gjc@4064
   678
    if Options.options.pyrun:
gjc@4332
   679
        wutils.run_python_program(Options.options.pyrun, env)
gjc@3419
   680
        raise SystemExit(0)
gjc@3419
   681
gjc@4326
   682
    if Options.options.shell:
craigdo@5361
   683
        raise Utils.WafError("Please run `./waf shell' now, instead of `./waf --shell'")
gjc@4326
   684
craigdo@5361
   685
    if Options.options.check:
craigdo@5361
   686
        raise Utils.WafError("Please run `./test.py' now, instead of `./waf --check'")
gjc@4326
   687
gjc@4326
   688
    check_shell(bld)
gjc@4326
   689
gjc@5201
   690
check_context = Build.BuildContext
gjc@4326
   691
gjc@4326
   692
def check(bld):
craigdo@5372
   693
    """run the equivalent of the old ns-3 unit tests using test.py"""
craigdo@5392
   694
    env = wutils.bld.env
craigdo@5392
   695
    wutils.run_python_program("test.py -n -c core", env)
gjc@1536
   696
gjc@4531
   697
class print_introspected_doxygen_task(Task.TaskBase):
gjc@4531
   698
    after = 'cc cxx cc_link cxx_link'
gjc@4531
   699
    color = 'BLUE'
gjc@3408
   700
gjc@4531
   701
    def __init__(self, bld):
gjc@4531
   702
        self.bld = bld
gjc@4531
   703
        super(print_introspected_doxygen_task, self).__init__(generator=self)
gjc@4531
   704
        
gjc@4531
   705
    def __str__(self):
gjc@4531
   706
        return 'print-introspected-doxygen\n'
gjc@3408
   707
gjc@4531
   708
    def runnable_status(self):
gjc@4531
   709
        return Task.RUN_ME
gjc@4531
   710
gjc@4531
   711
    def run(self):
gjc@4531
   712
        ## generate the trace sources list docs
gjc@4531
   713
        env = wutils.bld.env
gjc@4531
   714
        proc_env = wutils.get_proc_env()
gjc@4531
   715
        try:
gjc@4531
   716
            program_obj = wutils.find_program('print-introspected-doxygen', env)
gjc@4531
   717
        except ValueError: # could happen if print-introspected-doxygen is
gjc@4531
   718
                           # not built because of waf configure
gjc@4531
   719
                           # --enable-modules=xxx
gjc@4531
   720
            pass
gjc@4531
   721
        else:
gjc@4531
   722
            prog = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj)).abspath(env)
gjc@4531
   723
            out = open(os.path.join('..', 'doc', 'introspected-doxygen.h'), 'w')
gjc@4531
   724
            if subprocess.Popen([prog], stdout=out, env=proc_env).wait():
gjc@4531
   725
                raise SystemExit(1)
gjc@4531
   726
            out.close()
gjc@4531
   727
gjc@4531
   728
class run_python_unit_tests_task(Task.TaskBase):
gjc@4531
   729
    after = 'cc cxx cc_link cxx_link'
gjc@4531
   730
    color = 'BLUE'
gjc@4531
   731
gjc@4531
   732
    def __init__(self, bld):
gjc@4531
   733
        self.bld = bld
gjc@4531
   734
        super(run_python_unit_tests_task, self).__init__(generator=self)
gjc@4531
   735
        
gjc@4531
   736
    def __str__(self):
gjc@4531
   737
        return 'run-python-unit-tests\n'
gjc@4531
   738
gjc@4531
   739
    def runnable_status(self):
gjc@4531
   740
        return Task.RUN_ME
gjc@4531
   741
gjc@4531
   742
    def run(self):
gjc@4531
   743
        proc_env = wutils.get_proc_env()
gjc@4531
   744
        wutils.run_argv([self.bld.env['PYTHON'], os.path.join("..", "utils", "python-unit-tests.py")],
gjc@4531
   745
                        self.bld.env, proc_env, force_no_valgrind=True)
gjc@4531
   746
gjc@4326
   747
def check_shell(bld):
craigdo@5975
   748
    if ('NS3_MODULE_PATH' not in os.environ) or ('NS3_EXECUTABLE_PATH' not in os.environ):
gjc@1016
   749
        return
gjc@4326
   750
    env = bld.env
gjc@1016
   751
    correct_modpath = os.pathsep.join(env['NS3_MODULE_PATH'])
gjc@1016
   752
    found_modpath = os.environ['NS3_MODULE_PATH']
craigdo@5975
   753
    correct_execpath = os.pathsep.join(env['NS3_EXECUTABLE_PATH'])
craigdo@5975
   754
    found_execpath = os.environ['NS3_EXECUTABLE_PATH']
craigdo@5975
   755
    if (found_modpath != correct_modpath) or (correct_execpath != found_execpath):
gjc@4326
   756
        msg = ("Detected shell (./waf shell) with incorrect configuration\n"
gjc@1016
   757
               "=========================================================\n"
gjc@1016
   758
               "Possible reasons for this problem:\n"
gjc@1016
   759
               "  1. You switched to another ns-3 tree from inside this shell\n"
gjc@1016
   760
               "  2. You switched ns-3 debug level (waf configure --debug)\n"
gjc@1016
   761
               "  3. You modified the list of built ns-3 modules\n"
gjc@1016
   762
               "You should correct this situation before running any program.  Possible solutions:\n"
gjc@1016
   763
               "  1. Exit this shell, and start a new one\n"
gjc@1016
   764
               "  2. Run a new nested shell")
gjc@4064
   765
        raise Utils.WafError(msg)
gjc@1016
   766
gjc@672
   767
gjc@4326
   768
shell_context = Build.BuildContext
gjc@4326
   769
def shell(ctx):
gjc@4326
   770
    """run a shell with an environment suitably modified to run locally built programs"""
gjc@4326
   771
gjc@4326
   772
    #make sure we build first"
gjc@4326
   773
    Scripting.build(ctx)
gjc@4326
   774
gjc@672
   775
    if sys.platform == 'win32':
gjc@672
   776
        shell = os.environ.get("COMSPEC", "cmd.exe")
gjc@672
   777
    else:
gjc@672
   778
        shell = os.environ.get("SHELL", "/bin/sh")
gjc@1016
   779
gjc@4326
   780
    env = wutils.bld.env
craigdo@5975
   781
    os_env = {'NS3_MODULE_PATH': os.pathsep.join(env['NS3_MODULE_PATH']), 'NS3_EXECUTABLE_PATH': os.pathsep.join(env['NS3_EXECUTABLE_PATH'])}
craigdo@5975
   782
    wutils.run_argv([shell], env, os_env)
gjc@672
   783
gjc@5468
   784
def _doxygen(bld):
craigdo@5392
   785
    env = wutils.bld.env
craigdo@5392
   786
    proc_env = wutils.get_proc_env()
gjc@1536
   787
craigdo@5392
   788
    try:
craigdo@5392
   789
        program_obj = wutils.find_program('print-introspected-doxygen', env)
craigdo@5392
   790
    except ValueError: 
craigdo@5392
   791
        Logs.warn("print-introspected-doxygen does not exist")
craigdo@5392
   792
        raise SystemExit(1)
craigdo@5392
   793
        return
craigdo@5392
   794
craigdo@5392
   795
    prog = program_obj.path.find_or_declare(ccroot.get_target_name(program_obj)).abspath(env)
gjc@6254
   796
gjc@6254
   797
    if not os.path.exists(prog):
gjc@6254
   798
        Logs.error("print-introspected-doxygen has not been built yet."
gjc@6254
   799
                   " You need to build ns-3 at least once before "
gjc@6254
   800
                   "generating doxygen docs...")
gjc@6254
   801
        raise SystemExit(1)
gjc@6254
   802
craigdo@5392
   803
    out = open(os.path.join('doc', 'introspected-doxygen.h'), 'w')
craigdo@5392
   804
craigdo@5392
   805
    if subprocess.Popen([prog], stdout=out, env=proc_env).wait():
craigdo@5392
   806
        raise SystemExit(1)
craigdo@5392
   807
    out.close()
craigdo@5392
   808
gjc@671
   809
    doxygen_config = os.path.join('doc', 'doxygen.conf')
gjc@671
   810
    if subprocess.Popen(['doxygen', doxygen_config]).wait():
gjc@671
   811
        raise SystemExit(1)
gjc@671
   812
gjc@5468
   813
def doxygen(bld):
gjc@5468
   814
    """do a full build, generate the introspected doxygen and then the doxygen"""
gjc@5468
   815
    Scripting.build(bld)
gjc@5468
   816
    _doxygen(bld)
gjc@5468
   817
gjc@671
   818
def lcov_report():
gjc@4064
   819
    env = Build.bld.env
gjc@671
   820
    variant_name = env['NS3_ACTIVE_VARIANT']
gjc@671
   821
gjc@671
   822
    if 'gcov' not in variant_name:
gjc@4064
   823
        raise Utils.WafError("project not configured for code coverage;"
gjc@671
   824
                     " reconfigure with --enable-gcov")
gjc@671
   825
gjc@671
   826
    os.chdir(blddir)
gjc@671
   827
    try:
gjc@671
   828
        lcov_report_dir = os.path.join(variant_name, 'lcov-report')
gjc@671
   829
        create_dir_command = "rm -rf " + lcov_report_dir
gjc@671
   830
        create_dir_command += " && mkdir " + lcov_report_dir + ";"
gjc@671
   831
gjc@671
   832
        if subprocess.Popen(create_dir_command, shell=True).wait():
gjcarneiro@537
   833
            raise SystemExit(1)
gjcarneiro@537
   834
gjc@671
   835
        info_file = os.path.join(lcov_report_dir, variant_name + '.info')
gjc@671
   836
        lcov_command = "../utils/lcov/lcov -c -d . -o " + info_file
gjc@671
   837
        lcov_command += " --source-dirs=" + os.getcwd()
gjc@671
   838
        lcov_command += ":" + os.path.join(
gjc@671
   839
            os.getcwd(), variant_name, 'include')
gjc@671
   840
        if subprocess.Popen(lcov_command, shell=True).wait():
gjc@671
   841
            raise SystemExit(1)
gjc@671
   842
gjc@671
   843
        genhtml_command = "../utils/lcov/genhtml -o " + lcov_report_dir
gjc@671
   844
        genhtml_command += " " + info_file
gjc@671
   845
        if subprocess.Popen(genhtml_command, shell=True).wait():
gjc@671
   846
            raise SystemExit(1)
gjc@671
   847
    finally:
gjc@671
   848
        os.chdir("..")
gjc@671
   849
gjc@2622
   850
##
gjc@2622
   851
## The default WAF DistDir implementation is rather slow, because it
gjc@2622
   852
## first copies everything and only later removes unwanted files and
gjc@2622
   853
## directories; this means that it needless copies the full build dir
gjc@2622
   854
## and the .hg repository tree.  Here we provide a replacement DistDir
gjc@2622
   855
## implementation that is more efficient.
gjc@2622
   856
##
gjc@2622
   857
import Scripting
gjc@4064
   858
from Scripting import dist_exts, excludes, BLDDIR
gjc@2622
   859
import Utils
gjc@2622
   860
import os
gjc@2622
   861
gjc@4326
   862
def _copytree(src, dst, symlinks=False, excludes=(), build_dir=None):
gjc@2622
   863
    """Recursively copy a directory tree using copy2().
gjc@2622
   864
gjc@2622
   865
    The destination directory must not already exist.
gjc@2622
   866
    If exception(s) occur, an Error is raised with a list of reasons.
gjc@2622
   867
gjc@2622
   868
    If the optional symlinks flag is true, symbolic links in the
gjc@2622
   869
    source tree result in symbolic links in the destination tree; if
gjc@2622
   870
    it is false, the contents of the files pointed to by symbolic
gjc@2622
   871
    links are copied.
gjc@2622
   872
gjc@2622
   873
    XXX Consider this example code rather than the ultimate tool.
gjc@2622
   874
gjc@2622
   875
    Note: this is a modified version of shutil.copytree from python
gjc@2622
   876
    2.5.2 library; modified for WAF purposes to exclude dot dirs and
gjc@2622
   877
    another list of files.
gjc@2622
   878
    """
gjc@2622
   879
    names = os.listdir(src)
gjc@2622
   880
    os.makedirs(dst)
gjc@2622
   881
    errors = []
gjc@2622
   882
    for name in names:
gjc@2622
   883
        srcname = os.path.join(src, name)
gjc@2622
   884
        dstname = os.path.join(dst, name)
gjc@2622
   885
        try:
gjc@2622
   886
            if symlinks and os.path.islink(srcname):
gjc@2622
   887
                linkto = os.readlink(srcname)
gjc@2622
   888
                os.symlink(linkto, dstname)
gjc@2622
   889
            elif os.path.isdir(srcname):
gjc@2622
   890
                if name in excludes:
gjc@2622
   891
                    continue
ahippo@3867
   892
                elif name.startswith('.') or name.startswith(',,') or name.startswith('++') or name.startswith('CVS'):
gjc@2622
   893
                    continue
gjc@2622
   894
                elif name == build_dir:
gjc@2622
   895
                    continue
gjc@2622
   896
                else:
gjc@2622
   897
                    ## build_dir is not passed into the recursive
gjc@2622
   898
                    ## copytree, but that is intentional; it is a
gjc@2622
   899
                    ## directory name valid only at the top level.
gjc@2622
   900
                    copytree(srcname, dstname, symlinks, excludes)
gjc@2622
   901
            else:
gjc@2622
   902
                ends = name.endswith
gjc@2622
   903
                to_remove = False
gjc@2622
   904
                if name.startswith('.') or name.startswith('++'):
gjc@2622
   905
                    to_remove = True
gjc@2622
   906
                else:
gjc@4064
   907
                    for x in dist_exts:
gjc@2622
   908
                        if ends(x):
gjc@2622
   909
                            to_remove = True
gjc@2622
   910
                            break
gjc@2622
   911
                if not to_remove:
gjc@2622
   912
                    shutil.copy2(srcname, dstname)
gjc@2622
   913
            # XXX What about devices, sockets etc.?
gjc@2622
   914
        except (IOError, os.error), why:
gjc@2622
   915
            errors.append((srcname, dstname, str(why)))
gjc@2622
   916
        # catch the Error from the recursive copytree so that we can
gjc@2622
   917
        # continue with other files
gjc@2622
   918
        except shutil.Error, err:
gjc@2622
   919
            errors.extend(err.args[0])
gjc@2622
   920
    try:
gjc@2622
   921
        shutil.copystat(src, dst)
gjc@2622
   922
    except WindowsError:
gjc@2622
   923
        # can't copy file access times on Windows
gjc@2622
   924
        pass
gjc@2622
   925
    except OSError, why:
gjc@2622
   926
        errors.extend((src, dst, str(why)))
gjc@2622
   927
    if errors:
gjc@2622
   928
        raise shutil.Error, errors
gjc@2622
   929
gjc@2622
   930
gjc@2622
   931
def DistDir(appname, version):
gjc@4326
   932
    #"make a distribution directory with all the sources in it"
gjc@2622
   933
    import shutil
gjc@2622
   934
gjc@2622
   935
    # Our temporary folder where to put our files
gjc@2622
   936
    TMPFOLDER=appname+'-'+version
gjc@2622
   937
gjc@2622
   938
    # Remove an old package directory
gjc@2622
   939
    if os.path.exists(TMPFOLDER): shutil.rmtree(TMPFOLDER)
gjc@2622
   940
gjc@2622
   941
    global g_dist_exts, g_excludes
gjc@2622
   942
gjc@2622
   943
    # Remove the Build dir
gjc@2622
   944
    build_dir = getattr(Utils.g_module, BLDDIR, None)
gjc@2622
   945
gjc@2622
   946
    # Copy everything into the new folder
gjc@4326
   947
    _copytree('.', TMPFOLDER, excludes=excludes, build_dir=build_dir)
gjc@2622
   948
gjc@2622
   949
    # TODO undocumented hook
gjc@2622
   950
    dist_hook = getattr(Utils.g_module, 'dist_hook', None)
gjc@2622
   951
    if dist_hook:
gjc@2622
   952
        os.chdir(TMPFOLDER)
gjc@2622
   953
        try:
gjc@2622
   954
            dist_hook()
gjc@2622
   955
        finally:
gjc@2622
   956
            # go back to the root directory
gjc@2622
   957
            os.chdir('..')
gjc@2622
   958
    return TMPFOLDER
gjc@2622
   959
gjc@2622
   960
Scripting.DistDir = DistDir
gjc@2881
   961
gjc@2881
   962