Add an example

This commit is contained in:
Gustavo J. A. M. Carneiro
2007-05-31 17:58:02 +01:00
parent ccd7c49e6a
commit a0cd17dbdb
5 changed files with 119 additions and 17 deletions
+26
View File
@@ -0,0 +1,26 @@
//
// foo.cc
//
// Made by Gustavo J. A. M. Carneiro
// Login <gjc@localhost.localdomain>
//
// Started on Thu May 31 17:36:21 2007 Gustavo J. A. M. Carneiro
// Started on Thu May 31 17:36:21 2007 Gustavo J. A. M. Carneiro
//
#include "foo.h"
#include <iostream>
#include <string.h>
int print_something(const char *message)
{
std::cout << "MESSAGE1: " << message << std::endl;
return strlen(message);
}
int print_something_else(const char *message2)
{
std::cout << "MESSAGE2: " << message2 << std::endl;
return strlen(message2);
}
+7
View File
@@ -0,0 +1,7 @@
#ifndef FOO_H_
# define FOO_H_
int print_something(const char *message);
int print_something_else(const char *message2);
#endif /* !FOO_H_ */
+72
View File
@@ -0,0 +1,72 @@
## -*- python -*-
import Action
import Object
import Params
import Task
import os, sys
sys.path.insert(0, os.getcwd()) # to work with uninstalled pybindgen
from pybindgen import (ReturnValue, Parameter, Module, Function, FileCodeSink)
def _pybindgen_action(task):
target, = task.m_outputs
out_file = file(target.bldpath(task.m_env), "w")
task.function(out_file)
out_file.close()
class PyBindGen(Object.genobj):
def __init__(self, env=None):
Object.genobj.__init__(self, 'other')
self.install_var = 0
self.env = env
if not self.env:
self.env = Params.g_build.m_allenvs['default'].copy()
self.function = None
self.target = None
self.prio = 5
def apply(self):
function = self.function
task = self.create_task('pybindgen', self.env, self.prio)
task.function = self.function
target = self.path.find_build(self.target)
task.set_outputs([target])
task.set_inputs([self.path.find_source('wscript')])
def install(self):
pass
def my_module_gen(out_file):
print >> out_file, "#include <Python.h>"
print >> out_file, "#include \"foo.h\""
mod = Module('foo')
mod.add_function(Function(ReturnValue('int'), 'print_something',
[Parameter('const char*', 'message')]))
mod.add_function(Function(ReturnValue('int'), 'print_something_else',
[Parameter('const char*', 'message2')]))
mod.generate(FileCodeSink(out_file))
def build(bld):
Object.register('pybindgen', PyBindGen)
Action.Action('pybindgen', func=_pybindgen_action, color='BLUE')
bindgen = bld.create_obj('pybindgen')
bindgen.target = 'foomodule.cc'
bindgen.function = my_module_gen
obj = bld.create_obj('cpp', 'shlib', 'pyext')
obj.source = [
'foo.cc',
'foomodule.cc'
]
obj.target = 'foo'
obj.post()
-15
View File
@@ -3,23 +3,8 @@
import sys
import os.path
import os
from Params import fatal
import pproc as subprocess
def set_options(opt):
opt.tool_options('python')
opt.tool_options('compiler_cxx')
def configure(conf):
conf.check_tool('misc')
if not conf.check_tool('compiler_cxx'):
fatal("Error: no C compiler was found in PATH.")
if not (conf.check_tool('python')
and conf.check_python_version((2,4,2))
and conf.check_python_headers()):
fatal("Error: missing Python development environment.\n"
"(Hint: if you do not have a debugging Python library installed"
" try using the configure option '--debug-level release')")
def build(bld):
gen = bld.create_obj('command-output')
+14 -2
View File
@@ -2,6 +2,7 @@
## (C) 2007 Gustavo J. A. M. Carneiro
import Params
from Params import fatal
VERSION='0.1'
@@ -10,12 +11,23 @@ srcdir = '.'
blddir = 'build'
def set_options(opt):
opt.sub_options('tests')
opt.tool_options('python')
opt.tool_options('compiler_cxx')
def configure(conf):
conf.sub_config('tests')
conf.check_tool('misc')
if not conf.check_tool('compiler_cxx'):
fatal("Error: no C compiler was found in PATH.")
if not (conf.check_tool('python')
and conf.check_python_version((2,4,2))
and conf.check_python_headers()):
fatal("Error: missing Python development environment.\n"
"(Hint: if you do not have a debugging Python library installed"
" try using the configure option '--debug-level release')")
def build(bld):
if Params.g_commands['check']:
bld.add_subdirs('tests')
bld.add_subdirs('examples')