[196] | 1 | import os, os.path, pdb |
---|
| 2 | from functools import partial |
---|
| 3 | import utils |
---|
| 4 | import config |
---|
| 5 | import class_parser |
---|
| 6 | |
---|
| 7 | def 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 | |
---|
| 22 | nenv = utils.ExtendedEnvironment() |
---|
| 23 | |
---|
| 24 | BOUND_FILES = Split(""" |
---|
| 25 | ../include/regfi.h |
---|
| 26 | regfi/pyregfi.h |
---|
| 27 | """) |
---|
| 28 | |
---|
| 29 | nenv.config = config |
---|
[198] | 30 | if config.DEBUG: |
---|
[202] | 31 | nenv.Append(CFLAGS = "-std=gnu99 -pedantic -Wall -fPIC -ggdb -O0") |
---|
[198] | 32 | nenv.Append(CPPPATH=['../include', 'include']) |
---|
| 33 | nenv.python_cppflags = '-I/usr/include/python2.5_d' |
---|
| 34 | else: |
---|
[202] | 35 | nenv.Append(CFLAGS = "-std=gnu99 -pedantic -Wall -fPIC") |
---|
[198] | 36 | nenv.Append(CPPPATH=['../include', 'include']) |
---|
| 37 | |
---|
[196] | 38 | nenv.Append(LIBPATH="../lib") |
---|
| 39 | nenv.Append(LINKFLAGS="") |
---|
[202] | 40 | # XXX: why should I need to call regfi_init() when it should be called only once automatically? |
---|
[196] | 41 | nenv.Command('regfi/pyregfi.c', BOUND_FILES, partial(build_python_bindings, |
---|
[202] | 42 | initialization='pyregfi_init();regfi_init();')) |
---|
[196] | 43 | nenv.Depends('regfi/pyregfi.c', 'class_parser.py') |
---|
| 44 | |
---|
| 45 | nenv.PythonModule("pyregfi", ['regfi/pyregfi.c', 'regfi/regfi.c', 'regfi/class.c', 'regfi/error.c'], |
---|
| 46 | LIBS=['regfi', 'talloc']) |
---|