diff --git a/bindings/python/ns3modulegen-modular.py b/bindings/python/ns3modulegen-modular.py index aba049f87..9547e287a 100644 --- a/bindings/python/ns3modulegen-modular.py +++ b/bindings/python/ns3modulegen-modular.py @@ -44,7 +44,7 @@ class MyMultiSectionFactory(MultiSectionFactory): def main(argv): - module_abs_src_path, target, output_cc_file_name = argv[1:] + module_abs_src_path, target, extension_name, output_cc_file_name = argv[1:] module_name = os.path.basename(module_abs_src_path) out = MyMultiSectionFactory(output_cc_file_name) @@ -70,6 +70,7 @@ def main(argv): sys.path.pop(0) root_module = module_apidefs.module_init() + root_module.set_name(extension_name) root_module.add_include('"ns3/%s-module.h"' % module_name) # ----------- diff --git a/bindings/python/wscript b/bindings/python/wscript index 84ae4fc88..295dd1a34 100644 --- a/bindings/python/wscript +++ b/bindings/python/wscript @@ -15,7 +15,7 @@ import Build import Utils ## https://launchpad.net/pybindgen/ -REQUIRED_PYBINDGEN_VERSION = (0, 15, 0, 777) +REQUIRED_PYBINDGEN_VERSION = (0, 15, 0, 779) REQUIRED_PYGCCXML_VERSION = (0, 9, 5) diff --git a/src/wscript b/src/wscript index c0c5895ae..3aa4baace 100644 --- a/src/wscript +++ b/src/wscript @@ -199,6 +199,19 @@ def ns3_python_bindings(bld): 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/.py exists, it becomes the module frontend, and the C extension befomes _ + 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,) + else: + extension_name = module_py_name + target = ['bindings/ns3module.cc', 'bindings/ns3module.h', 'bindings/ns3modulegen.log'] #if not debug: # target.append('ns3modulegen.log') @@ -207,7 +220,7 @@ def ns3_python_bindings(bld): #if debug: # argv.extend(["-m", "pdb"]) - argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, '${TGT[0]}']) + argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, extension_name, '${TGT[0]}']) argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log @@ -223,9 +236,10 @@ def ns3_python_bindings(bld): bindgen.after = 'gen_ns3_module_header_task' bindgen.name = "pybindgen(ns3 module %s)" % module + # generate the extension module pymod = bld.new_task_gen(features='cxx cshlib pyext') pymod.source = ['bindings/ns3module.cc'] - pymod.target = '%s/%s' % (bld.srcnode.find_dir("bindings/python/ns").relpath_gen(bld.path), module.replace('-', '_')) + pymod.target = '%s/%s' % (module_target_dir, extension_name) pymod.name = 'ns3module_%s' % module pymod.uselib_local = "ns3-"+module if pymod.env['ENABLE_STATIC_NS3']: