View | Details | Raw Unified | Return to bug 1174
Collapse All | Expand All

(-)a/src/wscript (-43 / +105 lines)
 Lines 103-154    Link Here 
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.
 Lines 416-422    Link Here 
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")
 Lines 431-436    Link Here 
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:
 Lines 598-610    Link Here 
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)
(-)a/wscript (-5 / +18 lines)
 Lines 58-64    Link Here 
58
# local modules
58
# local modules
59
import wutils
59
import wutils
60
60
61
Configure.autoconfig = 1
61
#Configure.autoconfig = 1
62
62
63
# the following two variables are used by the target "waf dist"
63
# the following two variables are used by the target "waf dist"
64
VERSION = file("VERSION", "rt").read().strip()
64
VERSION = file("VERSION", "rt").read().strip()
 Lines 207-212    Link Here 
207
                   help=('Compile NS-3 statically: works only on linux, without python'),
207
                   help=('Compile NS-3 statically: works only on linux, without python'),
208
                   dest='enable_static', action='store_true',
208
                   dest='enable_static', action='store_true',
209
                   default=False)
209
                   default=False)
210
    opt.add_option('--enable-shared-and-static',
211
                   help=('Compile NS-3 both shared and static libraries at the same time: static works only on linux'),
212
                   dest='enable_shared_and_static', action='store_true',
213
                   default=False)
210
    opt.add_option('--enable-mpi',
214
    opt.add_option('--enable-mpi',
211
                   help=('Compile NS-3 with MPI and distributed simulation support'),
215
                   help=('Compile NS-3 with MPI and distributed simulation support'),
212
                   dest='enable_mpi', action='store_true',
216
                   dest='enable_mpi', action='store_true',
 Lines 316-327    Link Here 
316
                env['WL_SONAME_SUPPORTED'] = True
320
                env['WL_SONAME_SUPPORTED'] = True
317
321
318
    env['ENABLE_STATIC_NS3'] = False
322
    env['ENABLE_STATIC_NS3'] = False
319
    if Options.options.enable_static:
323
    if Options.options.enable_static or Options.options.enable_shared_and_static:
320
        if env['PLATFORM'].startswith('linux') and \
324
        if env['PLATFORM'].startswith('linux') and \
321
                env['CXX_NAME'] in ['gcc', 'icc']:
325
                env['CXX_NAME'] in ['gcc', 'icc']:
322
            if re.match('i[3-6]86', os.uname()[4]):
326
            if re.match('i[3-6]86', os.uname()[4]):
323
                conf.report_optional_feature("static", "Static build", True, '')
327
                conf.report_optional_feature("static", "Static build", True, '')
324
                env['ENABLE_STATIC_NS3'] = True
328
                if Options.options.enable_static:
329
                    env['ENABLE_STATIC_NS3'] = True
330
                if Options.options.enable_shared_and_static:
331
                    env['ENABLE_SHARED_AND_STATIC_NS3'] = True
325
            elif os.uname()[4] == 'x86_64':
332
            elif os.uname()[4] == 'x86_64':
326
                if env['ENABLE_PYTHON_BINDINGS'] and \
333
                if env['ENABLE_PYTHON_BINDINGS'] and \
327
                        not conf.check_compilation_flag('-mcmodel=large'):
334
                        not conf.check_compilation_flag('-mcmodel=large'):
 Lines 332-343    Link Here 
332
                                                     "compiler to at least gcc 4.3.x.")
339
                                                     "compiler to at least gcc 4.3.x.")
333
                else:
340
                else:
334
                    conf.report_optional_feature("static", "Static build", True, '')
341
                    conf.report_optional_feature("static", "Static build", True, '')
335
                    env['ENABLE_STATIC_NS3'] = True                    
342
                    if Options.options.enable_static:
343
                        env['ENABLE_STATIC_NS3'] = True
344
                    if Options.options.enable_shared_and_static:
345
                        env['ENABLE_SHARED_AND_STATIC_NS3'] = True
336
        elif env['CXX_NAME'] == 'gcc' and \
346
        elif env['CXX_NAME'] == 'gcc' and \
337
                (env['PLATFORM'].startswith('darwin') or \
347
                (env['PLATFORM'].startswith('darwin') or \
338
                     env['PLATFORM'].startswith('cygwin')):
348
                     env['PLATFORM'].startswith('cygwin')):
339
                conf.report_optional_feature("static", "Static build", True, '')
349
                conf.report_optional_feature("static", "Static build", True, '')
340
                env['ENABLE_STATIC_NS3'] = True
350
                if Options.options.enable_static:
351
                    env['ENABLE_STATIC_NS3'] = True
352
                if Options.options.enable_shared_and_static:
353
                    env['ENABLE_SHARED_AND_STATIC_NS3'] = True
341
        else:
354
        else:
342
            conf.report_optional_feature("static", "Static build", False,
355
            conf.report_optional_feature("static", "Static build", False,
343
                                         "Unsupported platform")
356
                                         "Unsupported platform")

Return to bug 1174