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
|
2011-05-27 14:48:14 -07:00
|
|
|
import sys
|
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
|
|
|
|
2011-09-12 14:54:27 +01:00
|
|
|
from waflib.Errors import WafError
|
|
|
|
|
|
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
|
2011-03-18 10:58:21 -07:00
|
|
|
|
2011-06-26 13:40:27 +01:00
|
|
|
import wutils
|
|
|
|
|
|
2010-04-06 11:34:06 +04:00
|
|
|
try:
|
|
|
|
|
set
|
|
|
|
|
except NameError:
|
|
|
|
|
from sets import Set as set # Python 2.3 fallback
|
|
|
|
|
|
2007-05-13 12:46:18 +01:00
|
|
|
|
2011-09-13 17:50:05 +01:00
|
|
|
all_modules = []
|
|
|
|
|
for dirname in os.listdir('src'):
|
|
|
|
|
if dirname.startswith('.') or dir == 'CVS':
|
|
|
|
|
continue
|
|
|
|
|
path = os.path.join('src', dirname)
|
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
|
continue
|
|
|
|
|
if os.path.exists(os.path.join(path, 'wscript')):
|
|
|
|
|
all_modules.append(dirname)
|
|
|
|
|
all_modules.sort()
|
|
|
|
|
|
2007-07-20 11:38:16 +01:00
|
|
|
|
2011-09-13 17:50:05 +01:00
|
|
|
|
|
|
|
|
def options(opt):
|
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')
|
|
|
|
|
|
2011-09-13 17:50:05 +01:00
|
|
|
for module in all_modules:
|
|
|
|
|
opt.sub_options(module, mandatory=False)
|
|
|
|
|
|
|
|
|
|
|
2007-05-07 12:01:51 +01:00
|
|
|
def configure(conf):
|
2011-09-13 17:50:05 +01:00
|
|
|
for module in all_modules:
|
|
|
|
|
conf.sub_config(module, mandatory=False)
|
2007-05-07 12:01:51 +01:00
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
blddir = os.path.abspath(os.path.join(conf.bldnode.abspath(), conf.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
|
|
|
|
2011-07-03 12:01:29 +01:00
|
|
|
|
2011-09-12 19:04:36 +01:00
|
|
|
# we need the 'ns3module' waf "feature" to be created because code
|
|
|
|
|
# elsewhere looks for it to find the ns3 module objects.
|
2011-09-12 14:54:27 +01:00
|
|
|
@TaskGen.feature('ns3module')
|
|
|
|
|
def _add_test_code(module):
|
2011-09-12 19:04:36 +01:00
|
|
|
pass
|
2011-09-12 14:54:27 +01:00
|
|
|
|
2011-07-03 12:01:29 +01:00
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
def create_ns3_module(bld, name, dependencies=(), test=False):
|
|
|
|
|
static = bool(bld.env.ENABLE_STATIC_NS3)
|
|
|
|
|
# Create a separate library for this module.
|
|
|
|
|
if static:
|
2011-09-12 14:54:27 +01:00
|
|
|
module = bld.new_task_gen(features=['cxx', 'cxxstlib', 'ns3module'])
|
2011-09-08 16:13:40 +01:00
|
|
|
else:
|
2011-09-12 14:54:27 +01:00
|
|
|
module = bld.new_task_gen(features=['cxx', 'cxxshlib', 'ns3module'])
|
2011-09-12 16:19:24 +01:00
|
|
|
module.target = '%s/ns3-%s' % (bld.srcnode.relpath_gen(module.path), name)
|
2011-09-08 16:13:40 +01:00
|
|
|
linkflags = []
|
|
|
|
|
cxxflags = []
|
|
|
|
|
ccflags = []
|
|
|
|
|
if not static:
|
|
|
|
|
cxxflags = module.env['shlib_CXXFLAGS']
|
|
|
|
|
ccflags = module.env['shlib_CXXFLAGS']
|
|
|
|
|
# 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.
|
2011-09-12 16:19:24 +01:00
|
|
|
module_library_name = module.env.cshlib_PATTERN % (os.path.basename(module.target),)
|
|
|
|
|
linkflags = '-Wl,--soname=' + module_library_name
|
2011-09-08 16:13:40 +01:00
|
|
|
elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \
|
|
|
|
|
os.uname()[4] == 'x86_64' and \
|
|
|
|
|
sys.platform != 'darwin' 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)
|
|
|
|
|
cxxflags = ['-mcmodel=large']
|
|
|
|
|
ccflags = ['-mcmodel=large']
|
|
|
|
|
cxxdefines = ["NS3_MODULE_COMPILATION"]
|
|
|
|
|
ccdefines = ["NS3_MODULE_COMPILATION"]
|
|
|
|
|
|
|
|
|
|
module.env.append_value('CXXFLAGS', cxxflags)
|
|
|
|
|
module.env.append_value('CCFLAGS', ccflags)
|
|
|
|
|
module.env.append_value('LINKFLAGS', linkflags)
|
|
|
|
|
module.env.append_value('CXXDEFINES', cxxdefines)
|
|
|
|
|
module.env.append_value('CCDEFINES', ccdefines)
|
|
|
|
|
|
|
|
|
|
module.is_static = static
|
|
|
|
|
module.vnum = wutils.VNUM
|
|
|
|
|
# Add the proper path to the module's name.
|
|
|
|
|
# Set the libraries this module depends on.
|
|
|
|
|
module.module_deps = list(dependencies)
|
2011-07-03 12:01:29 +01:00
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
module.install_path = "${LIBDIR}"
|
2011-07-03 12:01:29 +01:00
|
|
|
|
|
|
|
|
module.name = "ns3-" + name
|
|
|
|
|
module.dependencies = dependencies
|
2011-04-12 10:39:17 -07:00
|
|
|
# Initially create an empty value for this because the pcfile
|
|
|
|
|
# writing task assumes every module has a uselib attribute.
|
|
|
|
|
module.uselib = ''
|
2011-09-08 16:13:40 +01:00
|
|
|
module.use = ['ns3-' + dep for dep in dependencies]
|
2011-07-03 12:01:29 +01:00
|
|
|
module.test = test
|
|
|
|
|
module.is_ns3_module = True
|
2011-07-29 03:38:59 -04:00
|
|
|
module.ns3_dir_location = bld.path.relpath_gen(bld.srcnode)
|
2011-07-03 12:01:29 +01:00
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
module.env.append_value("INCLUDES", '#')
|
2011-09-20 11:58:53 +01:00
|
|
|
|
|
|
|
|
pcfilegen = bld(features='ns3pcfile')
|
|
|
|
|
pcfilegen.module = module
|
2011-09-12 14:54:27 +01:00
|
|
|
|
2007-08-08 15:10:36 +01:00
|
|
|
return module
|
2008-12-29 13:28:54 +00:00
|
|
|
|
2011-09-12 14:54:27 +01:00
|
|
|
@TaskGen.feature("ns3testlib")
|
|
|
|
|
@TaskGen.before_method("apply_incpaths")
|
|
|
|
|
def apply_incpaths_ns3testlib(self):
|
|
|
|
|
if not self.source:
|
|
|
|
|
return
|
|
|
|
|
testdir = self.source[-1].parent.relpath_gen(self.bld.srcnode)
|
|
|
|
|
self.env.append_value("DEFINES", 'NS_TEST_SOURCEDIR="%s"' % (testdir,))
|
|
|
|
|
|
2011-07-03 12:01:29 +01: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"
|
2011-09-12 14:54:27 +01:00
|
|
|
library = bld.create_ns3_module(library_name, [name], test=True)
|
|
|
|
|
library.features.append("ns3testlib")
|
2011-03-18 10:58:21 -07:00
|
|
|
|
|
|
|
|
# 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.
|
2011-09-12 14:54:27 +01:00
|
|
|
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-09-12 18:54:57 +01:00
|
|
|
if Options.options.apiscan:
|
|
|
|
|
return
|
|
|
|
|
|
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
|
|
|
|
|
|
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-27 23:35:55 +01:00
|
|
|
module_py_name = module.replace('-', '_')
|
|
|
|
|
module_target_dir = bld.srcnode.find_dir("bindings/python/ns").relpath_gen(bld.path)
|
|
|
|
|
|
|
|
|
|
# if bindings/<module>.py exists, it becomes the module frontend, and the C extension befomes _<module>
|
|
|
|
|
if bld.path.find_resource("bindings/%s.py" % (module_py_name,)) is not None:
|
|
|
|
|
bld.new_task_gen(
|
|
|
|
|
features='copy',
|
|
|
|
|
source=("bindings/%s.py" % (module_py_name,)),
|
|
|
|
|
target=('%s/%s.py' % (module_target_dir, module_py_name)))
|
|
|
|
|
extension_name = '_%s' % (module_py_name,)
|
2011-07-05 19:25:18 +01:00
|
|
|
bld.install_files('${PYTHONDIR}/ns', ["bindings/%s.py" % (module_py_name,)])
|
2011-03-27 23:35:55 +01:00
|
|
|
else:
|
|
|
|
|
extension_name = module_py_name
|
|
|
|
|
|
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')
|
|
|
|
|
|
2011-08-07 16:52:49 +01:00
|
|
|
argv = ['NS3_ENABLED_FEATURES=${FEATURES}',
|
|
|
|
|
'GCC_RTTI_ABI_COMPLETE=${GCC_RTTI_ABI_COMPLETE}',
|
|
|
|
|
'${PYTHON}']
|
2010-11-07 23:17:52 +00:00
|
|
|
#if debug:
|
|
|
|
|
# argv.extend(["-m", "pdb"])
|
|
|
|
|
|
2011-03-27 23:35:55 +01:00
|
|
|
argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, extension_name, '${TGT[0]}'])
|
2011-03-12 18:34:30 +00:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
bindgen = bld.new_task_gen(features=['command'], source=source, target=target, command=argv)
|
2010-11-07 23:17:52 +00:00
|
|
|
bindgen.env['FEATURES'] = ','.join(features)
|
2011-08-07 16:52:49 +01:00
|
|
|
bindgen.dep_vars = ['FEATURES', "GCC_RTTI_ABI_COMPLETE"]
|
2010-11-07 23:17:52 +00:00
|
|
|
bindgen.before = 'cxx'
|
2011-09-08 16:13:40 +01:00
|
|
|
bindgen.after = 'gen_ns3_module_header'
|
2010-11-07 23:17:52 +00:00
|
|
|
bindgen.name = "pybindgen(ns3 module %s)" % module
|
|
|
|
|
|
2011-03-27 23:35:55 +01:00
|
|
|
# generate the extension module
|
2011-09-08 16:13:40 +01:00
|
|
|
pymod = bld.new_task_gen(features='cxx cxxshlib pyext')
|
2011-03-12 18:34:30 +00:00
|
|
|
pymod.source = ['bindings/ns3module.cc']
|
2011-03-27 23:35:55 +01:00
|
|
|
pymod.target = '%s/%s' % (module_target_dir, extension_name)
|
2010-11-07 23:17:52 +00:00
|
|
|
pymod.name = 'ns3module_%s' % module
|
2011-09-08 16:13:40 +01:00
|
|
|
pymod.use = ["%s" % mod for mod in pymod.env['NS3_ENABLED_MODULES']] # Should be '"ns3-"+module', but see bug 1117
|
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-09-08 16:13:40 +01:00
|
|
|
for mod in pymod.usel:
|
|
|
|
|
#mod = mod.split("--lib")[0]
|
2011-03-18 10:58:21 -07:00
|
|
|
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-09-08 16:13:40 +01:00
|
|
|
for mod in pymod.use:
|
|
|
|
|
#mod = mod.split("--lib")[0]
|
2011-03-18 10:58:21 -07:00
|
|
|
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')
|
2011-09-13 13:47:17 +01:00
|
|
|
defines = list(pymod.env['DEFINES'])
|
2010-11-07 23:17:52 +00:00
|
|
|
defines.extend(['NS_DEPRECATED=', 'NS3_DEPRECATED_H'])
|
|
|
|
|
if Options.platform == 'win32':
|
|
|
|
|
try:
|
|
|
|
|
defines.remove('_DEBUG') # causes undefined symbols on win32
|
|
|
|
|
except ValueError:
|
|
|
|
|
pass
|
2011-09-13 13:47:17 +01:00
|
|
|
pymod.env['DEFINES'] = defines
|
2011-09-08 16:13:40 +01:00
|
|
|
pymod.includes = '# bindings'
|
2011-07-05 19:16:47 +01:00
|
|
|
pymod.install_path = '${PYTHONDIR}/ns'
|
2011-03-12 18:34:30 +00:00
|
|
|
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
|
|
|
|
2011-05-30 15:30:49 -07:00
|
|
|
# Remove these modules from the list of all modules.
|
|
|
|
|
for not_built in bld.env['MODULES_NOT_BUILT']:
|
2011-06-03 10:54:07 -07:00
|
|
|
|
|
|
|
|
# XXX Becaue these modules are located in subdirectories of
|
|
|
|
|
# test, their names in the all_modules list include the extra
|
|
|
|
|
# relative path "test/". If these modules are moved into the
|
|
|
|
|
# src directory, then this if block should be removed.
|
|
|
|
|
if not_built == 'ns3tcp' or not_built == 'ns3wifi':
|
|
|
|
|
not_built = 'test/' + not_built
|
|
|
|
|
|
2011-05-30 15:30:49 -07:00
|
|
|
if not_built in all_modules:
|
|
|
|
|
all_modules.remove(not_built)
|
2011-05-27 14:48:14 -07: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:
|
2011-09-08 16:13:40 +01:00
|
|
|
modheader = bld.new_task_gen(features=['ns3moduleheader'])
|
2008-03-15 16:13:18 +00:00
|
|
|
modheader.module = module.split('/')[-1]
|
|
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
class ns3pcfile_task(Task.Task):
|
|
|
|
|
after = 'cc cxx'
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def __str__(self):
|
|
|
|
|
"string to display to the user"
|
|
|
|
|
tgt_str = ' '.join([a.nice_path(self.env) for a in self.outputs])
|
|
|
|
|
return 'pcfile: %s\n' % (tgt_str)
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def runnable_status(self):
|
|
|
|
|
return super(ns3pcfile_task, self).runnable_status()
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def _self_libs(self, env, name, libdir):
|
|
|
|
|
if env['ENABLE_STATIC_NS3']:
|
2011-09-20 21:16:08 +01:00
|
|
|
path_st = 'STLIBPATH_ST'
|
|
|
|
|
lib_st = 'STLIB_ST'
|
|
|
|
|
lib_marker = 'STLIB_MARKER'
|
2011-04-11 15:19:44 +02:00
|
|
|
else:
|
|
|
|
|
path_st = 'LIBPATH_ST'
|
|
|
|
|
lib_st = 'LIB_ST'
|
|
|
|
|
lib_marker = 'SHLIB_MARKER'
|
2011-04-19 14:39:15 +02:00
|
|
|
retval = [env[path_st] % libdir,
|
|
|
|
|
env[lib_marker],
|
|
|
|
|
env[lib_st] % name]
|
|
|
|
|
return retval
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def _lib(self, env, dep):
|
|
|
|
|
libpath = env['LIBPATH_%s' % dep]
|
|
|
|
|
linkflags = env['LINKFLAGS_%s' % dep]
|
|
|
|
|
libs = env['LIB_%s' % dep]
|
|
|
|
|
retval = []
|
|
|
|
|
for path in libpath:
|
|
|
|
|
retval.append(env['LIBPATH_ST'] % path)
|
|
|
|
|
retval = retval + linkflags
|
|
|
|
|
for lib in libs:
|
|
|
|
|
retval.append(env['LIB_ST'] % lib)
|
|
|
|
|
return retval
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def _listify(self, v):
|
|
|
|
|
if isinstance(v, list):
|
|
|
|
|
return v
|
|
|
|
|
else:
|
|
|
|
|
return [v]
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def _cflags(self, dep):
|
|
|
|
|
flags = self.env['CFLAGS_%s' % dep]
|
|
|
|
|
return self._listify(flags)
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def _cxxflags(self, dep):
|
|
|
|
|
return self._listify(self.env['CXXFLAGS_%s' % dep])
|
2011-09-20 14:09:37 +01:00
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def _defines(self, dep):
|
2011-09-20 14:09:37 +01:00
|
|
|
return [self.env['DEFINES_ST'] % define for define in self.env['DEFINES_%s' % dep]]
|
|
|
|
|
|
2011-04-11 15:19:44 +02:00
|
|
|
def _includes(self, dep):
|
2011-09-20 14:09:37 +01:00
|
|
|
includes = self.env['INCLUDES_%s' % dep]
|
2011-04-11 15:19:44 +02:00
|
|
|
return [self.env['CPPPATH_ST'] % include for include in includes]
|
|
|
|
|
|
2011-09-20 14:09:37 +01:00
|
|
|
def _generate_pcfile(self, name, use, env, outfilename):
|
|
|
|
|
outfile = open(outfilename, 'wt')
|
2011-07-05 18:30:43 +01:00
|
|
|
prefix = env.PREFIX
|
2011-07-29 03:38:59 -04:00
|
|
|
includedir = env.INCLUDEDIR
|
2011-07-05 18:30:43 +01:00
|
|
|
libdir = env.LIBDIR
|
2011-09-20 14:09:37 +01:00
|
|
|
libs = self._self_libs(env, name, '${libdir}')
|
2011-04-11 15:19:44 +02:00
|
|
|
for dep in use:
|
2011-09-20 14:09:37 +01:00
|
|
|
libs += self._lib(env, dep)
|
|
|
|
|
for dep in env.LIBS:
|
|
|
|
|
libs += self.env['LIB_ST'] % dep
|
2011-04-11 15:19:44 +02:00
|
|
|
cflags = [self.env['CPPPATH_ST'] % '${includedir}']
|
2011-09-20 15:11:17 +01:00
|
|
|
requires = []
|
2011-04-11 15:19:44 +02:00
|
|
|
for dep in use:
|
|
|
|
|
cflags = cflags + self._cflags(dep) + self._cxxflags(dep) + \
|
|
|
|
|
self._defines(dep) + self._includes(dep)
|
2011-09-20 15:11:17 +01:00
|
|
|
if dep.startswith('ns3-'):
|
|
|
|
|
requires.append("lib"+dep)
|
2011-04-11 15:19:44 +02:00
|
|
|
print >> outfile, """
|
|
|
|
|
prefix=%s
|
|
|
|
|
libdir=%s
|
|
|
|
|
includedir=%s
|
|
|
|
|
|
|
|
|
|
Name: lib%s
|
|
|
|
|
Description: ns-3 module %s
|
|
|
|
|
Version: devel
|
|
|
|
|
Libs: %s
|
|
|
|
|
Cflags: %s
|
2011-09-20 15:11:17 +01:00
|
|
|
Requires: %s
|
2011-04-11 15:19:44 +02:00
|
|
|
""" % (prefix, libdir, includedir,
|
2011-09-20 15:11:17 +01:00
|
|
|
name, name, ' '.join(libs), ' '.join(cflags), ' '.join(requires))
|
2011-04-11 15:19:44 +02:00
|
|
|
outfile.close()
|
|
|
|
|
|
|
|
|
|
def run(self):
|
2011-09-20 11:58:53 +01:00
|
|
|
output_filename = self.outputs[0].abspath()
|
2011-09-21 09:32:06 -07:00
|
|
|
self._generate_pcfile(self.module.name[0],
|
2011-09-20 14:09:37 +01:00
|
|
|
self.module.to_list(self.module.use),
|
2011-07-05 18:30:43 +01:00
|
|
|
self.env, output_filename)
|
2011-04-11 15:19:44 +02:00
|
|
|
|
2011-09-20 11:58:53 +01:00
|
|
|
|
|
|
|
|
@TaskGen.feature('ns3pcfile')
|
|
|
|
|
@TaskGen.after_method('process_rule')
|
|
|
|
|
def apply(self):
|
|
|
|
|
output_filename = 'lib%s.pc' % self.module.name
|
|
|
|
|
output_node = self.path.find_or_declare(output_filename)
|
|
|
|
|
assert output_node is not None, str(self)
|
|
|
|
|
task = self.create_task('ns3pcfile')
|
|
|
|
|
self.bld.install_files('${LIBDIR}/pkgconfig', output_node)
|
|
|
|
|
task.set_outputs([output_node])
|
|
|
|
|
task.module = self.module
|
2011-04-11 15:19:44 +02:00
|
|
|
|
2007-08-08 21:07:52 +01:00
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
|
|
|
|
|
@TaskGen.feature('ns3header')
|
|
|
|
|
@TaskGen.after_method('process_rule')
|
|
|
|
|
def apply_ns3header(self):
|
|
|
|
|
if self.module is None:
|
2011-09-13 17:50:05 +01:00
|
|
|
raise WafError("'module' missing on ns3headers object %s" % self)
|
2011-09-08 16:13:40 +01:00
|
|
|
ns3_dir_node = self.bld.path.find_dir("ns3")
|
|
|
|
|
for filename in set(self.to_list(self.source)):
|
|
|
|
|
src_node = self.path.find_resource(filename)
|
|
|
|
|
if src_node is None:
|
2011-09-13 17:50:05 +01:00
|
|
|
raise WafError("source ns3 header file %s not found" % (filename,))
|
2011-09-08 16:13:40 +01:00
|
|
|
dst_node = ns3_dir_node.find_or_declare(src_node.name)
|
|
|
|
|
assert dst_node is not None
|
|
|
|
|
task = self.create_task('ns3header')
|
|
|
|
|
task.mode = getattr(self, 'mode', 'install')
|
|
|
|
|
if task.mode == 'install':
|
|
|
|
|
self.bld.install_files('${PREFIX}/include/ns3', [src_node])
|
|
|
|
|
task.set_inputs([src_node])
|
|
|
|
|
task.set_outputs([dst_node])
|
|
|
|
|
else:
|
|
|
|
|
task.header_to_remove = dst_node
|
|
|
|
|
self.headers = set(self.to_list(self.source))
|
|
|
|
|
self.source = '' # tell WAF not to process these files further
|
2007-05-24 17:54:51 +01:00
|
|
|
|
2011-09-12 19:04:36 +01:00
|
|
|
|
2008-12-29 13:28:54 +00:00
|
|
|
class ns3header_task(Task.Task):
|
2011-09-08 16:13:40 +01:00
|
|
|
before = 'cc cxx gen_ns3_module_header'
|
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':
|
2011-09-12 14:54:27 +01:00
|
|
|
return 'rm-ns3-header %s\n' % (self.header_to_remove.abspath(),)
|
2010-10-26 15:11:17 +01:00
|
|
|
return 'install-ns3-header: %s%s%s\n' % (src_str, sep, tgt_str)
|
|
|
|
|
|
2011-09-12 14:54:27 +01:00
|
|
|
def __repr__(self):
|
|
|
|
|
return str(self)
|
|
|
|
|
|
|
|
|
|
def uid(self):
|
|
|
|
|
try:
|
|
|
|
|
return self.uid_
|
|
|
|
|
except AttributeError:
|
|
|
|
|
m = Utils.md5()
|
|
|
|
|
up = m.update
|
|
|
|
|
up(self.__class__.__name__.encode())
|
|
|
|
|
for x in self.inputs + self.outputs:
|
|
|
|
|
up(x.abspath().encode())
|
|
|
|
|
up(self.mode)
|
|
|
|
|
if self.mode == 'remove':
|
|
|
|
|
up(self.header_to_remove.abspath().encode())
|
|
|
|
|
self.uid_ = m.digest()
|
|
|
|
|
return self.uid_
|
|
|
|
|
|
2010-10-26 15:11:17 +01:00
|
|
|
def runnable_status(self):
|
|
|
|
|
if self.mode == 'remove':
|
2011-09-12 14:54:27 +01:00
|
|
|
if os.path.exists(self.header_to_remove.abspath()):
|
2011-09-08 16:13:40 +01:00
|
|
|
return Task.RUN_ME
|
2010-10-26 15:11:17 +01:00
|
|
|
else:
|
2011-09-08 16:13:40 +01:00
|
|
|
return Task.SKIP_ME
|
2010-10-26 15:11:17 +01:00
|
|
|
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)
|
2011-09-08 16:13:40 +01:00
|
|
|
inputs = [node.abspath() for node in self.inputs]
|
|
|
|
|
outputs = [node.abspath() for node in self.outputs]
|
2010-10-26 15:11:17 +01:00
|
|
|
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
|
2011-09-12 14:54:27 +01:00
|
|
|
out_file_name = self.header_to_remove.abspath()
|
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'
|
2011-09-08 16:13:40 +01:00
|
|
|
after = 'ns3header'
|
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':
|
2011-09-12 14:54:27 +01:00
|
|
|
if os.path.exists(self.header_to_remove.abspath()):
|
2011-09-08 16:13:40 +01:00
|
|
|
return Task.RUN_ME
|
2010-10-26 15:11:17 +01:00
|
|
|
else:
|
2011-09-08 16:13:40 +01:00
|
|
|
return Task.SKIP_ME
|
2010-10-26 15:11:17 +01:00
|
|
|
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':
|
2011-09-12 14:54:27 +01:00
|
|
|
return 'rm-module-header %s\n' % (self.header_to_remove.abspath(),)
|
2010-10-26 15:11:17 +01:00
|
|
|
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
|
2011-09-12 14:54:27 +01:00
|
|
|
out_file_name = self.header_to_remove.abspath()
|
2010-10-26 15:11:17 +01:00
|
|
|
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
|
2011-09-08 16:13:40 +01:00
|
|
|
out_file_name = self.outputs[0].get_bld().abspath()#self.env)
|
|
|
|
|
header_files = [os.path.basename(node.abspath()) 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):
|
2011-09-08 16:13:40 +01:00
|
|
|
self.m.update('\n'.join([node.abspath() for node in self.inputs]))
|
2010-11-27 14:29:45 +00:00
|
|
|
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
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
# Generates a 'ns3/foo-module.h' header file that includes all public
|
|
|
|
|
# ns3 headers of a certain module.
|
|
|
|
|
@TaskGen.feature('ns3moduleheader')
|
|
|
|
|
@TaskGen.after_method('process_rule')
|
|
|
|
|
def apply_ns3moduleheader(self):
|
|
|
|
|
## get all of the ns3 headers
|
|
|
|
|
ns3_dir_node = self.bld.path.find_dir("ns3")
|
|
|
|
|
all_headers_inputs = []
|
|
|
|
|
found_the_module = False
|
|
|
|
|
for ns3headers in self.bld.all_task_gen:
|
|
|
|
|
if 'ns3header' in getattr(ns3headers, "features", []):
|
|
|
|
|
if ns3headers.module != self.module:
|
|
|
|
|
continue
|
|
|
|
|
found_the_module = True
|
|
|
|
|
for source in ns3headers.headers:
|
|
|
|
|
source = os.path.basename(source)
|
|
|
|
|
node = ns3_dir_node.find_or_declare(os.path.basename(source))
|
|
|
|
|
if node is None:
|
|
|
|
|
fatal("missing header file %s" % (source,))
|
|
|
|
|
all_headers_inputs.append(node)
|
|
|
|
|
if not found_the_module:
|
2011-09-13 17:50:05 +01:00
|
|
|
raise WafError("error finding headers for module %s" % self.module)
|
2011-09-08 16:13:40 +01:00
|
|
|
if not all_headers_inputs:
|
|
|
|
|
return
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
try:
|
2011-09-12 14:54:27 +01:00
|
|
|
module_obj = self.bld.get_tgen_by_name("ns3-" + self.module)
|
|
|
|
|
except WafError: # maybe the module was disabled, and therefore removed
|
2011-09-08 16:13:40 +01:00
|
|
|
return
|
2008-03-15 16:13:18 +00:00
|
|
|
|
2011-09-08 16:13:40 +01:00
|
|
|
all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)]
|
|
|
|
|
task = self.create_task('gen_ns3_module_header')
|
|
|
|
|
task.module = self.module
|
|
|
|
|
task.mode = getattr(self, "mode", "install")
|
|
|
|
|
if task.mode == 'install':
|
|
|
|
|
assert module_obj is not None, self.module
|
|
|
|
|
self.bld.install_files('${PREFIX}/include/ns3',
|
|
|
|
|
ns3_dir_node.find_or_declare("%s-module.h" % self.module))
|
|
|
|
|
task.set_inputs(all_headers_inputs)
|
|
|
|
|
task.set_outputs(all_headers_outputs)
|
|
|
|
|
task.module_deps = module_obj.module_deps
|
|
|
|
|
else:
|
|
|
|
|
task.header_to_remove = all_headers_outputs[0]
|