def options(opt):
    opt.load('python')

def configure(conf):
    conf.load('python')
    conf.check_python_version((2, 6, 0))
    conf.check_python_headers()

def build(ctx):
    srcnode = ctx.srcnode.make_node('pylib')
    #bldnode = ctx.bldnode.make_node('pylib')
    target1 = ctx.srcnode.make_node('pylib/control.py')
    target2 = ctx.srcnode.make_node('pylib/magic.py')
    target3 = ctx.srcnode.make_node('pylib/version.py')
    target4 = ctx.srcnode.make_node('wafhelpers/.autorevision-cache')

    ctx(
	before      = ['pyc', 'pyo'],
	cwd         = srcnode,
	rule        = '${SRC} >${TGT}',
	source      = ["../wafhelpers/pythonize-header", "../include/ntp_control.h"],
	target      = target1,
	)

    ctx(
	before      = ['pyc', 'pyo'],
	cwd         = srcnode,
	rule        = '${SRC} >${TGT}',
	source      = ["../wafhelpers/pythonize-header", "../include/ntp.h"],
	target      = target2,
	)

    ctx(
	before      = ['pyc', 'pyo'],
	cwd         = srcnode,
	rule        = 'VCS_EXTRA=`cat ${SRC[0]}` ../wafhelpers/autorevision.sh -o ${TGT[1].abspath()} -e VERSION -t python >${TGT[0].name}',
	source      = ["../VERSION", '../wafhelpers/autorevision.sh'] ,
	target      = [target3, target4],
	)

    ctx.add_group() # Force early creation of generated files

    ctx(
	features     ='py',
	source       = ctx.path.ant_glob('*.py'),
	install_from = '.',
	install_path ='${PYTHONDIR}/ntp'
	)
