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 nenv.Append(CFLAGS = "-I../include/ -Iinclude") nenv.Append(LIBPATH="../lib") nenv.Append(LINKFLAGS="") nenv.Command('regfi/pyregfi.c', BOUND_FILES, partial(build_python_bindings, initialization='pyregfi_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'])