2007-05-07 12:01:51 +01:00
|
|
|
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
|
|
|
|
|
|
2007-06-12 18:52:58 +01:00
|
|
|
import os, os.path
|
2007-05-24 17:54:51 +01:00
|
|
|
import shutil
|
2007-08-08 15:10:36 +01:00
|
|
|
import types
|
2008-12-29 13:28:54 +00:00
|
|
|
import warnings
|
2007-05-24 17:54:51 +01:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
import TaskGen
|
|
|
|
|
import Task
|
|
|
|
|
import Options
|
|
|
|
|
import Build
|
2009-04-13 23:10:37 +01:00
|
|
|
import Utils
|
2010-10-26 15:11:17 +01:00
|
|
|
import Constants
|
2007-05-24 17:54:51 +01:00
|
|
|
|
2011-03-18 10:58:21 -07:00
|
|
|
import ccroot
|
|
|
|
|
ccroot.USE_TOP_LEVEL = True
|
|
|
|
|
|
2010-04-06 11:34:06 +04:00
|
|
|
try:
|
|
|
|
|
set
|
|
|
|
|
except NameError:
|
|
|
|
|
from sets import Set as set # Python 2.3 fallback
|
|
|
|
|
|
2007-07-24 16:13:31 +01:00
|
|
|
all_modules = (
|
2007-05-13 12:46:18 +01:00
|
|
|
'core',
|
2011-02-21 09:11:37 -08:00
|
|
|
'network',
|
2011-03-24 09:23:44 -07:00
|
|
|
'config-store',
|
2011-02-25 10:32:35 -08:00
|
|
|
'internet',
|
2011-01-28 14:11:21 -08:00
|
|
|
'propagation',
|
2011-03-04 01:26:54 +00:00
|
|
|
'point-to-point',
|
|
|
|
|
'csma',
|
|
|
|
|
'emu',
|
|
|
|
|
'bridge',
|
|
|
|
|
'tap-bridge',
|
|
|
|
|
'virtual-net-device',
|
2011-03-02 13:42:28 -08:00
|
|
|
'applications',
|
2011-03-04 01:26:54 +00:00
|
|
|
'nix-vector-routing',
|
|
|
|
|
'olsr',
|
|
|
|
|
'aodv',
|
|
|
|
|
'dsdv',
|
|
|
|
|
'click',
|
2011-03-11 15:21:50 -05:00
|
|
|
'openflow',
|
2007-07-23 15:53:54 +02:00
|
|
|
'mobility',
|
2011-03-04 01:26:54 +00:00
|
|
|
'wifi',
|
2011-03-05 10:51:26 -08:00
|
|
|
'netanim',
|
2011-03-04 10:56:07 -08:00
|
|
|
'stats',
|
2011-03-04 01:26:54 +00:00
|
|
|
'uan',
|
2011-01-31 10:13:32 +01:00
|
|
|
'spectrum',
|
2011-03-03 16:27:21 -08:00
|
|
|
'mesh',
|
2009-09-27 23:51:23 -07:00
|
|
|
'test',
|
2009-09-12 19:44:17 -07:00
|
|
|
'test/ns3tcp',
|
|
|
|
|
'test/ns3wifi',
|
2011-03-22 16:56:10 -07:00
|
|
|
'flow-monitor',
|
2011-03-04 01:26:54 +00:00
|
|
|
'wimax',
|
|
|
|
|
'lte',
|
2010-03-08 21:07:31 -05:00
|
|
|
'mpi',
|
2011-03-04 09:59:42 -08:00
|
|
|
'topology-read',
|
2011-03-22 16:40:32 -07:00
|
|
|
'energy',
|
2011-03-24 09:23:44 -07:00
|
|
|
'tools',
|
2011-03-24 10:54:24 -07:00
|
|
|
'visualizer',
|
2007-07-24 16:13:31 +01:00
|
|
|
)
|
2007-05-13 12:46:18 +01:00
|
|
|
|
2007-05-07 12:01:51 +01:00
|
|
|
def set_options(opt):
|
2011-02-18 16:05:39 -08:00
|
|
|
opt.sub_options('core')
|
2011-03-04 01:26:54 +00:00
|
|
|
opt.sub_options('click')
|
2011-03-11 15:21:50 -05:00
|
|
|
opt.sub_options('openflow')
|
2007-07-20 11:38:16 +01:00
|
|
|
|
|
|
|
|
opt.add_option('--enable-rpath',
|
|
|
|
|
help=("Link programs with rpath"
|
|
|
|
|
" (normally not needed, see "
|
|
|
|
|
" --run and --shell; moreover, only works in some"
|
|
|
|
|
" specific platforms, such as Linux and Solaris)"),
|
|
|
|
|
action="store_true", dest='enable_rpath', default=False)
|
2009-01-27 20:26:34 -08:00
|
|
|
|
2007-11-20 18:27:43 +00:00
|
|
|
opt.add_option('--enable-modules',
|
|
|
|
|
help=("Build only these modules (and dependencies)"),
|
|
|
|
|
dest='enable_modules')
|
|
|
|
|
|
2007-05-07 12:01:51 +01:00
|
|
|
def configure(conf):
|
|
|
|
|
conf.sub_config('core')
|
2011-03-04 01:26:54 +00:00
|
|
|
conf.sub_config('emu')
|
|
|
|
|
conf.sub_config('tap-bridge')
|
2011-03-24 09:23:44 -07:00
|
|
|
conf.sub_config('config-store')
|
2011-02-25 10:32:35 -08:00
|
|
|
conf.sub_config('internet')
|
2011-03-05 10:51:26 -08:00
|
|
|
conf.sub_config('netanim')
|
2010-01-29 15:01:07 -08:00
|
|
|
conf.sub_config('test')
|
2011-03-04 01:26:54 +00:00
|
|
|
conf.sub_config('click')
|
2011-03-11 15:21:50 -05:00
|
|
|
conf.sub_config('openflow')
|
2007-05-07 12:01:51 +01:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
blddir = os.path.abspath(os.path.join(conf.blddir, conf.env.variant()))
|
2008-07-31 15:04:01 -07:00
|
|
|
conf.env.append_value('NS3_MODULE_PATH', blddir)
|
2008-12-29 13:28:54 +00:00
|
|
|
if Options.options.enable_rpath:
|
2007-08-28 16:53:01 +01:00
|
|
|
conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (os.path.join(blddir),))
|
2007-06-12 18:52:58 +01:00
|
|
|
|
2009-10-04 20:52:24 -07:00
|
|
|
## Used to link the 'test-runner' program with all of ns-3 code
|
2007-07-15 13:04:47 +01:00
|
|
|
conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules]
|
|
|
|
|
|
2007-11-20 18:27:43 +00:00
|
|
|
|
2007-08-08 15:10:36 +01:00
|
|
|
def create_ns3_module(bld, name, dependencies=()):
|
2011-03-18 10:58:21 -07:00
|
|
|
# Create a separate library for this module.
|
|
|
|
|
if bld.env['ENABLE_STATIC_NS3']:
|
|
|
|
|
module = bld.new_task_gen('cxx', 'cstaticlib')
|
|
|
|
|
else:
|
|
|
|
|
module = bld.new_task_gen('cxx', 'cshlib')
|
2010-10-25 21:27:03 +01:00
|
|
|
module.is_ns3_module = True
|
2007-08-08 15:10:36 +01:00
|
|
|
module.name = 'ns3-' + name
|
2011-03-18 10:58:21 -07:00
|
|
|
# Add the proper path to the module's name.
|
|
|
|
|
module.target = '%s/ns3-%s' % (bld.srcnode.relpath_gen(bld.path), name)
|
|
|
|
|
# Set the libraries this module depends on.
|
|
|
|
|
module.uselib_local = ['ns3-' + dep for dep in dependencies]
|
2008-03-15 16:13:18 +00:00
|
|
|
module.module_deps = list(dependencies)
|
2009-04-21 14:38:47 +02:00
|
|
|
if not module.env['ENABLE_STATIC_NS3']:
|
|
|
|
|
module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS'])
|
2010-02-18 15:37:51 +00:00
|
|
|
module.env.append_value('CCFLAGS', module.env['shlib_CXXFLAGS'])
|
2011-03-18 10:58:21 -07:00
|
|
|
# Turn on the link flags for shared libraries if we have the
|
|
|
|
|
# proper compiler and platform.
|
|
|
|
|
if module.env['CXX_NAME'] in ['gcc', 'icc'] and module.env['WL_SONAME_SUPPORTED']:
|
|
|
|
|
# Get the module library name without any relative paths
|
|
|
|
|
# at its beginning because all of the libraries will end
|
|
|
|
|
# up in the same directory.
|
|
|
|
|
module_library_name = os.path.basename(ccroot.get_target_name(module))
|
|
|
|
|
module.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % module_library_name)
|
2009-09-25 12:28:32 +01:00
|
|
|
elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \
|
2009-04-22 17:22:41 +02:00
|
|
|
os.uname()[4] == 'x86_64' and \
|
|
|
|
|
module.env['ENABLE_PYTHON_BINDINGS']:
|
|
|
|
|
# enable that flag for static builds only on x86-64 platforms
|
|
|
|
|
# when gcc is present and only when we want python bindings
|
|
|
|
|
# (it's more efficient to not use this option if we can avoid it)
|
|
|
|
|
module.env.append_value('CXXFLAGS', '-mcmodel=large')
|
2010-02-18 15:37:51 +00:00
|
|
|
module.env.append_value('CCFLAGS', '-mcmodel=large')
|
2009-04-22 17:22:41 +02:00
|
|
|
|
2008-03-15 16:13:18 +00:00
|
|
|
module.env.append_value('CXXDEFINES', "NS3_MODULE_COMPILATION")
|
2010-02-18 15:37:51 +00:00
|
|
|
module.env.append_value('CCDEFINES', "NS3_MODULE_COMPILATION")
|
2007-08-08 15:10:36 +01:00
|
|
|
return module
|
2008-12-29 13:28:54 +00:00
|
|
|
|
2011-03-18 10:58:21 -07:00
|
|
|
def create_ns3_module_test_library(bld, name):
|
|
|
|
|
# Create an ns3 module for the test library that depends only on
|
|
|
|
|
# the module being tested.
|
|
|
|
|
library_name = name + "-test"
|
|
|
|
|
library = bld.create_ns3_module(library_name, [name])
|
|
|
|
|
|
|
|
|
|
# Modify attributes for the test library that are different from a
|
|
|
|
|
# normal module.
|
|
|
|
|
del library.is_ns3_module
|
|
|
|
|
library.is_ns3_module_test_library = True
|
|
|
|
|
library.module_name = 'ns3-' + name
|
|
|
|
|
|
2011-03-21 11:26:56 -07:00
|
|
|
# Add this module and test library to the list.
|
|
|
|
|
bld.env.append_value('NS3_MODULES_WITH_TEST_LIBRARIES', (library.module_name, library.name))
|
2011-03-18 10:58:21 -07:00
|
|
|
|
|
|
|
|
# Set the include path from the build directory to modules.
|
|
|
|
|
relative_path_from_build_to_here = bld.path.relpath_gen(bld.bldnode)
|
|
|
|
|
include_flag = '-I' + relative_path_from_build_to_here
|
|
|
|
|
library.env.append_value('CXXFLAGS', include_flag)
|
|
|
|
|
library.env.append_value('CCFLAGS', include_flag)
|
|
|
|
|
|
|
|
|
|
return library
|
|
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
def create_obj(bld, *args):
|
|
|
|
|
warnings.warn("(in %s) Use bld.new_task_gen(...) now, instead of bld.create_obj(...)" % str(bld.path),
|
|
|
|
|
DeprecationWarning, stacklevel=2)
|
|
|
|
|
return bld.new_task_gen(*args)
|
2007-05-13 12:46:18 +01:00
|
|
|
|
2010-11-07 23:17:52 +00:00
|
|
|
|
|
|
|
|
def ns3_python_bindings(bld):
|
2011-03-22 15:56:41 +00:00
|
|
|
# this method is called from a module wscript, so remember bld.path is not bindings/python!
|
|
|
|
|
module_abs_src_path = bld.path.abspath()
|
|
|
|
|
module = os.path.basename(module_abs_src_path)
|
2010-11-07 23:17:52 +00:00
|
|
|
env = bld.env
|
2011-03-22 15:56:41 +00:00
|
|
|
env.append_value("MODULAR_BINDINGS_MODULES", "ns3-"+module)
|
|
|
|
|
|
2010-11-07 23:17:52 +00:00
|
|
|
if not env['ENABLE_PYTHON_BINDINGS']:
|
|
|
|
|
return
|
|
|
|
|
if env['BINDINGS_TYPE'] not in ('modular', 'both'):
|
|
|
|
|
return
|
|
|
|
|
|
2011-03-24 16:57:27 +00:00
|
|
|
bindings_dir = bld.path.find_dir("bindings")
|
|
|
|
|
if bindings_dir is None or not os.path.exists(bindings_dir.abspath()):
|
2011-03-08 15:02:28 +00:00
|
|
|
warnings.warn("(in %s) Requested to build modular python bindings, but apidefs dir not found "
|
|
|
|
|
"=> skipped the bindings." % str(bld.path),
|
|
|
|
|
Warning, stacklevel=2)
|
|
|
|
|
return
|
|
|
|
|
|
2011-03-20 14:18:56 +00:00
|
|
|
if ("ns3-%s" % (module,)) not in env.NS3_ENABLED_MODULES:
|
|
|
|
|
#print "bindings for module %s which is not enabled, skip" % module
|
|
|
|
|
return
|
|
|
|
|
|
2011-03-13 16:03:33 +00:00
|
|
|
env.append_value('PYTHON_MODULES_BUILT', module)
|
2010-11-07 23:17:52 +00:00
|
|
|
apidefs = env['PYTHON_BINDINGS_APIDEFS'].replace("-", "_")
|
|
|
|
|
|
|
|
|
|
#debug = ('PYBINDGEN_DEBUG' in os.environ)
|
|
|
|
|
debug = True # XXX
|
|
|
|
|
source = [bld.srcnode.find_resource('bindings/python/ns3modulegen-modular.py').relpath_gen(bld.path),
|
|
|
|
|
"bindings/modulegen__%s.py" % apidefs]
|
|
|
|
|
|
2011-03-27 22:50:00 +01:00
|
|
|
if bindings_dir.find_resource("modulegen_customizations.py") is not None:
|
|
|
|
|
source.append("bindings/modulegen_customizations.py")
|
|
|
|
|
|
2010-11-07 23:17:52 +00:00
|
|
|
# the local customization file may or not exist
|
|
|
|
|
if bld.path.find_resource("bindings/modulegen_local.py"):
|
|
|
|
|
source.append("bindings/modulegen_local.py")
|
|
|
|
|
|
2011-03-12 18:34:30 +00:00
|
|
|
target = ['bindings/ns3module.cc', 'bindings/ns3module.h', 'bindings/ns3modulegen.log']
|
2010-11-07 23:17:52 +00:00
|
|
|
#if not debug:
|
|
|
|
|
# target.append('ns3modulegen.log')
|
|
|
|
|
|
|
|
|
|
argv = ['NS3_ENABLED_FEATURES=${FEATURES}', '${PYTHON}']
|
|
|
|
|
#if debug:
|
|
|
|
|
# argv.extend(["-m", "pdb"])
|
|
|
|
|
|
2011-03-12 18:34:30 +00:00
|
|
|
argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, '${TGT[0]}'])
|
|
|
|
|
|
|
|
|
|
argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log
|
2010-11-07 23:17:52 +00:00
|
|
|
|
|
|
|
|
features = []
|
|
|
|
|
for (name, caption, was_enabled, reason_not_enabled) in env['NS3_OPTIONAL_FEATURES']:
|
|
|
|
|
if was_enabled:
|
|
|
|
|
features.append(name)
|
|
|
|
|
|
|
|
|
|
bindgen = bld.new_task_gen('command', source=source, target=target, command=argv)
|
|
|
|
|
bindgen.env['FEATURES'] = ','.join(features)
|
|
|
|
|
bindgen.dep_vars = ['FEATURES']
|
|
|
|
|
bindgen.before = 'cxx'
|
|
|
|
|
bindgen.after = 'gen_ns3_module_header_task'
|
|
|
|
|
bindgen.name = "pybindgen(ns3 module %s)" % module
|
|
|
|
|
|
|
|
|
|
pymod = bld.new_task_gen(features='cxx cshlib pyext')
|
2011-03-12 18:34:30 +00:00
|
|
|
pymod.source = ['bindings/ns3module.cc']
|
2011-03-13 18:38:59 +00:00
|
|
|
pymod.target = '%s/%s' % (bld.srcnode.find_dir("bindings/python/ns").relpath_gen(bld.path), module.replace('-', '_'))
|
2010-11-07 23:17:52 +00:00
|
|
|
pymod.name = 'ns3module_%s' % module
|
2011-03-22 16:23:36 +00:00
|
|
|
pymod.uselib_local = "ns3-"+module
|
2010-11-07 23:17:52 +00:00
|
|
|
if pymod.env['ENABLE_STATIC_NS3']:
|
|
|
|
|
if sys.platform == 'darwin':
|
|
|
|
|
pymod.env.append_value('LINKFLAGS', '-Wl,-all_load')
|
2011-03-18 10:58:21 -07:00
|
|
|
for mod in pymod.uselib_local:
|
|
|
|
|
pymod.env.append_value('LINKFLAGS', '-l' + mod)
|
2010-11-07 23:17:52 +00:00
|
|
|
else:
|
|
|
|
|
pymod.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
|
2011-03-18 10:58:21 -07:00
|
|
|
for mod in pymod.uselib_local:
|
|
|
|
|
pymod.env.append_value('LINKFLAGS', '-l' + mod)
|
2010-11-07 23:17:52 +00:00
|
|
|
pymod.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
|
|
|
|
|
defines = list(pymod.env['CXXDEFINES'])
|
|
|
|
|
defines.extend(['NS_DEPRECATED=', 'NS3_DEPRECATED_H'])
|
|
|
|
|
if Options.platform == 'win32':
|
|
|
|
|
try:
|
|
|
|
|
defines.remove('_DEBUG') # causes undefined symbols on win32
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
|
|
|
|
pymod.env['CXXDEFINES'] = defines
|
2011-03-12 18:34:30 +00:00
|
|
|
pymod.includes = 'bindings'
|
|
|
|
|
return pymod
|
2010-11-07 23:17:52 +00:00
|
|
|
|
|
|
|
|
|
2007-05-07 12:01:51 +01:00
|
|
|
def build(bld):
|
2007-08-08 15:10:36 +01:00
|
|
|
bld.create_ns3_module = types.MethodType(create_ns3_module, bld)
|
2011-03-18 10:58:21 -07:00
|
|
|
bld.create_ns3_module_test_library = types.MethodType(create_ns3_module_test_library, bld)
|
2008-12-29 13:28:54 +00:00
|
|
|
bld.create_obj = types.MethodType(create_obj, bld)
|
2010-11-07 23:17:52 +00:00
|
|
|
bld.ns3_python_bindings = types.MethodType(ns3_python_bindings, bld)
|
2007-05-13 12:46:18 +01:00
|
|
|
|
2007-07-24 16:13:31 +01:00
|
|
|
bld.add_subdirs(list(all_modules))
|
2007-05-24 17:54:51 +01:00
|
|
|
|
2008-03-15 16:13:18 +00:00
|
|
|
for module in all_modules:
|
2008-12-29 13:28:54 +00:00
|
|
|
modheader = bld.new_task_gen('ns3moduleheader')
|
2008-03-15 16:13:18 +00:00
|
|
|
modheader.module = module.split('/')[-1]
|
|
|
|
|
|
2007-08-08 21:07:52 +01:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
class ns3header_taskgen(TaskGen.task_gen):
|
2007-05-24 17:54:51 +01:00
|
|
|
"""A set of NS-3 header files"""
|
2008-12-29 13:28:54 +00:00
|
|
|
COLOR = 'BLUE'
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(ns3header_taskgen, self).__init__(*args, **kwargs)
|
|
|
|
|
self.install_path = None
|
2007-12-05 11:51:10 +00:00
|
|
|
self.sub_dir = None # if not None, header files will be published as ns3/sub_dir/file.h
|
2007-12-26 13:40:39 +00:00
|
|
|
self.module = None # module name
|
2010-10-26 15:11:17 +01:00
|
|
|
self.mode = 'install'
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2007-05-24 17:54:51 +01:00
|
|
|
def apply(self):
|
2007-12-26 13:40:39 +00:00
|
|
|
if self.module is None:
|
2008-12-29 13:28:54 +00:00
|
|
|
raise Utils.WafError("'module' missing on ns3headers object %s" % self)
|
2009-04-13 23:10:37 +01:00
|
|
|
ns3_dir_node = self.bld.path.find_dir("ns3")
|
2007-12-05 11:51:10 +00:00
|
|
|
if self.sub_dir is not None:
|
|
|
|
|
ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir)
|
2010-04-06 11:34:06 +04:00
|
|
|
for filename in set(self.to_list(self.source)):
|
2008-12-29 13:28:54 +00:00
|
|
|
src_node = self.path.find_resource(filename)
|
2007-05-24 17:54:51 +01:00
|
|
|
if src_node is None:
|
2008-12-29 13:28:54 +00:00
|
|
|
raise Utils.WafError("source ns3 header file %s not found" % (filename,))
|
|
|
|
|
dst_node = ns3_dir_node.find_or_declare(os.path.basename(filename))
|
2007-05-24 17:54:51 +01:00
|
|
|
assert dst_node is not None
|
2010-02-01 14:27:08 +00:00
|
|
|
task = self.create_task('ns3header', env=self.env)
|
2010-10-26 15:11:17 +01:00
|
|
|
task.mode = self.mode
|
|
|
|
|
if self.mode == 'install':
|
|
|
|
|
task.set_inputs([src_node])
|
|
|
|
|
task.set_outputs([dst_node])
|
|
|
|
|
else:
|
|
|
|
|
task.header_to_remove = dst_node
|
2007-05-24 17:54:51 +01:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
class ns3header_task(Task.Task):
|
2008-12-29 15:48:34 +00:00
|
|
|
before = 'cc cxx gen_ns3_module_header_task'
|
2008-12-29 13:28:54 +00:00
|
|
|
color = 'BLUE'
|
2010-10-26 15:11:17 +01:00
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
"string to display to the user"
|
|
|
|
|
env = self.env
|
|
|
|
|
src_str = ' '.join([a.nice_path(env) for a in self.inputs])
|
|
|
|
|
tgt_str = ' '.join([a.nice_path(env) for a in self.outputs])
|
|
|
|
|
if self.outputs: sep = ' -> '
|
|
|
|
|
else: sep = ''
|
|
|
|
|
if self.mode == 'remove':
|
|
|
|
|
return 'rm-ns3-header %s\n' % (self.header_to_remove.bldpath(self.env),)
|
|
|
|
|
return 'install-ns3-header: %s%s%s\n' % (src_str, sep, tgt_str)
|
|
|
|
|
|
|
|
|
|
def runnable_status(self):
|
|
|
|
|
if self.mode == 'remove':
|
|
|
|
|
if os.path.exists(self.header_to_remove.bldpath(self.env)):
|
|
|
|
|
return Constants.RUN_ME
|
|
|
|
|
else:
|
|
|
|
|
return Constants.SKIP_ME
|
|
|
|
|
else:
|
|
|
|
|
return super(ns3header_task, self).runnable_status()
|
|
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
def run(self):
|
2010-10-26 15:11:17 +01:00
|
|
|
if self.mode == 'install':
|
|
|
|
|
assert len(self.inputs) == len(self.outputs)
|
|
|
|
|
inputs = [node.srcpath(self.env) for node in self.inputs]
|
|
|
|
|
outputs = [node.bldpath(self.env) for node in self.outputs]
|
|
|
|
|
for src, dst in zip(inputs, outputs):
|
|
|
|
|
try:
|
|
|
|
|
os.chmod(dst, 0600)
|
|
|
|
|
except OSError:
|
|
|
|
|
pass
|
|
|
|
|
shutil.copy2(src, dst)
|
|
|
|
|
## make the headers in builddir read-only, to prevent
|
|
|
|
|
## accidental modification
|
|
|
|
|
os.chmod(dst, 0400)
|
|
|
|
|
return 0
|
|
|
|
|
else:
|
|
|
|
|
assert len(self.inputs) == 0
|
|
|
|
|
assert len(self.outputs) == 0
|
|
|
|
|
out_file_name = self.header_to_remove.bldpath(self.env)
|
2008-12-29 13:28:54 +00:00
|
|
|
try:
|
2010-10-26 15:11:17 +01:00
|
|
|
os.unlink(out_file_name)
|
|
|
|
|
except OSError, ex:
|
|
|
|
|
if ex.errno != 2:
|
|
|
|
|
raise
|
|
|
|
|
return 0
|
|
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class gen_ns3_module_header_task(Task.Task):
|
|
|
|
|
before = 'cc cxx'
|
2008-12-29 15:48:34 +00:00
|
|
|
after = 'ns3header_task'
|
2008-12-29 13:28:54 +00:00
|
|
|
color = 'BLUE'
|
2010-10-26 15:11:17 +01:00
|
|
|
|
|
|
|
|
def runnable_status(self):
|
|
|
|
|
if self.mode == 'remove':
|
|
|
|
|
if os.path.exists(self.header_to_remove.bldpath(self.env)):
|
|
|
|
|
return Constants.RUN_ME
|
|
|
|
|
else:
|
|
|
|
|
return Constants.SKIP_ME
|
|
|
|
|
else:
|
|
|
|
|
return super(gen_ns3_module_header_task, self).runnable_status()
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
"string to display to the user"
|
|
|
|
|
env = self.env
|
|
|
|
|
src_str = ' '.join([a.nice_path(env) for a in self.inputs])
|
|
|
|
|
tgt_str = ' '.join([a.nice_path(env) for a in self.outputs])
|
|
|
|
|
if self.outputs: sep = ' -> '
|
|
|
|
|
else: sep = ''
|
|
|
|
|
if self.mode == 'remove':
|
|
|
|
|
return 'rm-module-header %s\n' % (self.header_to_remove.bldpath(self.env),)
|
|
|
|
|
return 'gen-module-header: %s%s%s\n' % (src_str, sep, tgt_str)
|
|
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
def run(self):
|
2010-10-26 15:11:17 +01:00
|
|
|
if self.mode == 'remove':
|
|
|
|
|
assert len(self.inputs) == 0
|
|
|
|
|
assert len(self.outputs) == 0
|
|
|
|
|
out_file_name = self.header_to_remove.bldpath(self.env)
|
|
|
|
|
try:
|
|
|
|
|
os.unlink(out_file_name)
|
|
|
|
|
except OSError, ex:
|
|
|
|
|
if ex.errno != 2:
|
|
|
|
|
raise
|
|
|
|
|
return 0
|
|
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
assert len(self.outputs) == 1
|
2010-10-26 15:11:17 +01:00
|
|
|
out_file_name = self.outputs[0].bldpath(self.env)
|
2008-12-29 13:28:54 +00:00
|
|
|
header_files = [os.path.basename(node.abspath(self.env)) for node in self.inputs]
|
2010-10-26 15:11:17 +01:00
|
|
|
outfile = file(out_file_name, "w")
|
2008-12-29 13:28:54 +00:00
|
|
|
header_files.sort()
|
|
|
|
|
|
|
|
|
|
print >> outfile, """
|
2008-03-15 16:13:18 +00:00
|
|
|
#ifdef NS3_MODULE_COMPILATION
|
|
|
|
|
# error "Do not include ns3 module aggregator headers from other modules; these are meant only for end user scripts."
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef NS3_MODULE_%s
|
2008-12-29 13:28:54 +00:00
|
|
|
""" % (self.module.upper().replace('-', '_'),)
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
# if self.module_deps:
|
|
|
|
|
# print >> outfile, "// Module dependencies:"
|
|
|
|
|
# for dep in self.module_deps:
|
|
|
|
|
# print >> outfile, "#include \"%s-module.h\"" % dep
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
print >> outfile
|
|
|
|
|
print >> outfile, "// Module headers:"
|
|
|
|
|
for header in header_files:
|
|
|
|
|
print >> outfile, "#include \"%s\"" % (header,)
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
print >> outfile, "#endif"
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
outfile.close()
|
|
|
|
|
return 0
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2009-01-25 21:57:24 +00:00
|
|
|
def sig_explicit_deps(self):
|
2010-11-27 14:29:45 +00:00
|
|
|
self.m.update('\n'.join([node.abspath(self.env) for node in self.inputs]))
|
|
|
|
|
return self.m.digest()
|
2009-01-25 21:57:24 +00:00
|
|
|
|
|
|
|
|
def unique_id(self):
|
|
|
|
|
try:
|
|
|
|
|
return self.uid
|
|
|
|
|
except AttributeError:
|
|
|
|
|
"this is not a real hot zone, but we want to avoid surprizes here"
|
2009-04-13 23:10:37 +01:00
|
|
|
m = Utils.md5()
|
2009-01-25 21:57:24 +00:00
|
|
|
m.update("ns-3-module-header-%s" % self.module)
|
|
|
|
|
self.uid = m.digest()
|
|
|
|
|
return self.uid
|
|
|
|
|
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
class ns3moduleheader_taskgen(TaskGen.task_gen):
|
2008-03-15 16:13:18 +00:00
|
|
|
"""
|
|
|
|
|
Generates a 'ns3/foo-module.h' header file that includes all
|
|
|
|
|
public ns3 headers of a certain module.
|
|
|
|
|
"""
|
2008-12-29 13:28:54 +00:00
|
|
|
COLOR = 'BLUE'
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
|
super(ns3moduleheader_taskgen, self).__init__(*args, **kwargs)
|
2010-10-26 15:11:17 +01:00
|
|
|
self.mode = 'install'
|
2008-03-15 16:13:18 +00:00
|
|
|
|
|
|
|
|
def apply(self):
|
|
|
|
|
## get all of the ns3 headers
|
2009-04-13 23:10:37 +01:00
|
|
|
ns3_dir_node = self.bld.path.find_dir("ns3")
|
2008-03-15 16:13:18 +00:00
|
|
|
all_headers_inputs = []
|
2009-09-02 17:43:28 +01:00
|
|
|
found_the_module = False
|
2009-04-13 23:10:37 +01:00
|
|
|
for ns3headers in self.bld.all_task_gen:
|
2008-04-26 21:54:36 +01:00
|
|
|
if isinstance(ns3headers, ns3header_taskgen):
|
2008-03-15 16:13:18 +00:00
|
|
|
if ns3headers.module != self.module:
|
|
|
|
|
continue
|
2009-09-02 17:43:28 +01:00
|
|
|
found_the_module = True
|
2010-04-06 11:34:06 +04:00
|
|
|
for source in set(ns3headers.to_list(ns3headers.source)):
|
2008-03-15 16:13:18 +00:00
|
|
|
source = os.path.basename(source)
|
2008-12-29 13:28:54 +00:00
|
|
|
node = ns3_dir_node.find_or_declare(os.path.basename(source))
|
2008-03-15 16:13:18 +00:00
|
|
|
if node is None:
|
|
|
|
|
fatal("missing header file %s" % (source,))
|
|
|
|
|
all_headers_inputs.append(node)
|
2009-09-02 17:43:28 +01:00
|
|
|
if not found_the_module:
|
2009-04-13 23:10:37 +01:00
|
|
|
raise Utils.WscriptError("error finding headers for module %s" % self.module)
|
2009-09-02 17:43:28 +01:00
|
|
|
if not all_headers_inputs:
|
|
|
|
|
return
|
2008-12-29 13:28:54 +00:00
|
|
|
all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)]
|
2010-02-01 14:27:08 +00:00
|
|
|
task = self.create_task('gen_ns3_module_header', env=self.env)
|
2008-03-15 16:13:18 +00:00
|
|
|
task.module = self.module
|
2010-10-26 15:11:17 +01:00
|
|
|
task.mode = self.mode
|
|
|
|
|
if self.mode == 'install':
|
|
|
|
|
task.set_inputs(all_headers_inputs)
|
|
|
|
|
task.set_outputs(all_headers_outputs)
|
|
|
|
|
module_obj = self.bld.name_to_obj("ns3-" + self.module, self.env)
|
|
|
|
|
assert module_obj is not None, self.module
|
|
|
|
|
task.module_deps = module_obj.module_deps
|
|
|
|
|
else:
|
|
|
|
|
task.header_to_remove = all_headers_outputs[0]
|
2008-03-15 16:13:18 +00:00
|
|
|
|
|
|
|
|
def install(self):
|
|
|
|
|
pass
|