--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pyscan.patch Thu Jun 20 09:56:26 2013 +0900
@@ -0,0 +1,157 @@
+diff --git a/wscript b/wscript
+--- a/wscript
++++ b/wscript
+@@ -44,6 +44,16 @@
+ help=('Change the default command template to run programs and unit tests with valgrind'),
+ action="store_true", default=False,
+ dest='valgrind')
++ opt.add_option('--apiscan',
++ help=("Rescan the API for the indicated module(s), for Python bindings. "
++ "Needs working GCCXML / pygccxml environment. "
++ "The metamodule 'all' expands to all available ns-3 modules."),
++ default=None, dest='apiscan', metavar="MODULE[,MODULE...]")
++# opt.add_option('--with-pybindgen',
++# help=('Path to an existing pybindgen source tree to use.'),
++# default=None,
++# dest='with_pybindgen', type="string")
++
+
+ def search_file(files):
+ for f in files:
+@@ -554,6 +564,8 @@
+ gen.post()
+ bld.env['PRINT_BUILT_MODULES_AT_END'] = False
+
++ wutils.ns3_python_bindings(bld)
++
+ from waflib import Context, Build
+ class Ns3ShellContext(Context.Context):
+ """run a shell with an environment suitably modified to run locally built programs"""
+diff --git a/wutils.py b/wutils.py
+--- a/wutils.py
++++ b/wutils.py
+@@ -251,4 +251,124 @@
+ execvec.append("--SimulatorImplementationType=ns3::VisualSimulatorImpl")
+ return run_argv([env['PYTHON'][0]] + execvec, env, cwd=cwd)
+
++def ns3_python_bindings(bld):
+
++ # 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)
++ env = bld.env
++ env.append_value("MODULAR_BINDINGS_MODULES", "ns3-"+module)
++
++ if Options.options.apiscan == False:
++ return
++
++ env['ENABLE_PYTHON_BINDINGS'] = True
++ if not env['ENABLE_PYTHON_BINDINGS']:
++ return
++
++ bindings_dir = bld.path.find_dir("bindings")
++ if bindings_dir is None or not os.path.exists(bindings_dir.abspath()):
++ 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
++
++ #if ("ns3-%s" % (module,)) not in env.NS3_ENABLED_MODULES:
++ # #print "bindings for module %s which is not enabled, skip" % module
++ # return
++
++ env.append_value('PYTHON_MODULES_BUILT', module)
++ 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]
++
++ if bindings_dir.find_resource("modulegen_customizations.py") is not None:
++ source.append("bindings/modulegen_customizations.py")
++
++ # the local customization file may or not exist
++ if bld.path.find_resource("bindings/modulegen_local.py"):
++ source.append("bindings/modulegen_local.py")
++
++ 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,)
++ bld.install_files('${PYTHONARCHDIR}/ns', ["bindings/%s.py" % (module_py_name,)])
++ else:
++ extension_name = module_py_name
++
++ target = ['bindings/ns3module.cc', 'bindings/ns3module.h', 'bindings/ns3modulegen.log']
++ #if not debug:
++ # target.append('ns3modulegen.log')
++
++ argv = ['NS3_ENABLED_FEATURES=${FEATURES}',
++ 'GCC_RTTI_ABI_COMPLETE=${GCC_RTTI_ABI_COMPLETE}',
++ '${PYTHON}']
++ #if debug:
++ # argv.extend(["-m", "pdb"])
++
++ argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, extension_name, '${TGT[0]}'])
++
++ argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log
++
++ 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(features=['command'], source=source, target=target, command=argv)
++ bindgen.env['FEATURES'] = ','.join(features)
++ bindgen.dep_vars = ['FEATURES', "GCC_RTTI_ABI_COMPLETE"]
++ bindgen.before = 'cxx'
++ bindgen.after = 'gen_ns3_module_header'
++ bindgen.name = "pybindgen(ns3 module %s)" % module
++ bindgen.install_path = None
++
++ # generate the extension module
++ pymod = bld.new_task_gen(features='cxx cxxshlib pyext')
++ pymod.source = ['bindings/ns3module.cc']
++ pymod.target = '%s/%s' % (module_target_dir, extension_name)
++ pymod.name = 'ns3module_%s' % module
++ pymod.use = ["%s" % mod for mod in pymod.env['NS3_ENABLED_MODULES']] # Should be '"ns3-"+module', but see bug 1117
++ if pymod.env['ENABLE_STATIC_NS3']:
++ if sys.platform == 'darwin':
++ pymod.env.append_value('LINKFLAGS', '-Wl,-all_load')
++ for mod in pymod.usel:
++ #mod = mod.split("--lib")[0]
++ pymod.env.append_value('LINKFLAGS', '-l' + mod)
++ else:
++ pymod.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
++ for mod in pymod.use:
++ #mod = mod.split("--lib")[0]
++ pymod.env.append_value('LINKFLAGS', '-l' + mod)
++ pymod.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
++ defines = list(pymod.env['DEFINES'])
++ 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['DEFINES'] = defines
++ pymod.includes = '# bindings'
++ pymod.install_path = '${PYTHONARCHDIR}/ns'
++
++ # Workaround to a WAF bug, remove this when ns-3 upgrades to WAF > 1.6.10
++ # https://www.nsnam.org/bugzilla/show_bug.cgi?id=1335
++ # http://code.google.com/p/waf/issues/detail?id=1098
++ if Utils.unversioned_sys_platform() == 'darwin':
++ pymod.mac_bundle = True
++
++ return pymod
++
++# bld.ns3_python_bindings = types.MethodType(ns3_python_bindings, bld)
++