1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
import os, os.path, pdb
from functools import partial
import utils
import config
import class_parser
def build_python_bindings(target, source, env, initialization=''):
""" A command to generate python bindings """
module_name = os.path.splitext(os.path.basename(target[0].name))[0]
utils.warn("Generating automatic python bindings for module %s" % module_name)
p = class_parser.HeaderParser(module_name, verbose=config.V)
p.module.init_string = initialization
p.parse_filenames([s.get_abspath() for s in source])
fd = open(target[0].get_abspath(), 'w')
p.write(fd)
fd.close()
nenv = utils.ExtendedEnvironment()
BOUND_FILES = Split("""
../include/regfi.h
regfi/pyregfi.h
""")
nenv.config = config
if config.DEBUG:
nenv.Append(CFLAGS = "-std=gnu99 -pedantic -Wall -fPIC -ggdb -O0")
nenv.Append(CPPPATH=['../include', 'include'])
nenv.python_cppflags = '-I/usr/include/python2.5_d'
else:
nenv.Append(CFLAGS = "-std=gnu99 -pedantic -Wall -fPIC")
nenv.Append(CPPPATH=['../include', 'include'])
nenv.Append(LIBPATH="../lib")
nenv.Append(LINKFLAGS="")
# XXX: why should I need to call regfi_init() when it should be called only once automatically?
nenv.Command('regfi/pyregfi.c', BOUND_FILES, partial(build_python_bindings,
initialization='pyregfi_init();regfi_init();'))
nenv.Depends('regfi/pyregfi.c', 'class_parser.py')
nenv.PythonModule("pyregfi", ['regfi/pyregfi.c', 'regfi/regfi.c', 'regfi/class.c', 'regfi/error.c'],
LIBS=['regfi', 'talloc'])
|