diff --git a/examples/a/module-autogen.py b/examples/a/module-autogen.py new file mode 100644 index 0000000..ead4258 --- /dev/null +++ b/examples/a/module-autogen.py @@ -0,0 +1,18 @@ +#! /usr/bin/env python + +import sys + +import pybindgen +from pybindgen import FileCodeSink +from pybindgen.gccxmlparser import ModuleParser + +def my_module_gen(): + module_parser = ModuleParser('a1', '::') + module = module_parser.parse([sys.argv[1]]) + module.add_include('"a.h"') + + pybindgen.write_preamble(FileCodeSink(sys.stdout)) + module.generate(FileCodeSink(sys.stdout)) + +if __name__ == '__main__': + my_module_gen() diff --git a/examples/a/module-autoscan.py b/examples/a/module-autoscan.py new file mode 100644 index 0000000..6d4ddbd --- /dev/null +++ b/examples/a/module-autoscan.py @@ -0,0 +1,13 @@ +#! /usr/bin/env python + +import sys + +from pybindgen import FileCodeSink +from pybindgen.gccxmlparser import ModuleParser + +def my_module_gen(): + module_parser = ModuleParser('a2', '::') + module_parser.parse([sys.argv[1]], includes=['"a.h"'], pygen_sink=FileCodeSink(sys.stdout)) + +if __name__ == '__main__': + my_module_gen() diff --git a/examples/a/wscript b/examples/a/wscript index c6f700c..3f7527d 100644 --- a/examples/a/wscript +++ b/examples/a/wscript @@ -26,3 +26,49 @@ def build(bld): obj.target = 'a' obj.inst_var = 0 # do not install obj.includes = '.' + + + if bld.env()['ENABLE_PYGCCXML']: + ## gccxml direct generation method + bindgen = bld.create_obj('command-output') + bindgen.stdout = 'a1module.cc' + bindgen.argv = [bindgen.input_file('module-autogen.py'), + bindgen.input_file('a.h')] + bindgen.command = bindgen.env['PYTHON'] + bindgen.command_is_external = True + bindgen.prio = 55 # must run after the 'py' objects in ../pybindgen + + obj = create_pyext_obj(bld, 'cpp') + obj.source = [ + 'a.cc', + 'a1module.cc' + ] + obj.target = 'a1' + obj.inst_var = 0 # do not install + obj.includes = '.' + + + ## gccxml indirect generation method + bindgen = bld.create_obj('command-output') + bindgen.stdout = 'a2modulegen.py' + bindgen.argv = [bindgen.input_file('module-autoscan.py'), + bindgen.input_file('a.h')] + bindgen.command = bindgen.env['PYTHON'] + bindgen.command_is_external = True + bindgen.prio = 55 # must run after the 'py' objects in ../pybindgen + + bindgen = bld.create_obj('command-output') + bindgen.stdout = 'a2module.cc' + bindgen.argv = [bindgen.input_file('a2modulegen.py')] + bindgen.command = bindgen.env['PYTHON'] + bindgen.command_is_external = True + bindgen.prio = 56 # must run after the 'py' objects in ../pybindgen + + obj = create_pyext_obj(bld, 'cpp') + obj.source = [ + 'a.cc', + 'a2module.cc' + ] + obj.target = 'a2' + obj.inst_var = 0 # do not install + obj.includes = '.'