|
|
| 103 |
conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules] |
103 |
conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules] |
| 104 |
|
104 |
|
| 105 |
|
105 |
|
|
|
106 |
class ns3module_taskgen(TaskGen.task_gen): |
| 107 |
def __init__(self, *args, **kwargs): |
| 108 |
super(ns3module_taskgen, self).__init__(*args, **kwargs) |
| 109 |
|
| 110 |
def apply(self): |
| 111 |
static_enabled = False |
| 112 |
shared_enabled = True |
| 113 |
bld = self.bld |
| 114 |
if bld.env['ENABLE_STATIC_NS3']: |
| 115 |
static_enabled = True |
| 116 |
shared_enabled = False |
| 117 |
if bld.env['ENABLE_SHARED_AND_STATIC_NS3']: |
| 118 |
static_enabled = True |
| 119 |
shared_enabled = True |
| 120 |
|
| 121 |
assert self.name.startswith("ns3-") |
| 122 |
name = self.name.split("ns3-")[1] |
| 123 |
|
| 124 |
sub_taskgens = [] |
| 125 |
if static_enabled: |
| 126 |
static = self._create_ns3_module(self.bld, name, self.dependencies, True) |
| 127 |
sub_taskgens.append(static) |
| 128 |
else: |
| 129 |
self.static = None |
| 130 |
if shared_enabled: |
| 131 |
shared = self._create_ns3_module(self.bld, name, self.dependencies, False) |
| 132 |
sub_taskgens.append(shared) |
| 133 |
else: |
| 134 |
self.shared = None |
| 135 |
|
| 136 |
for gen in sub_taskgens: |
| 137 |
gen.source = self.source |
| 138 |
gen.env = self.env.copy() |
| 139 |
features = list(self.features) |
| 140 |
features.remove("ns3module") |
| 141 |
gen.features.extend(features) |
| 142 |
gen.path = self.path |
| 143 |
gen.uselib = self.uselib |
| 144 |
if hasattr(self, 'includes'): |
| 145 |
gen.includes = self.includes |
| 146 |
if not hasattr(self, "is_ns3_module"): |
| 147 |
delattr(module, "is_ns3_module") |
| 148 |
|
| 149 |
if not self.test: |
| 150 |
pcfile = bld.new_task_gen('ns3pcfile') |
| 151 |
pcfile.module = sub_taskgens[0] |
| 152 |
|
| 153 |
|
| 154 |
def _create_ns3_module(self, bld, name, dependencies, static): |
| 155 |
# Create a separate library for this module. |
| 156 |
if static: |
| 157 |
module = bld.new_task_gen('cxx', 'cstaticlib') |
| 158 |
else: |
| 159 |
module = bld.new_task_gen('cxx', 'cshlib') |
| 160 |
|
| 161 |
# Initially create an empty value for this because the pcfile |
| 162 |
# writing task assumes every module has a uselib attribute. |
| 163 |
module.uselib = '' |
| 164 |
module.is_static = static |
| 165 |
module.is_ns3_module = True |
| 166 |
module.name = 'ns3-' + name |
| 167 |
module.vnum = wutils.VNUM |
| 168 |
# Add the proper path to the module's name. |
| 169 |
module.target = '%s/ns3-%s' % (bld.srcnode.relpath_gen(self.path), name) |
| 170 |
# Set the libraries this module depends on. |
| 171 |
module.uselib_local = ['ns3-' + dep for dep in dependencies] |
| 172 |
module.module_deps = list(dependencies) |
| 173 |
if not static: |
| 174 |
module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS']) |
| 175 |
module.env.append_value('CCFLAGS', module.env['shlib_CXXFLAGS']) |
| 176 |
# Turn on the link flags for shared libraries if we have the |
| 177 |
# proper compiler and platform. |
| 178 |
if module.env['CXX_NAME'] in ['gcc', 'icc'] and module.env['WL_SONAME_SUPPORTED']: |
| 179 |
# Get the module library name without any relative paths |
| 180 |
# at its beginning because all of the libraries will end |
| 181 |
# up in the same directory. |
| 182 |
module_library_name = os.path.basename(ccroot.get_target_name(module)) |
| 183 |
module.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % module_library_name) |
| 184 |
elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \ |
| 185 |
os.uname()[4] == 'x86_64' and \ |
| 186 |
module.env['ENABLE_PYTHON_BINDINGS']: |
| 187 |
# enable that flag for static builds only on x86-64 platforms |
| 188 |
# when gcc is present and only when we want python bindings |
| 189 |
# (it's more efficient to not use this option if we can avoid it) |
| 190 |
module.env.append_value('CXXFLAGS', '-mcmodel=large') |
| 191 |
module.env.append_value('CCFLAGS', '-mcmodel=large') |
| 192 |
|
| 193 |
module.env.append_value('CXXDEFINES', "NS3_MODULE_COMPILATION") |
| 194 |
module.env.append_value('CCDEFINES', "NS3_MODULE_COMPILATION") |
| 195 |
|
| 196 |
module.install_path = "${LIBDIR}" |
| 197 |
|
| 198 |
return module |
| 199 |
|
| 200 |
|
| 106 |
def create_ns3_module(bld, name, dependencies=(), test=False): |
201 |
def create_ns3_module(bld, name, dependencies=(), test=False): |
| 107 |
# Create a separate library for this module. |
202 |
module = bld.new_task_gen('ns3module') |
| 108 |
if bld.env['ENABLE_STATIC_NS3']: |
203 |
module.bld = bld |
| 109 |
module = bld.new_task_gen('cxx', 'cstaticlib') |
204 |
module.name = "ns3-" + name |
| 110 |
else: |
205 |
module.dependencies = dependencies |
| 111 |
module = bld.new_task_gen('cxx', 'cshlib') |
|
|
| 112 |
if not test: |
| 113 |
pcfile = bld.new_task_gen('ns3pcfile') |
| 114 |
pcfile.module = module |
| 115 |
|
| 116 |
# Initially create an empty value for this because the pcfile |
| 117 |
# writing task assumes every module has a uselib attribute. |
| 118 |
module.uselib = '' |
206 |
module.uselib = '' |
| 119 |
|
|
|
| 120 |
module.is_ns3_module = True |
| 121 |
module.name = 'ns3-' + name |
| 122 |
module.vnum = wutils.VNUM |
| 123 |
# Add the proper path to the module's name. |
| 124 |
module.target = '%s/ns3-%s' % (bld.srcnode.relpath_gen(bld.path), name) |
| 125 |
# Set the libraries this module depends on. |
| 126 |
module.uselib_local = ['ns3-' + dep for dep in dependencies] |
207 |
module.uselib_local = ['ns3-' + dep for dep in dependencies] |
| 127 |
module.module_deps = list(dependencies) |
208 |
module.module_deps = list(dependencies) |
| 128 |
if not module.env['ENABLE_STATIC_NS3']: |
209 |
module.test = test |
| 129 |
module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS']) |
210 |
module.is_ns3_module = True |
| 130 |
module.env.append_value('CCFLAGS', module.env['shlib_CXXFLAGS']) |
|
|
| 131 |
# Turn on the link flags for shared libraries if we have the |
| 132 |
# proper compiler and platform. |
| 133 |
if module.env['CXX_NAME'] in ['gcc', 'icc'] and module.env['WL_SONAME_SUPPORTED']: |
| 134 |
# Get the module library name without any relative paths |
| 135 |
# at its beginning because all of the libraries will end |
| 136 |
# up in the same directory. |
| 137 |
module_library_name = os.path.basename(ccroot.get_target_name(module)) |
| 138 |
module.env.append_value('LINKFLAGS', '-Wl,--soname=%s' % module_library_name) |
| 139 |
elif module.env['CXX_NAME'] in ['gcc', 'icc'] and \ |
| 140 |
os.uname()[4] == 'x86_64' and \ |
| 141 |
module.env['ENABLE_PYTHON_BINDINGS']: |
| 142 |
# enable that flag for static builds only on x86-64 platforms |
| 143 |
# when gcc is present and only when we want python bindings |
| 144 |
# (it's more efficient to not use this option if we can avoid it) |
| 145 |
module.env.append_value('CXXFLAGS', '-mcmodel=large') |
| 146 |
module.env.append_value('CCFLAGS', '-mcmodel=large') |
| 147 |
|
| 148 |
module.env.append_value('CXXDEFINES', "NS3_MODULE_COMPILATION") |
| 149 |
module.env.append_value('CCDEFINES', "NS3_MODULE_COMPILATION") |
| 150 |
return module |
211 |
return module |
| 151 |
|
212 |
|
|
|
213 |
|
| 152 |
def create_ns3_module_test_library(bld, name): |
214 |
def create_ns3_module_test_library(bld, name): |
| 153 |
# Create an ns3 module for the test library that depends only on |
215 |
# Create an ns3 module for the test library that depends only on |
| 154 |
# the module being tested. |
216 |
# the module being tested. |
|
|
| 416 |
def apply(self): |
478 |
def apply(self): |
| 417 |
for filename in set(self.to_list(self.source)): |
479 |
for filename in set(self.to_list(self.source)): |
| 418 |
src_node = self.path.find_resource(filename) |
480 |
src_node = self.path.find_resource(filename) |
| 419 |
self.bld.install_files('${PREFIX}/include/ns3', [src_node]) |
|
|
| 420 |
if self.module is None: |
481 |
if self.module is None: |
| 421 |
raise Utils.WafError("'module' missing on ns3headers object %s" % self) |
482 |
raise Utils.WafError("'module' missing on ns3headers object %s" % self) |
| 422 |
ns3_dir_node = self.bld.path.find_dir("ns3") |
483 |
ns3_dir_node = self.bld.path.find_dir("ns3") |
|
|
| 431 |
task = self.create_task('ns3header', env=self.env) |
492 |
task = self.create_task('ns3header', env=self.env) |
| 432 |
task.mode = self.mode |
493 |
task.mode = self.mode |
| 433 |
if self.mode == 'install': |
494 |
if self.mode == 'install': |
|
|
495 |
self.bld.install_files('${PREFIX}/include/ns3', [src_node]) |
| 434 |
task.set_inputs([src_node]) |
496 |
task.set_inputs([src_node]) |
| 435 |
task.set_outputs([dst_node]) |
497 |
task.set_outputs([dst_node]) |
| 436 |
else: |
498 |
else: |
|
|
| 598 |
raise Utils.WscriptError("error finding headers for module %s" % self.module) |
660 |
raise Utils.WscriptError("error finding headers for module %s" % self.module) |
| 599 |
if not all_headers_inputs: |
661 |
if not all_headers_inputs: |
| 600 |
return |
662 |
return |
| 601 |
self.bld.install_files('${PREFIX}/include/ns3', |
|
|
| 602 |
ns3_dir_node.find_or_declare("%s-module.h" % self.module)) |
| 603 |
all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)] |
663 |
all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)] |
| 604 |
task = self.create_task('gen_ns3_module_header', env=self.env) |
664 |
task = self.create_task('gen_ns3_module_header', env=self.env) |
| 605 |
task.module = self.module |
665 |
task.module = self.module |
| 606 |
task.mode = self.mode |
666 |
task.mode = self.mode |
| 607 |
if self.mode == 'install': |
667 |
if self.mode == 'install': |
|
|
668 |
self.bld.install_files('${PREFIX}/include/ns3', |
| 669 |
ns3_dir_node.find_or_declare("%s-module.h" % self.module)) |
| 608 |
task.set_inputs(all_headers_inputs) |
670 |
task.set_inputs(all_headers_inputs) |
| 609 |
task.set_outputs(all_headers_outputs) |
671 |
task.set_outputs(all_headers_outputs) |
| 610 |
module_obj = self.bld.name_to_obj("ns3-" + self.module, self.env) |
672 |
module_obj = self.bld.name_to_obj("ns3-" + self.module, self.env) |