source: trunk/python2/SConstruct @ 196

Last change on this file since 196 was 196, checked in by tim, 14 years ago

experimental python bindings generator as provided by Michael Cohen

File size: 1.2 KB
Line 
1import os, os.path, pdb
2from functools import partial
3import utils
4import config
5import class_parser
6
7def build_python_bindings(target, source, env, initialization=''):
8    """ A command to generate python bindings """
9    module_name = os.path.splitext(os.path.basename(target[0].name))[0]
10    utils.warn("Generating automatic python bindings for module %s" % module_name)
11
12    p = class_parser.HeaderParser(module_name, verbose=config.V)
13    p.module.init_string = initialization
14    p.parse_filenames([s.get_abspath() for s in source])
15
16    fd = open(target[0].get_abspath(), 'w')
17    p.write(fd)
18    fd.close()
19
20
21
22nenv = utils.ExtendedEnvironment()
23
24BOUND_FILES = Split("""
25    ../include/regfi.h
26    regfi/pyregfi.h
27    """)
28
29nenv.config = config
30nenv.Append(CFLAGS = "-I../include/ -Iinclude")
31nenv.Append(LIBPATH="../lib")
32nenv.Append(LINKFLAGS="")
33nenv.Command('regfi/pyregfi.c', BOUND_FILES, partial(build_python_bindings,
34                                                     initialization='pyregfi_init();'))
35nenv.Depends('regfi/pyregfi.c', 'class_parser.py')
36
37nenv.PythonModule("pyregfi", ['regfi/pyregfi.c', 'regfi/regfi.c', 'regfi/class.c', 'regfi/error.c'],
38                  LIBS=['regfi', 'talloc'])
Note: See TracBrowser for help on using the repository browser.