Files
unison/src/wscript

216 lines
7.3 KiB
Plaintext
Raw Normal View History

2007-05-07 12:01:51 +01:00
## -*- Mode: python; py-indent-offset: 4; indent-tabs-mode: nil; coding: utf-8; -*-
import os, os.path
import shutil
import types
2008-12-29 13:28:54 +00:00
import warnings
2008-12-29 13:28:54 +00:00
import TaskGen
import Task
import Options
import Build
#import Action
#import Common
#import Object
#import Params
all_modules = (
'core',
'common',
'simulator',
'contrib',
'node',
'internet-stack',
'devices/point-to-point',
2007-08-09 15:56:28 -07:00
'devices/csma',
2008-10-29 22:39:36 -07:00
'devices/emu',
2008-11-07 20:41:38 -08:00
'devices/bridge',
2007-09-12 15:23:25 -07:00
'applications/onoff',
'applications/packet-sink',
'applications/udp-echo',
'routing/olsr',
2007-08-03 09:29:57 -07:00
'routing/global-routing',
2007-07-23 15:53:54 +02:00
'mobility',
'devices/wifi',
2008-03-13 14:24:45 -07:00
'helper',
2008-08-29 13:22:09 -04:00
'contrib/stats',
'applications/v4ping',
)
2007-05-07 12:01:51 +01:00
def set_options(opt):
opt.sub_options('simulator')
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)
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')
conf.sub_config('simulator')
2008-11-07 20:41:38 -08:00
conf.sub_config('devices/emu')
conf.sub_config('contrib')
conf.sub_config('internet-stack')
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()))
conf.env.append_value('NS3_MODULE_PATH', blddir)
2008-12-29 13:28:54 +00:00
if Options.options.enable_rpath:
conf.env.append_value('RPATH', '-Wl,-rpath=%s' % (os.path.join(blddir),))
## Used to link the 'run-tests' program with all of ns-3 code
conf.env['NS3_MODULES'] = ['ns3-' + module.split('/')[-1] for module in all_modules]
def create_ns3_module(bld, name, dependencies=()):
2008-12-29 13:28:54 +00:00
module = bld.new_task_gen('cxx', 'objects')
module.name = 'ns3-' + name
module.target = module.name
module.add_objects = ['ns3-' + dep for dep in dependencies]
module.module_deps = list(dependencies)
module.env.append_value('CXXFLAGS', module.env['shlib_CXXFLAGS'])
module.env.append_value('CXXDEFINES', "NS3_MODULE_COMPILATION")
return module
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-07 12:01:51 +01:00
def build(bld):
#Object.register('ns3header', Ns3Header)
2008-12-29 13:28:54 +00:00
#Action.Action('ns3header', func=_ns3_headers_inst, color='BLUE')
#Object.register('ns3-module-header', Ns3ModuleHeader)
2008-12-29 13:28:54 +00:00
#Action.Action('gen-ns3-module-header', func=gen_ns3_module_header, color='BLUE')
bld.create_ns3_module = types.MethodType(create_ns3_module, bld)
2008-12-29 13:28:54 +00:00
bld.create_obj = types.MethodType(create_obj, bld)
bld.add_subdirs(list(all_modules))
for module in all_modules:
2008-12-29 13:28:54 +00:00
modheader = bld.new_task_gen('ns3moduleheader')
modheader.module = module.split('/')[-1]
2008-12-29 13:28:54 +00:00
class ns3header_taskgen(TaskGen.task_gen):
"""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
self.sub_dir = None # if not None, header files will be published as ns3/sub_dir/file.h
self.module = None # module name
def apply(self):
if self.module is None:
2008-12-29 13:28:54 +00:00
raise Utils.WafError("'module' missing on ns3headers object %s" % self)
ns3_dir_node = Build.bld.path.find_dir("ns3")
if self.sub_dir is not None:
ns3_dir_node = ns3_dir_node.find_dir(self.sub_dir)
for filename in self.to_list(self.source):
2008-12-29 13:28:54 +00:00
src_node = self.path.find_resource(filename)
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))
assert dst_node is not None
2008-12-29 13:28:54 +00:00
task = self.create_task('ns3header', self.env)
task.set_inputs([src_node])
task.set_outputs([dst_node])
2008-12-29 13:28:54 +00:00
class ns3header_task(Task.Task):
before = 'cc cxx'
color = 'BLUE'
def run(self):
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
class gen_ns3_module_header_task(Task.Task):
before = 'cc cxx'
color = 'BLUE'
def run(self):
assert len(self.outputs) == 1
header_files = [os.path.basename(node.abspath(self.env)) for node in self.inputs]
outfile = file(self.outputs[0].bldpath(self.env), "w")
header_files.sort()
print >> outfile, """
#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-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-12-29 13:28:54 +00:00
print >> outfile
print >> outfile, "// Module headers:"
for header in header_files:
print >> outfile, "#include \"%s\"" % (header,)
2008-12-29 13:28:54 +00:00
print >> outfile, "#endif"
2008-12-29 13:28:54 +00:00
outfile.close()
return 0
2008-12-29 13:28:54 +00:00
class ns3moduleheader_taskgen(TaskGen.task_gen):
"""
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)
self.module_name = None
def apply(self):
## get all of the ns3 headers
2008-12-29 13:28:54 +00:00
ns3_dir_node = Build.bld.path.find_dir("ns3")
all_headers_inputs = []
2008-12-29 13:28:54 +00:00
for ns3headers in Build.bld.all_task_gen:
if isinstance(ns3headers, ns3header_taskgen):
if ns3headers.module != self.module:
continue
for source in ns3headers.to_list(ns3headers.source):
source = os.path.basename(source)
2008-12-29 13:28:54 +00:00
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)
assert all_headers_inputs
2008-12-29 13:28:54 +00:00
module_obj = Build.bld.name_to_obj("ns3-" + self.module, self.env)
assert module_obj is not None
2008-12-29 13:28:54 +00:00
all_headers_outputs = [ns3_dir_node.find_or_declare("%s-module.h" % self.module)]
task = self.create_task('gen_ns3_module_header', self.env)
task.set_inputs(all_headers_inputs)
task.set_outputs(all_headers_outputs)
task.module = self.module
task.module_deps = module_obj.module_deps
def install(self):
pass