1from waflib.Logs import pprint
2
3
4def options(opt):
5    opt.load('python')
6
7
8def configure(conf):
9    conf.load('python')
10    if not conf.env.ENABLE_CROSS:
11        conf.check_python_version((2, 6, 0))
12    conf.check_python_headers(features='pyext')  # Extension-only, no embedded
13    try:
14        conf.check_python_module('curses')
15        conf.env['PYTHON_CURSES'] = True
16    except conf.errors.ConfigurationError:
17        pprint("YELLOW", "WARNING: ntpmon will not be built/installed since "
18               "python curses module was not found")
19    try:
20        conf.check_python_module('argparse')
21        conf.env['PYTHON_ARGPARSE'] = True
22    except conf.errors.ConfigurationError:
23        pprint("YELLOW", "WARNING: ntploggps, ntplogtemp, and ntpviz will not "
24               "be built/installed since python argparse module was not found")
25    try:
26        conf.check_python_module('gps', condition="ver >= num(3, 18)")
27        conf.env['PYTHON_GPS'] = True
28    except conf.errors.ConfigurationError:
29        pprint("YELLOW", "WARNING: ntploggps will not be built/installed since "
30               "python gps module >= 3.18 was not found")
31
32
33def build(ctx):
34    srcnode = ctx.srcnode.make_node('pylib')
35    bldnode = ctx.bldnode.make_node('pylib')
36    target1 = bldnode.make_node('control.py')
37    target2 = bldnode.make_node('magic.py')
38
39    sources = []
40    if ctx.env['ntpc'] == 'ext':
41        sources = srcnode.ant_glob("*.py", excl='ntpc.py')
42    elif ctx.env['ntpc'] == 'ffi':
43        sources = srcnode.ant_glob('*.py')
44    builds = [x.get_bld() for x in sources]
45
46    # The rm's here were added to fix a reported (but underdocumented) problem
47    # where the results of pythonize-header were not updated when needed,
48    # though there is as yet no explanation for why this had occurred, and the
49    # alleged failure only occurred when changing the code between 'configure'
50    # and 'build', which is not a legal action, anyway.
51    # These rm's were causing unnecessary reruns of pythonize-header,
52    # including during 'install'. They are now disabled but retained as a
53    # comment.
54
55    ## Remove generated files to ensure they are properly updated
56    #ctx.exec_command("rm -f %s" % target1.abspath())
57    #ctx.exec_command("rm -f %s" % target2.abspath())
58
59    if ctx.env['ntpc'] is None:
60        return
61
62    # Make sure Python sees .py as well as .pyc/.pyo
63    ctx(
64        features="subst",
65        source=sources,
66        target=builds,
67    )
68
69    ctx(
70        before=['pyc', 'pyo'],
71        cwd=srcnode,
72        rule='${PYTHON} ${SRC} >${TGT}',
73        source=["../wafhelpers/pythonize-header", "../include/ntp_control.h"],
74        target=target1,
75    )
76
77    ctx(
78        before=['pyc', 'pyo'],
79        cwd=srcnode,
80        rule='${PYTHON} ${SRC} >${TGT}',
81        source=["../wafhelpers/pythonize-header", "../include/ntp.h"],
82        target=target2,
83    )
84
85    # Force early creation of generated files
86    ctx.add_group()
87
88    ctx(
89        features='py',
90        source=builds+[target1, target2],
91        install_from=bldnode,
92        install_path='${PYTHONARCHDIR}/ntp'
93    )
94
95    # pep241  lay an egg
96    egg = ['ntp-%s.egg-info' % ctx.env.NTPSEC_VERSION]
97    ctx(
98        features="subst",
99        source=['ntp-in.egg-info'],
100        target=egg
101    )
102    ctx.install_files(ctx.env.PYTHONARCHDIR, egg)
103