Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 852143 | Differences between
and this patch

Collapse All | Expand All

(-)a/attic/wscript (-4 / +9 lines)
Lines 1-8 Link Here
1
def build(ctx):
1
def build(ctx):
2
    util = [	'sht',
2
    util = [
3
		'digest-find', 'clocks', "random",
3
        "sht",
4
		'digest-timing', 'cmac-timing',
4
        "digest-find",
5
		'backwards']
5
        "clocks",
6
        "random",
7
        "digest-timing",
8
        "cmac-timing",
9
        "backwards",
10
    ]
6
11
7
    for name in util:
12
    for name in util:
8
        ctx(
13
        ctx(
(-)a/docs/wscript (-15 / +10 lines)
Lines 1-6 Link Here
1
def build(ctx):
1
def build(ctx):
2
2
3
    doc_source = ctx.path.ant_glob("*.adoc", excl='*-body.adoc')
3
    doc_source = ctx.path.ant_glob("*.adoc", excl="*-body.adoc")
4
4
5
    ctx(
5
    ctx(
6
        source=doc_source,
6
        source=doc_source,
Lines 8-18 def build(ctx): Link Here
8
    )
8
    )
9
9
10
    image_source = []
10
    image_source = []
11
    ctx.path.get_bld().make_node("hints").mkdir()    # create 'hints' directory
11
    ctx.path.get_bld().make_node("hints").mkdir()  # create 'hints' directory
12
    for dir in ["icons", "pic"]:
12
    for dir in ["icons", "pic"]:
13
13
14
        files = ctx.path.ant_glob('%s/*' % dir)      # Find images
14
        files = ctx.path.ant_glob("%s/*" % dir)  # Find images
15
        ctx.path.get_bld().make_node(dir).mkdir()    # create 'pic' directory
15
        ctx.path.get_bld().make_node(dir).mkdir()  # create 'pic' directory
16
        image_source += files
16
        image_source += files
17
17
18
        # Copy images
18
        # Copy images
Lines 20-40 def build(ctx): Link Here
20
            features="subst",
20
            features="subst",
21
            is_copy=True,
21
            is_copy=True,
22
            source=files,
22
            source=files,
23
            target=[ctx.path.find_node(dir).get_bld().make_node(x.name)
23
            target=[ctx.path.find_node(dir).get_bld().make_node(x.name) for x in files],
24
                    for x in files]
25
        )
24
        )
26
25
27
    extra = ["asciidoc.js", "asciidoc.css"]
26
    extra = ["asciidoc.js", "asciidoc.css"]
28
27
29
    # Copy extra files
28
    # Copy extra files
30
    ctx(
29
    ctx(features="subst", is_copy=True, source=extra, target=extra)
31
        features="subst",
32
        is_copy=True,
33
        source=extra,
34
        target=extra
35
    )
36
30
37
    # Install HTML
31
    # Install HTML
38
    ctx.install_files('${HTMLDIR}', extra +
32
    ctx.install_files(
39
                      [x.change_ext(".html").name for x in doc_source])
33
        "${HTMLDIR}", extra + [x.change_ext(".html").name for x in doc_source]
40
    ctx.install_files('${HTMLDIR}', image_source, relative_trick=True)
34
    )
35
    ctx.install_files("${HTMLDIR}", image_source, relative_trick=True)
(-)a/libaes_siv/wscript (-14 / +14 lines)
Lines 1-21 Link Here
1
def build(ctx):
1
def build(ctx):
2
    aes_cflags=['-Wno-shadow',
2
    aes_cflags = [
3
            # '-Wall', '-Wextra', '-Wstrict-prototypes',  # default
3
        "-Wno-shadow",
4
            '-Wconversion',
4
        # '-Wall', '-Wextra', '-Wstrict-prototypes',  # default
5
            '-O3',
5
        "-Wconversion",
6
            '-fomit-frame-pointer',
6
        "-O3",
7
            '-funroll-loops',
7
        "-fomit-frame-pointer",
8
            '-ftree-vectorize',
8
        "-funroll-loops",
9
            '-Wno-inline',  # gcc 10 gives inline warnings?
9
        "-ftree-vectorize",
10
            ]
10
        "-Wno-inline",  # gcc 10 gives inline warnings?
11
11
    ]
12
12
13
    ctx(
13
    ctx(
14
        target='aes_siv',
14
        target="aes_siv",
15
        features='c cstlib',
15
        features="c cstlib",
16
        includes=[ctx.bldnode.parent.abspath()],
16
        includes=[ctx.bldnode.parent.abspath()],
17
        source='aes_siv.c',
17
        source="aes_siv.c",
18
        use='CRYPTO',
18
        use="CRYPTO",
19
        cflags=aes_cflags,
19
        cflags=aes_cflags,
20
    )
20
    )
21
21
(-)a/libntp/wscript (-8 / +14 lines)
Lines 4-9 import waflib Link Here
4
from waflib import Errors, Options
4
from waflib import Errors, Options
5
from waflib.Logs import pprint
5
from waflib.Logs import pprint
6
6
7
7
def build(ctx):
8
def build(ctx):
8
9
9
    libntp_source = [
10
    libntp_source = [
Lines 53-59 def build(ctx): Link Here
53
        use="CRYPTO SSL",
54
        use="CRYPTO SSL",
54
    )
55
    )
55
56
56
    if ctx.env['ntpc'] == 'ffi':
57
    if ctx.env["ntpc"] == "ffi":
57
        # Loadable FFI stub
58
        # Loadable FFI stub
58
        ctx(
59
        ctx(
59
            features="c cshlib",
60
            features="c cshlib",
Lines 61-82 def build(ctx): Link Here
61
            source=["ntp_c.c", "pymodule-mac.c"] + libntp_source_sharable,
62
            source=["ntp_c.c", "pymodule-mac.c"] + libntp_source_sharable,
62
            target="../pylib/ntpc",  # Put the output in the pylib directory
63
            target="../pylib/ntpc",  # Put the output in the pylib directory
63
            use="M RT CRYPTO",
64
            use="M RT CRYPTO",
64
            vnum=ctx.env['ntpcver'],
65
            vnum=ctx.env["ntpcver"],
65
        )
66
        )
66
        ctx.add_post_fun(post)
67
        ctx.add_post_fun(post)
67
    elif ctx.env['ntpc'] == 'ext':
68
    elif ctx.env["ntpc"] == "ext":
68
        # Loadable Python extension
69
        # Loadable Python extension
69
        ctx(
70
        ctx(
70
            features="c cshlib pyext",
71
            features="c cshlib pyext",
71
            install_path='${PYTHONARCHDIR}/ntp',
72
            install_path="${PYTHONARCHDIR}/ntp",
72
            includes=[ctx.bldnode.parent.abspath(), "../include"],
73
            includes=[ctx.bldnode.parent.abspath(), "../include"],
73
            source=["pymodule.c", "pymodule-mac.c"] + libntp_source_sharable,
74
            source=["pymodule.c", "pymodule-mac.c"] + libntp_source_sharable,
74
            target="../pylib/ntpc",  # Put the output in the pylib directory
75
            target="../pylib/ntpc",  # Put the output in the pylib directory
75
            use="M RT CRYPTO",
76
            use="M RT CRYPTO",
76
        )
77
        )
78
    elif "none" == ctx.env["ntpc"]:
79
        return
80
77
81
78
def post(ctx):
82
def post(ctx):
79
    if not (ctx.cmd == 'install' and ctx.env.BIN_LDCONFIG):
83
    if not (ctx.cmd == "install" and ctx.env.BIN_LDCONFIG):
80
        return
84
        return
81
85
82
    destdir = Options.options.destdir
86
    destdir = Options.options.destdir
Lines 92-102 def post(ctx): Link Here
92
96
93
    # Try to run ldconfig.  It is not a fatal error here if it fails, as the
97
    # Try to run ldconfig.  It is not a fatal error here if it fails, as the
94
    # install could be run by a non-root user.
98
    # install could be run by a non-root user.
95
    ldconfig = ' '.join(ctx.env.BIN_LDCONFIG)
99
    ldconfig = " ".join(ctx.env.BIN_LDCONFIG)
96
    try:
100
    try:
97
        out = ctx.cmd_and_log(
101
        out = ctx.cmd_and_log(
98
            ctx.env.BIN_LDCONFIG, output=waflib.Context.STDOUT,
102
            ctx.env.BIN_LDCONFIG,
99
            quiet=waflib.Context.BOTH)
103
            output=waflib.Context.STDOUT,
104
            quiet=waflib.Context.BOTH,
105
        )
100
        pprint("GREEN", "running: %s  OK" % ldconfig)
106
        pprint("GREEN", "running: %s  OK" % ldconfig)
101
    except Errors.WafError as e:
107
    except Errors.WafError as e:
102
        pprint("RED", "running: %s  FAILED" % ldconfig)
108
        pprint("RED", "running: %s  FAILED" % ldconfig)
(-)a/ntpd/wscript (-20 / +22 lines)
Lines 1-4 Link Here
1
2
def build(ctx):
1
def build(ctx):
3
    bldnode = ctx.bldnode.abspath()
2
    bldnode = ctx.bldnode.abspath()
4
3
Lines 15-21 def build(ctx): Link Here
15
        # Generate Bison file first.
14
        # Generate Bison file first.
16
        ctx.add_group()
15
        ctx.add_group()
17
16
18
        keyword_gen_source = ["keyword-gen.c", ]
17
        keyword_gen_source = [
18
            "keyword-gen.c",
19
        ]
19
20
20
        ctx(
21
        ctx(
21
            features="c cprogram",
22
            features="c cprogram",
Lines 35-41 def build(ctx): Link Here
35
            features="c",
36
            features="c",
36
            rule="%s/ntpd/keyword-gen ${SRC} > ${TGT}" % bldnode,
37
            rule="%s/ntpd/keyword-gen ${SRC} > ${TGT}" % bldnode,
37
            source="ntp_parser.tab.h",
38
            source="ntp_parser.tab.h",
38
            target="ntp_keyword.h"
39
            target="ntp_keyword.h",
39
        )
40
        )
40
41
41
        # Make sure ntp_keyword.h is created last.
42
        # Make sure ntp_keyword.h is created last.
Lines 47-66 def build(ctx): Link Here
47
        "ntp_control.c",
48
        "ntp_control.c",
48
        "ntp_filegen.c",
49
        "ntp_filegen.c",
49
        "ntp_leapsec.c",
50
        "ntp_leapsec.c",
50
        "ntp_monitor.c",    # Needed by the restrict code
51
        "ntp_monitor.c",  # Needed by the restrict code
51
        "ntp_recvbuff.c",
52
        "ntp_recvbuff.c",
52
        "ntp_restrict.c",
53
        "ntp_restrict.c",
53
        "ntp_util.c",
54
        "ntp_util.c",
54
    ]
55
    ]
55
56
56
    if not ctx.env.DISABLE_NTS:
57
    if not ctx.env.DISABLE_NTS:
57
      libntpd_source += [
58
        libntpd_source += [
58
        "nts.c",
59
            "nts.c",
59
        "nts_server.c",
60
            "nts_server.c",
60
        "nts_client.c",
61
            "nts_client.c",
61
        "nts_cookie.c",
62
            "nts_cookie.c",
62
        "nts_extens.c",
63
            "nts_extens.c",
63
    ]
64
        ]
64
65
65
    ctx(
66
    ctx(
66
        features="c",
67
        features="c",
Lines 77-88 def build(ctx): Link Here
77
        # use="libntpd_obj bison_obj",
78
        # use="libntpd_obj bison_obj",
78
    )
79
    )
79
80
80
    use_refclock = ""      # XXX: there must be a better way to do this
81
    use_refclock = ""  # XXX: there must be a better way to do this
81
    if ctx.env.REFCLOCK_ENABLE:
82
    if ctx.env.REFCLOCK_ENABLE:
82
83
83
        refclock_source = ["ntp_refclock.c",
84
        refclock_source = ["ntp_refclock.c", "refclock_conf.c"]
84
                           "refclock_conf.c"
85
                           ]
86
85
87
        ctx(
86
        ctx(
88
            target="refclock",
87
            target="refclock",
Lines 117-135 def build(ctx): Link Here
117
        "ntp_timer.c",
116
        "ntp_timer.c",
118
        "ntp_dns.c",
117
        "ntp_dns.c",
119
        "ntpd.c",
118
        "ntpd.c",
120
        ctx.bldnode.parent.find_node("host/ntpd/ntp_parser.tab.c")
119
        ctx.bldnode.parent.find_node("host/ntpd/ntp_parser.tab.c"),
121
    ]
120
    ]
122
121
123
    ctx(
122
    ctx(
124
        features="c rtems_trace cprogram",
123
        features="c rtems_trace cprogram",
125
        includes=[
124
        includes=[
126
            ctx.bldnode.parent.abspath(), "../include",
125
            ctx.bldnode.parent.abspath(),
127
            "%s/host/ntpd/" % ctx.bldnode.parent.abspath(), "." ],
126
            "../include",
128
        install_path='${SBINDIR}',
127
            "%s/host/ntpd/" % ctx.bldnode.parent.abspath(),
128
            ".",
129
        ],
130
        install_path="${SBINDIR}",
129
        source=ntpd_source,
131
        source=ntpd_source,
130
        target="ntpd",
132
        target="ntpd",
131
        use="libntpd_obj ntp M parse RT CAP SECCOMP PTHREAD NTPD "
133
        use="libntpd_obj ntp M parse RT CAP SECCOMP PTHREAD NTPD "
132
            "CRYPTO SSL DNS_SD %s SOCKET NSL SCF" % use_refclock,
134
        "CRYPTO SSL DNS_SD %s SOCKET NSL SCF" % use_refclock,
133
    )
135
    )
134
136
135
    ctx.manpage(8, "ntpd-man.adoc")
137
    ctx.manpage(8, "ntpd-man.adoc")
(-)a/ntpfrob/wscript (-3 / +10 lines)
Lines 1-11 Link Here
1
def build(ctx):
1
def build(ctx):
2
    frob_sources = ['main.c', 'bumpclock.c', 'dump.c', 'jitter.c',
2
    frob_sources = [
3
                    'precision.c', 'pps-api.c', 'tickadj.c']
3
        "main.c",
4
        "bumpclock.c",
5
        "dump.c",
6
        "jitter.c",
7
        "precision.c",
8
        "pps-api.c",
9
        "tickadj.c",
10
    ]
4
11
5
    ctx(
12
    ctx(
6
        features="c cprogram",
13
        features="c cprogram",
7
        includes=[ctx.bldnode.parent.abspath(), "../include"],
14
        includes=[ctx.bldnode.parent.abspath(), "../include"],
8
        install_path='${BINDIR}',
15
        install_path="${BINDIR}",
9
        source=frob_sources,
16
        source=frob_sources,
10
        target="ntpfrob",
17
        target="ntpfrob",
11
        use="M RT",
18
        use="M RT",
(-)a/ntptime/wscript (-1 / +2 lines)
Lines 6-14 def build(ctx): Link Here
6
            includes=[ctx.bldnode.parent.abspath(), "../include"],
6
            includes=[ctx.bldnode.parent.abspath(), "../include"],
7
            source=["ntptime.c"],
7
            source=["ntptime.c"],
8
            use="ntp M RT",
8
            use="ntp M RT",
9
            install_path='${BINDIR}',
9
            install_path="${BINDIR}",
10
        )
10
        )
11
11
12
    ctx.manpage(8, "ntptime-man.adoc")
12
    ctx.manpage(8, "ntptime-man.adoc")
13
13
14
14
# end
15
# end
(-)a/pylib/version.txt.in (+1 lines)
Line 0 Link Here
1
ntpsec-@NTPSEC_VERSION_EXTENDED@
(-)a/pylib/wscript (-41 / +52 lines)
Lines 2-46 from waflib.Logs import pprint Link Here
2
2
3
3
4
def options(opt):
4
def options(opt):
5
    opt.load('python')
5
    opt.load("python")
6
6
7
7
8
def configure(conf):
8
def configure(conf):
9
    conf.load('python')
9
    if conf.env["ntpc"] == "none":
10
        return
11
    conf.load("python")
12
10
    if not conf.env.ENABLE_CROSS:
13
    if not conf.env.ENABLE_CROSS:
11
        conf.check_python_version((2, 6, 0))
14
        conf.check_python_version((2, 6, 0))
12
    conf.check_python_headers(features='pyext')  # Extension-only, no embedded
15
    conf.check_python_headers(features="pyext")  # Extension-only
13
    try:
16
    try:
14
        conf.check_python_module('curses')
17
        conf.check_python_module("curses")
15
        conf.env['PYTHON_CURSES'] = True
18
        conf.env["PYTHON_CURSES"] = True
16
    except conf.errors.ConfigurationError:
19
    except conf.errors.ConfigurationError:
17
        pprint("YELLOW", "WARNING: ntpmon will not be built/installed since "
20
        pprint(
18
               "python curses module was not found")
21
            "YELLOW",
22
            "WARNING: ntpmon will not be built/installed since "
23
            "python curses module was not found",
24
        )
19
    try:
25
    try:
20
        conf.check_python_module('argparse')
26
        conf.check_python_module("argparse")
21
        conf.env['PYTHON_ARGPARSE'] = True
27
        conf.env["PYTHON_ARGPARSE"] = True
22
    except conf.errors.ConfigurationError:
28
    except conf.errors.ConfigurationError:
23
        pprint("YELLOW", "WARNING: ntploggps, ntplogtemp, and ntpviz will not "
29
        pprint(
24
               "be built/installed since python argparse module was not found")
30
            "YELLOW",
31
            "WARNING: ntploggps, ntplogtemp, and ntpviz will not "
32
            "be built/installed since python argparse module was not found",
33
        )
25
    try:
34
    try:
26
        conf.check_python_module('gps', condition="ver >= num(3, 18)")
35
        conf.check_python_module("gps", condition="ver >= num(3, 18)")
27
        conf.env['PYTHON_GPS'] = True
36
        conf.env["PYTHON_GPS"] = True
28
    except conf.errors.ConfigurationError:
37
    except conf.errors.ConfigurationError:
29
        pprint("YELLOW", "WARNING: ntploggps will not be built/installed since "
38
        pprint(
30
               "python gps module >= 3.18 was not found")
39
            "YELLOW",
40
            "WARNING: ntploggps will not be built/installed"
41
            " since python gps module >= 3.18 was not found",
42
        )
31
43
32
44
33
def build(ctx):
45
def build(ctx):
34
    srcnode = ctx.srcnode.make_node('pylib')
46
    ctx(features="subst", source=["version.txt.in"], target=['version.txt'])
35
    bldnode = ctx.bldnode.make_node('pylib')
47
    if ctx.env["ntpc"] == "none":
36
    target1 = bldnode.make_node('control.py')
48
        return
37
    target2 = bldnode.make_node('magic.py')
49
    srcnode = ctx.srcnode.make_node("pylib")
50
    bldnode = ctx.bldnode.make_node("pylib")
51
    target1 = bldnode.make_node("control.py")
52
    target2 = bldnode.make_node("magic.py")
38
53
39
    sources = []
54
    sources = []
40
    if ctx.env['ntpc'] == 'ext':
55
    if ctx.env["ntpc"] == "ext":
41
        sources = srcnode.ant_glob("*.py", excl='ntpc.py')
56
        sources = srcnode.ant_glob("*.py", excl="ntpc.py")
42
    elif ctx.env['ntpc'] == 'ffi':
57
    elif ctx.env["ntpc"] == "ffi":
43
        sources = srcnode.ant_glob('*.py')
58
        sources = srcnode.ant_glob("*.py")
44
    builds = [x.get_bld() for x in sources]
59
    builds = [x.get_bld() for x in sources]
45
60
46
    # The rm's here were added to fix a reported (but underdocumented) problem
61
    # The rm's here were added to fix a reported (but underdocumented) problem
Lines 52-64 def build(ctx): Link Here
52
    # including during 'install'. They are now disabled but retained as a
67
    # including during 'install'. They are now disabled but retained as a
53
    # comment.
68
    # comment.
54
69
55
    ## Remove generated files to ensure they are properly updated
70
    # # Remove generated files to ensure they are properly updated
56
    #ctx.exec_command("rm -f %s" % target1.abspath())
71
    # ctx.exec_command("rm -f %s" % target1.abspath())
57
    #ctx.exec_command("rm -f %s" % target2.abspath())
72
    # ctx.exec_command("rm -f %s" % target2.abspath())
58
73
59
    if ctx.env['ntpc'] is None:
74
    if ctx.env["ntpc"] is None:
60
        return
75
        return
61
        
76
62
    # Make sure Python sees .py as well as .pyc/.pyo
77
    # Make sure Python sees .py as well as .pyc/.pyo
63
    ctx(
78
    ctx(
64
        features="subst",
79
        features="subst",
Lines 67-83 def build(ctx): Link Here
67
    )
82
    )
68
83
69
    ctx(
84
    ctx(
70
        before=['pyc', 'pyo'],
85
        before=["pyc", "pyo"],
71
        cwd=srcnode,
86
        cwd=srcnode,
72
        rule='${PYTHON} ${SRC} >${TGT}',
87
        rule="${PYTHON} ${SRC} >${TGT}",
73
        source=["../wafhelpers/pythonize-header", "../include/ntp_control.h"],
88
        source=["../wafhelpers/pythonize-header", "../include/ntp_control.h"],
74
        target=target1,
89
        target=target1,
75
    )
90
    )
76
91
77
    ctx(
92
    ctx(
78
        before=['pyc', 'pyo'],
93
        before=["pyc", "pyo"],
79
        cwd=srcnode,
94
        cwd=srcnode,
80
        rule='${PYTHON} ${SRC} >${TGT}',
95
        rule="${PYTHON} ${SRC} >${TGT}",
81
        source=["../wafhelpers/pythonize-header", "../include/ntp.h"],
96
        source=["../wafhelpers/pythonize-header", "../include/ntp.h"],
82
        target=target2,
97
        target=target2,
83
    )
98
    )
Lines 86-102 def build(ctx): Link Here
86
    ctx.add_group()
101
    ctx.add_group()
87
102
88
    ctx(
103
    ctx(
89
        features='py',
104
        features="py",
90
        source=builds+[target1, target2],
105
        source=builds + [target1, target2],
91
        install_from=bldnode,
106
        install_from=bldnode,
92
        install_path='${PYTHONARCHDIR}/ntp'
107
        install_path="${PYTHONARCHDIR}/ntp",
93
    )
108
    )
94
109
95
    # pep241  lay an egg
110
    # pep241  lay an egg
96
    egg = ['ntp-%s.egg-info' % ctx.env.NTPSEC_VERSION]
111
    egg = ["ntp-%s.egg-info" % ctx.env.NTPSEC_VERSION]
97
    ctx(
112
    ctx(features="subst", source=["ntp-in.egg-info"], target=egg)
98
        features="subst",
99
        source=['ntp-in.egg-info'],
100
        target=egg
101
    )
102
    ctx.install_files(ctx.env.PYTHONARCHDIR, egg)
113
    ctx.install_files(ctx.env.PYTHONARCHDIR, egg)
(-)a/tests/wscript (-29 / +33 lines)
Lines 3-13 from waflib import Utils # pylint: disable=import-error Link Here
3
3
4
4
5
def build(ctx):
5
def build(ctx):
6
    testsrc = ctx.srcnode.make_node('tests')
7
    pylib = ctx.srcnode.make_node('pylib')
8
    testpylib = testsrc.make_node('pylib')
9
    testpysrc = testpylib.ant_glob('*.py')
10
11
    # Unity source
6
    # Unity source
12
    unity_source = [
7
    unity_source = [
13
        "unity/unity.c",
8
        "unity/unity.c",
Lines 17-28 def build(ctx): Link Here
17
12
18
    unity_config = ["UNITY_INCLUDE_DOUBLE", "UNITY_SUPPORT_64"]
13
    unity_config = ["UNITY_INCLUDE_DOUBLE", "UNITY_SUPPORT_64"]
19
14
20
    ctx(
15
    ctx(defines=unity_config, features="c", target="unity", source=unity_source)
21
        defines=unity_config,
22
        features="c",
23
        target="unity",
24
        source=unity_source
25
    )
26
16
27
    # Test main.
17
    # Test main.
28
    common_source = [
18
    common_source = [
Lines 52-58 def build(ctx): Link Here
52
        "libntp/strtolfp.c",
42
        "libntp/strtolfp.c",
53
        "libntp/timespecops.c",
43
        "libntp/timespecops.c",
54
        "libntp/vi64ops.c",
44
        "libntp/vi64ops.c",
55
        "libntp/ymd2yd.c"
45
        "libntp/ymd2yd.c",
56
    ] + common_source
46
    ] + common_source
57
47
58
    ctx.ntp_test(
48
    ctx.ntp_test(
Lines 95-125 def build(ctx): Link Here
95
    ] + common_source
85
    ] + common_source
96
86
97
    if not ctx.env.DISABLE_NTS:
87
    if not ctx.env.DISABLE_NTS:
98
      ntpd_source += [
88
        ntpd_source += [
99
        "ntpd/nts.c",
89
            "ntpd/nts.c",
100
        "ntpd/nts_client.c",
90
            "ntpd/nts_client.c",
101
        "ntpd/nts_server.c",
91
            "ntpd/nts_server.c",
102
        "ntpd/nts_cookie.c",
92
            "ntpd/nts_cookie.c",
103
        "ntpd/nts_extens.c",
93
            "ntpd/nts_extens.c",
104
    ]
94
        ]
105
95
106
    ctx.ntp_test(
96
    ctx.ntp_test(
107
        defines=unity_config + ["TEST_NTPD=1"],
97
        defines=unity_config + ["TEST_NTPD=1"],
108
        features="c cprogram test",
98
        features="c cprogram test",
109
        includes=[ctx.bldnode.parent.abspath(), "../include", "unity", "../ntpd", "common", "../libaes_siv"],
99
        includes=[
100
            ctx.bldnode.parent.abspath(),
101
            "../include",
102
            "unity",
103
            "../ntpd",
104
            "common",
105
            "../libaes_siv",
106
        ],
110
        install_path=None,
107
        install_path=None,
111
        source=ntpd_source,
108
        source=ntpd_source,
112
        target="test_ntpd",
109
        target="test_ntpd",
113
        use="ntpd_lib libntpd_obj unity ntp aes_siv "
110
        use="ntpd_lib libntpd_obj unity ntp aes_siv " "M PTHREAD CRYPTO RT SOCKET NSL",
114
            "M PTHREAD CRYPTO RT SOCKET NSL",
115
    )
111
    )
116
112
113
    if "none" == ctx.env["ntpc"]:
114
        return
115
    testsrc = ctx.srcnode.make_node("tests")
116
    pylib = ctx.srcnode.make_node("pylib")
117
    testpylib = testsrc.make_node("pylib")
118
    testpysrc = testpylib.ant_glob("*.py")
117
    testpylib.get_bld().mkdir()
119
    testpylib.get_bld().mkdir()
118
120
119
    pypath = pylib.get_bld()
121
    pypath = pylib.get_bld()
120
    targdir = "tests/pylib"
122
    targdir = "tests/pylib"
121
    linkpath = ctx.bldnode.make_node(targdir + "/ntp").abspath()
123
    linkpath = ctx.bldnode.make_node(targdir + "/ntp").abspath()
122
    relpath = ("../" * (targdir.count("/")+1)) + pypath.path_from(ctx.bldnode)
124
    relpath = ("../" * (targdir.count("/") + 1)) + pypath.path_from(ctx.bldnode)
123
    if (not os.path.exists(linkpath)) or os.readlink(linkpath) != relpath:
125
    if (not os.path.exists(linkpath)) or os.readlink(linkpath) != relpath:
124
        try:
126
        try:
125
            os.remove(linkpath)
127
            os.remove(linkpath)
Lines 127-138 def build(ctx): Link Here
127
            pass
129
            pass
128
        os.symlink(relpath, linkpath)
130
        os.symlink(relpath, linkpath)
129
131
130
    pytests = ["pylib/test_util.py",
132
    pytests = [
131
               "pylib/test_agentx.py",
133
        "pylib/test_util.py",
132
               "pylib/test_agentx_packet.py",
134
        "pylib/test_agentx.py",
133
               "pylib/test_ntpc.py",
135
        "pylib/test_agentx_packet.py",
134
               "pylib/test_packet.py",
136
        "pylib/test_ntpc.py",
135
               "pylib/test_statfiles.py"]
137
        "pylib/test_packet.py",
138
        "pylib/test_statfiles.py",
139
    ]
136
140
137
    ctx(
141
    ctx(
138
        features="subst",
142
        features="subst",
(-)a/wafhelpers/bin_test.py (-35 / +29 lines)
Lines 2-8 Link Here
2
from __future__ import print_function
2
from __future__ import print_function
3
import os
3
import os
4
import os.path
4
import os.path
5
import sys
5
6
# import sys
6
import waflib.Context
7
import waflib.Context
7
import waflib.Logs
8
import waflib.Logs
8
import waflib.Utils
9
import waflib.Utils
Lines 13-19 cmd_map = { Link Here
13
    ("main/ntpclients/ntpleapfetch", "--version"): "ntpleapfetch %s\n",
14
    ("main/ntpclients/ntpleapfetch", "--version"): "ntpleapfetch %s\n",
14
    ("main/ntpd/ntpd", "--version"): "ntpd %s\n",
15
    ("main/ntpd/ntpd", "--version"): "ntpd %s\n",
15
    ("main/ntpfrob/ntpfrob", "-V"): "ntpfrob %s\n",
16
    ("main/ntpfrob/ntpfrob", "-V"): "ntpfrob %s\n",
16
    ("main/ntptime/ntptime", "-V"): "ntptime %s\n"
17
    ("main/ntptime/ntptime", "-V"): "ntptime %s\n",
17
}
18
}
18
cmd_map_python = {
19
cmd_map_python = {
19
    ("main/ntpclients/ntpdig", "--version"): "ntpdig %s\n",
20
    ("main/ntpclients/ntpdig", "--version"): "ntpdig %s\n",
Lines 22-28 cmd_map_python = { Link Here
22
    ("main/ntpclients/ntpsnmpd", "--version"): "ntpsnmpd %s\n",
23
    ("main/ntpclients/ntpsnmpd", "--version"): "ntpsnmpd %s\n",
23
    ("main/ntpclients/ntpsweep", "--version"): "ntpsweep %s\n",
24
    ("main/ntpclients/ntpsweep", "--version"): "ntpsweep %s\n",
24
    ("main/ntpclients/ntptrace", "--version"): "ntptrace %s\n",
25
    ("main/ntpclients/ntptrace", "--version"): "ntptrace %s\n",
25
    ("main/ntpclients/ntpwait", "--version"): "ntpwait %s\n"
26
    ("main/ntpclients/ntpwait", "--version"): "ntpwait %s\n",
26
}
27
}
27
# Need argparse
28
# Need argparse
28
cmd_map_python_argparse = {
29
cmd_map_python_argparse = {
Lines 57-71 def run(cmd, expected, python=None): Link Here
57
        addLog("YELLOW", prefix + " SKIPPING (does not exist)")
58
        addLog("YELLOW", prefix + " SKIPPING (does not exist)")
58
        return False
59
        return False
59
60
61
    envy = {}
60
    if python:
62
    if python:
61
        cmd = python + list(cmd)
63
        cmd = python + list(cmd)
62
    p = Popen(cmd, env={'PYTHONPATH': '%s/main/tests/pylib' %
64
        envy = {"PYTHONPATH": waflib.Context.out_dir + "/main/tests/pylib"}
63
                        waflib.Context.out_dir},
65
    p = Popen(
64
              universal_newlines=True,
66
        cmd,
65
              stdin=waflib.Utils.subprocess.PIPE,
67
        env=envy,
66
              stdout=waflib.Utils.subprocess.PIPE,
68
        universal_newlines=True,
67
              stderr=waflib.Utils.subprocess.PIPE,
69
        stdin=waflib.Utils.subprocess.PIPE,
68
              cwd=waflib.Context.out_dir)
70
        stdout=waflib.Utils.subprocess.PIPE,
71
        stderr=waflib.Utils.subprocess.PIPE,
72
        cwd=waflib.Context.out_dir,
73
    )
69
74
70
    stdout, stderr = p.communicate()
75
    stdout, stderr = p.communicate()
71
76
Lines 73-116 def run(cmd, expected, python=None): Link Here
73
        addLog("GREEN", prefix + "  OK")
78
        addLog("GREEN", prefix + "  OK")
74
        return True
79
        return True
75
    addLog("RED", prefix + "  FAILED")
80
    addLog("RED", prefix + "  FAILED")
76
    addLog("PINK", "Expected: " + expected)
81
    addLog("PINK", "Expected: '%s'" % expected)
77
    if stdout:
82
    if stdout:
78
        addLog("PINK", "Got (stdout): " + stdout)
83
        addLog("PINK", "Got (stdout): '%s'" % stdout)
79
    if stderr:
84
    if stderr:
80
        addLog("PINK", "Got (stderr): " + stderr)
85
        addLog("PINK", "Got (stderr): '%s'" % stderr)
81
    return False
86
    return False
82
87
83
88
84
def cmd_bin_test(ctx):
89
def cmd_bin_test(ctx):
85
    """Run a suite of binary tests."""
90
    """Run a suite of binary tests."""
86
    fails = 0
91
    fails = 0
87
92
    with open(waflib.Context.out_dir + "/main/pylib/version.txt") as fp:
88
    cmd = ctx.env['PYTHON'] + ['-c',
93
        version = fp.read().strip(' \n')
89
        'from __future__ import print_function;'
94
90
        'import ntp.util;'
95
    if not os.path.isdir(waflib.Context.out_dir + "/main/tests/pylib"):
91
        'print(ntp.util.stdversion())']
96
        if ctx.env["PYTHON_ARGPARSE"]:
92
    p = waflib.Utils.subprocess.Popen(cmd, env={'PYTHONPATH': '%s/main/tests/pylib' %
97
            cmd_map_python.update(cmd_map_python_argparse)
93
                                                 waflib.Context.out_dir},
98
        if ctx.env["PYTHON_CURSES"]:
94
                         universal_newlines=True,
99
            cmd_map_python.update(cmd_map_python_curses)
95
                         stdin=waflib.Utils.subprocess.PIPE,
100
        for cmd in sorted(cmd_map_python):
96
                         stdout=waflib.Utils.subprocess.PIPE,
101
            if not run(cmd, cmd_map_python[cmd] % version, ctx.env["PYTHON"]):
97
                         stderr=waflib.Utils.subprocess.PIPE, cwd=waflib.Context.out_dir)
102
                fails += 1
98
    version = p.communicate()[0].rstrip()
99
100
    if ctx.env['PYTHON_ARGPARSE']:
101
        cmd_map_python.update(cmd_map_python_argparse)
102
103
    if ctx.env['PYTHON_CURSES']:
104
        cmd_map_python.update(cmd_map_python_curses)
105
103
106
    for cmd in sorted(cmd_map):
104
    for cmd in sorted(cmd_map):
107
        if not run(cmd, cmd_map[cmd] % version):
105
        if not run(cmd, cmd_map[cmd] % version):
108
            fails += 1
106
            fails += 1
109
107
110
    for cmd in sorted(cmd_map_python):
111
        if not run(cmd, cmd_map_python[cmd] % version, ctx.env['PYTHON']):
112
            fails += 1
113
114
    if 1 == fails:
108
    if 1 == fails:
115
        bin_test_summary(ctx)
109
        bin_test_summary(ctx)
116
        ctx.fatal("1 binary test failed!")
110
        ctx.fatal("1 binary test failed!")
(-)a/wscript (-282 / +351 lines)
Lines 1-18 Link Here
1
from __future__ import print_function
1
from __future__ import print_function
2
2
3
from datetime import datetime
3
# from datetime import datetime
4
import itertools
4
import itertools
5
import os
5
import os
6
import shlex
6
import shlex
7
import sys
7
import sys
8
import time
8
9
# import time
9
10
10
from waflib import Build
11
from waflib import Build
11
from waflib import Context
12
from waflib import Context
12
from waflib import Scripting
13
from waflib import Scripting
13
from waflib import Utils
14
from waflib import Utils
14
from waflib.Build import (BuildContext, CleanContext, InstallContext,
15
from waflib.Build import (
15
                          StepContext, ListContext)
16
    BuildContext,
17
    CleanContext,
18
    InstallContext,
19
    StepContext,
20
    ListContext,
21
)
16
from waflib.Context import BOTH
22
from waflib.Context import BOTH
17
from waflib.Errors import WafError
23
from waflib.Errors import WafError
18
from waflib.Logs import pprint
24
from waflib.Logs import pprint
Lines 28-46 from wafhelpers.test import test_write_log, test_print_log Link Here
28
34
29
pprint.__doc__ = None
35
pprint.__doc__ = None
30
36
31
APPNAME = 'ntpsec'
37
APPNAME = "ntpsec"
32
38
33
out = "build"
39
out = "build"
34
40
35
config = {
41
config = {"out": out, "OPT_STORE": {}}
36
    "out": out,
37
    "OPT_STORE": {}
38
}
39
42
40
43
41
def help(ctx):
44
def help(ctx):
42
    "Be helpful, give a usage"
45
    "Be helpful, give a usage"
43
    print('''
46
    print(
47
        """
44
Usage: waf <command>
48
Usage: waf <command>
45
    build       Build the project
49
    build       Build the project
46
    check       Run tests
50
    check       Run tests
Lines 50-85 Usage: waf <command> Link Here
50
    loccount    Show SLOC count of the source tree
54
    loccount    Show SLOC count of the source tree
51
    uninstall   Uninstall the project
55
    uninstall   Uninstall the project
52
56
53
''')
57
"""
58
    )
54
59
55
60
56
def options(ctx):
61
def options(ctx):
57
    options_cmd(ctx, config)
62
    options_cmd(ctx, config)
58
    ctx.load('asciidoc', tooldir='wafhelpers/')
63
    ctx.load("asciidoc", tooldir="wafhelpers/")
59
    ctx.recurse("pylib")
64
    ctx.recurse("pylib")
60
65
61
66
62
def configure(ctx):
67
def configure(ctx):
63
    ctx.load('asciidoc', tooldir='wafhelpers/')
68
    ctx.load("asciidoc", tooldir="wafhelpers/")
64
69
65
    class oc(Build.BuildContext):
70
    class oc(Build.BuildContext):
66
        cmd = 'oc'
71
        cmd = "oc"
67
72
68
        def exec_command(self, cmd, **kw):
73
        def exec_command(self, cmd, **kw):
69
            kw['output'] = BOTH
74
            kw["output"] = BOTH
70
            try:
75
            try:
71
                err, out = self.cmd_and_log(cmd, **kw)
76
                err, out = self.cmd_and_log(cmd, **kw)
72
            except WafError as e:
77
            except WafError as e:
73
                self.logger.debug('WafError')
78
                self.logger.debug("WafError")
74
                return e.returncode
79
                return e.returncode
75
            if (len(out) and any(word in out for word
80
            if len(out) and any(
76
                                 in ['err', 'err:', 'error', 'error:',
81
                word in out
77
                                     'ignored', 'illegal', 'unknown',
82
                for word in [
78
                                     'unrecognized', 'warning'])):
83
                    "err",
79
                self.logger.debug('noooo %r' % out)
84
                    "err:",
85
                    "error",
86
                    "error:",
87
                    "ignored",
88
                    "illegal",
89
                    "unknown",
90
                    "unrecognized",
91
                    "warning",
92
                ]
93
            ):
94
                self.logger.debug("noooo %r" % out)
80
                return 1
95
                return 1
81
            if err:
96
            if err:
82
                self.logger.debug('noooo %r' % err)
97
                self.logger.debug("noooo %r" % err)
83
                return 1
98
                return 1
84
            return 0
99
            return 0
85
100
Lines 93-102 def configure(ctx): Link Here
93
    srcnode = ctx.srcnode.abspath()
108
    srcnode = ctx.srcnode.abspath()
94
    bldnode = ctx.bldnode.abspath()
109
    bldnode = ctx.bldnode.abspath()
95
110
96
    ctx.run_build_cls = 'check'
111
    ctx.run_build_cls = "check"
97
    ctx.load('waf', tooldir='wafhelpers/')
112
    ctx.load("waf", tooldir="wafhelpers/")
98
    ctx.load('waf_unit_test')
113
    ctx.load("waf_unit_test")
99
    ctx.load('gnu_dirs')
114
    ctx.load("gnu_dirs")
100
115
101
    with open("VERSION", "r") as f:
116
    with open("VERSION", "r") as f:
102
        ntpsec_release = f.read().split(" ")[0].strip()
117
        ntpsec_release = f.read().split(" ")[0].strip()
Lines 120-160 def configure(ctx): Link Here
120
            opt = flag.replace("--", "").upper()
135
            opt = flag.replace("--", "").upper()
121
            opt_map[opt] = ctx.env.OPT_STORE[flag]
136
            opt_map[opt] = ctx.env.OPT_STORE[flag]
122
137
123
    ctx.env['ntpc'] = ctx.options.enable_pylib
138
    ctx.env["ntpc"] = ctx.options.enable_pylib
124
    ctx.env['ntpcver'] = '1.1.0'
139
    ctx.env["ntpcver"] = "1.1.0"
125
140
126
    msg("--- Configuring host ---")
141
    msg("--- Configuring host ---")
127
    ctx.setenv('host', ctx.env.derive())
142
    ctx.setenv("host", ctx.env.derive())
128
143
129
    ctx.load('compiler_c')
144
    ctx.load("compiler_c")
130
    ctx.start_msg('Checking compiler version')
145
    ctx.start_msg("Checking compiler version")
131
    ctx.end_msg("%s" % ".".join(ctx.env.CC_VERSION))
146
    ctx.end_msg("%s" % ".".join(ctx.env.CC_VERSION))
132
147
133
    # Some distros do not have /sbin in the PATH for non-root users.  We honor
148
    # Some distros do not have /sbin in the PATH for non-root users.  We honor
134
    # the real PATH first, but append the sbin directories.
149
    # the real PATH first, but append the sbin directories.
135
    ctx.find_program(
150
    ctx.find_program(
136
        "ldconfig", var="BIN_LDCONFIG", mandatory=False,
151
        "ldconfig",
137
        path_list=(os.environ.get('PATH','').split(os.pathsep) +
152
        var="BIN_LDCONFIG",
138
            ["/sbin", "/usr/sbin", "/usr/local/sbin"]))
153
        mandatory=False,
154
        path_list=(
155
            os.environ.get("PATH", "").split(os.pathsep)
156
            + ["/sbin", "/usr/sbin", "/usr/local/sbin"]
157
        ),
158
    )
139
159
140
    # Ensure m4 is present, or bison will fail with SIGPIPE
160
    # Ensure m4 is present, or bison will fail with SIGPIPE
141
    ctx.find_program('m4')
161
    ctx.find_program("m4")
142
    ctx.load('bison')
162
    ctx.load("bison")
143
163
144
    for opt in opt_map:
164
    for opt in opt_map:
145
        ctx.env[opt] = opt_map[opt]
165
        ctx.env[opt] = opt_map[opt]
146
166
147
    if ctx.options.enable_rtems_trace:
167
    if ctx.options.enable_rtems_trace:
148
        ctx.find_program("rtems-tld", var="BIN_RTEMS_TLD",
168
        ctx.find_program(
149
                         path_list=[ctx.options.rtems_trace_path,
169
            "rtems-tld",
150
                                    '${BINDIR}'])
170
            var="BIN_RTEMS_TLD",
171
            path_list=[ctx.options.rtems_trace_path, "${BINDIR}"],
172
        )
151
        ctx.env.RTEMS_TEST_ENABLE = True
173
        ctx.env.RTEMS_TEST_ENABLE = True
152
        ctx.env.RTEMS_TEST_FLAGS = [
174
        ctx.env.RTEMS_TEST_FLAGS = [
153
            "-C", "%s/devel/trace/ntpsec-trace.ini" % srcnode,
175
            "-C",
154
            "-W", "%s/ntpsec-wrapper" % bldnode,
176
            "%s/devel/trace/ntpsec-trace.ini" % srcnode,
155
            "-P", "%s/devel/trace/" % srcnode,
177
            "-W",
156
            "-f", "-I%s" % bldnode,
178
            "%s/ntpsec-wrapper" % bldnode,
157
            "-f", "-I%s/include/" % srcnode,
179
            "-P",
180
            "%s/devel/trace/" % srcnode,
181
            "-f",
182
            "-I%s" % bldnode,
183
            "-f",
184
            "-I%s/include/" % srcnode,
158
        ]
185
        ]
159
186
160
    # Not needed to build.  Used by utility scripts.
187
    # Not needed to build.  Used by utility scripts.
Lines 162-170 def configure(ctx): Link Here
162
    ctx.find_program("sh", var="BIN_SH", mandatory=False)
189
    ctx.find_program("sh", var="BIN_SH", mandatory=False)
163
190
164
    ctx.check_cfg(
191
    ctx.check_cfg(
165
        package='systemd', variables=['systemdsystemunitdir'],
192
        package="systemd",
166
        uselib_store='SYSTEMD', mandatory=False,
193
        variables=["systemdsystemunitdir"],
167
        msg="Checking for systemd")
194
        uselib_store="SYSTEMD",
195
        mandatory=False,
196
        msg="Checking for systemd",
197
    )
168
    if ctx.env.SYSTEMD_systemdsystemunitdir:
198
    if ctx.env.SYSTEMD_systemdsystemunitdir:
169
        ctx.start_msg("systemd unit directory:")
199
        ctx.start_msg("systemd unit directory:")
170
        ctx.end_msg(ctx.env.SYSTEMD_systemdsystemunitdir)
200
        ctx.end_msg(ctx.env.SYSTEMD_systemdsystemunitdir)
Lines 175-181 def configure(ctx): Link Here
175
205
176
    build_desc = ctx.options.build_desc.strip()
206
    build_desc = ctx.options.build_desc.strip()
177
    if build_desc:
207
    if build_desc:
178
        build_desc = ' ' + build_desc
208
        build_desc = " " + build_desc
179
    if ctx.env.BIN_GIT:
209
    if ctx.env.BIN_GIT:
180
        # 'tag', '7', and 'deadbeef' are fill ins for
210
        # 'tag', '7', and 'deadbeef' are fill ins for
181
        # a previous tag (always dropped), commits since that tag,
211
        # a previous tag (always dropped), commits since that tag,
Lines 189-207 def configure(ctx): Link Here
189
        # 3-4 gets the first token dropped and the rest added
219
        # 3-4 gets the first token dropped and the rest added
190
        # I have never seen 5+ tokens, we should be safe
220
        # I have never seen 5+ tokens, we should be safe
191
        cmd = ctx.env.BIN_GIT + shlex.split("describe --tags --dirty --always")
221
        cmd = ctx.env.BIN_GIT + shlex.split("describe --tags --dirty --always")
192
        git_short_hash = ctx.cmd_and_log(cmd).strip().split('-')
222
        git_short_hash = ctx.cmd_and_log(cmd).strip().split("-")
193
        clip = 1 if len(git_short_hash) > 2 else 0
223
        clip = 1 if len(git_short_hash) > 2 else 0
194
        git_short_hash = '-'.join(git_short_hash[clip:])
224
        git_short_hash = "-".join(git_short_hash[clip:])
195
225
196
        ctx.env.NTPSEC_VERSION = "%s+" % ntpsec_release
226
        ctx.env.NTPSEC_VERSION = "%s+" % ntpsec_release
197
        ctx.env.NTPSEC_VERSION_EXTENDED = ("%s+%s%s" %
227
        ctx.env.NTPSEC_VERSION_EXTENDED = "%s+%s%s" % (
198
                                           (ntpsec_release,
228
            ntpsec_release,
199
                                            git_short_hash,
229
            git_short_hash,
200
                                            build_desc))
230
            build_desc,
231
        )
201
    else:
232
    else:
202
        ctx.env.NTPSEC_VERSION = "%s" % ntpsec_release
233
        ctx.env.NTPSEC_VERSION = "%s" % ntpsec_release
203
        ctx.env.NTPSEC_VERSION_EXTENDED = ("%s%s" % (ntpsec_release,
234
        ctx.env.NTPSEC_VERSION_EXTENDED = "%s%s" % (ntpsec_release, build_desc)
204
                                                      build_desc))
205
    ctx.define("NTPSEC_VERSION", ctx.env.NTPSEC_VERSION)
235
    ctx.define("NTPSEC_VERSION", ctx.env.NTPSEC_VERSION)
206
    ctx.define("NTPSEC_VERSION_EXTENDED", ctx.env.NTPSEC_VERSION_EXTENDED)
236
    ctx.define("NTPSEC_VERSION_EXTENDED", ctx.env.NTPSEC_VERSION_EXTENDED)
207
237
Lines 239-245 def configure(ctx): Link Here
239
        ctx.env.ENABLE_CROSS = True
269
        ctx.env.ENABLE_CROSS = True
240
270
241
        ctx.start_msg("Using Cross compiler CC:")
271
        ctx.start_msg("Using Cross compiler CC:")
242
#           ctx.get_cc_version(ctx.env.CC, gcc=True)
272
        #           ctx.get_cc_version(ctx.env.CC, gcc=True)
243
        ctx.end_msg(ctx.options.cross_compiler)
273
        ctx.end_msg(ctx.options.cross_compiler)
244
274
245
        ctx.env.CC = shlex.split(ctx.options.cross_compiler)
275
        ctx.env.CC = shlex.split(ctx.options.cross_compiler)
Lines 257-262 def configure(ctx): Link Here
257
287
258
    if ctx.options.list:
288
    if ctx.options.list:
259
        from wafhelpers.refclock import refclock_map
289
        from wafhelpers.refclock import refclock_map
290
260
        print("ID    Description")
291
        print("ID    Description")
261
        print("~~    ~~~~~~~~~~~")
292
        print("~~    ~~~~~~~~~~~")
262
        for id in refclock_map:
293
        for id in refclock_map:
Lines 270-308 def configure(ctx): Link Here
270
        ctx.define("WORDS_BIGENDIAN", 1)
301
        ctx.define("WORDS_BIGENDIAN", 1)
271
302
272
    if ctx.options.enable_leap_testing:
303
    if ctx.options.enable_leap_testing:
273
        ctx.define("ENABLE_LEAP_TESTING", 1,
304
        ctx.define(
274
                   comment="Enable leap seconds on other than 1st of month.")
305
            "ENABLE_LEAP_TESTING",
306
            1,
307
            comment="Enable leap seconds on other than 1st of month.",
308
        )
275
309
276
    # check for some libs first.  some options, like stack protector,
310
    # check for some libs first.  some options, like stack protector,
277
    # may depend on some libs, like -lssp
311
    # may depend on some libs, like -lssp
278
    ctx.check_cc(lib="m", comment="Math library")
312
    ctx.check_cc(lib="m", comment="Math library")
279
    ctx.check_cc(lib="rt", mandatory=False, comment="realtime library")
313
    ctx.check_cc(lib="rt", mandatory=False, comment="realtime library")
280
    ctx.check_cc(lib="pthread", mandatory=False, comment="threads library")
314
    ctx.check_cc(lib="pthread", mandatory=False, comment="threads library")
281
    ctx.check_cc(lib="execinfo", mandatory=False,
315
    ctx.check_cc(lib="execinfo", mandatory=False, comment="BSD backtrace library")
282
                 comment="BSD backtrace library")
316
    ret = ctx.check_cc(lib="bsd", mandatory=False, comment="BSD compatibility library")
283
    ret = ctx.check_cc(lib="bsd", mandatory=False,
284
                       comment="BSD compatibility library")
285
    if ret:
317
    if ret:
286
        ctx.env.LDFLAGS += ["-lbsd"]
318
        ctx.env.LDFLAGS += ["-lbsd"]
287
319
288
    # -lssp and -lssp_nonshared may be needed by older gcc to
320
    # -lssp and -lssp_nonshared may be needed by older gcc to
289
    # support "-fstack-protector-all"
321
    # support "-fstack-protector-all"
290
    ret = ctx.check_cc(lib="ssp", mandatory=False,
322
    ret = ctx.check_cc(lib="ssp", mandatory=False, comment="libssp")
291
                       comment="libssp")
292
    if ret:
323
    if ret:
293
        ctx.env.LDFLAGS += ["-lssp"]
324
        ctx.env.LDFLAGS += ["-lssp"]
294
325
295
    ret = ctx.check_cc(lib="ssp_nonshared", mandatory=False,
326
    ret = ctx.check_cc(lib="ssp_nonshared", mandatory=False, comment="libssp_nonshared")
296
                       comment="libssp_nonshared")
297
    if ret:
327
    if ret:
298
        ctx.env.LDFLAGS += ["-lssp_nonshared"]
328
        ctx.env.LDFLAGS += ["-lssp_nonshared"]
299
329
300
    cc_test_flags = [
330
    cc_test_flags = [
301
        ('f_stack_protector_all', '-fstack-protector-all'),
331
        ("f_stack_protector_all", "-fstack-protector-all"),
302
        ('PIC', '-fPIC'),
332
        ("PIC", "-fPIC"),
303
        ('PIE', '-pie -fPIE'),
333
        ("PIE", "-pie -fPIE"),
304
        # this quiets most of macOS warnings on -fpie
334
        # this quiets most of macOS warnings on -fpie
305
        ('unused', '-Qunused-arguments'),
335
        ("unused", "-Qunused-arguments"),
306
        # This is a useless warning on any architecture with a barrel
336
        # This is a useless warning on any architecture with a barrel
307
        # shifter, which includes Intel and ARM and basically
337
        # shifter, which includes Intel and ARM and basically
308
        # everything nowadays. Even so, we'd enable it out of
338
        # everything nowadays. Even so, we'd enable it out of
Lines 310-338 def configure(ctx): Link Here
310
        # useful for forcing structure alignment in order to suppress
340
        # useful for forcing structure alignment in order to suppress
311
        # it locally don't seem to be working quite right.
341
        # it locally don't seem to be working quite right.
312
        # ('w_cast_align', "-Wcast-align"),
342
        # ('w_cast_align', "-Wcast-align"),
313
        ('w_cast_qual', "-Wcast-qual"),
343
        ("w_cast_qual", "-Wcast-qual"),
314
        ('w_disabled_optimization', "-Wdisabled-optimization"),
344
        ("w_disabled_optimization", "-Wdisabled-optimization"),
315
        ('w_float_equal', "-Wfloat-equal"),
345
        ("w_float_equal", "-Wfloat-equal"),
316
        ('w_format', '-Wformat'),
346
        ("w_format", "-Wformat"),
317
        ('w_format_security', '-Wformat-security'),
347
        ("w_format_security", "-Wformat-security"),
318
        # fails on OpenBSD 6
348
        # fails on OpenBSD 6
319
        ('w_format_signedness', '-Wformat-signedness'),
349
        ("w_format_signedness", "-Wformat-signedness"),
320
        ('w_implicit_function_declaration', "-Wimplicit-function-declaration"),
350
        ("w_implicit_function_declaration", "-Wimplicit-function-declaration"),
321
        ('w_init_self', '-Winit-self'),
351
        ("w_init_self", "-Winit-self"),
322
        ('w_invalid_pch', '-Winvalid-pch'),
352
        ("w_invalid_pch", "-Winvalid-pch"),
323
        ('w_missing_declarations', '-Wmissing-declarations'),
353
        ("w_missing_declarations", "-Wmissing-declarations"),
324
        ('w_multichar', '-Wmultichar'),
354
        ("w_multichar", "-Wmultichar"),
325
        ('w_packed', '-Wpacked'),
355
        ("w_packed", "-Wpacked"),
326
        ('w_pointer_arith', '-Wpointer-arith'),
356
        ("w_pointer_arith", "-Wpointer-arith"),
327
        ('w_shadow', '-Wshadow'),
357
        ("w_shadow", "-Wshadow"),
328
        # fails on clang
358
        # fails on clang
329
        ('w_suggest_attribute_noreturn', "-Wsuggest-attribute=noreturn"),
359
        ("w_suggest_attribute_noreturn", "-Wsuggest-attribute=noreturn"),
330
        ('w_write_strings', '-Wwrite-strings'),
360
        ("w_write_strings", "-Wwrite-strings"),
331
        ]
361
    ]
332
362
333
    # Check which linker flags are supported
363
    # Check which linker flags are supported
334
    ld_hardening_flags = [
364
    ld_hardening_flags = [
335
        ("z_now", "-Wl,-z,now"),     # no deferred symbol resolution
365
        ("z_now", "-Wl,-z,now"),  # no deferred symbol resolution
336
    ]
366
    ]
337
367
338
    # we prepend our options to CFLAGS, this allows user provided
368
    # we prepend our options to CFLAGS, this allows user provided
Lines 343-353 def configure(ctx): Link Here
343
    else:
373
    else:
344
        # not gdb debugging
374
        # not gdb debugging
345
        cc_test_flags += [
375
        cc_test_flags += [
346
            ('LTO', '-flto'),                   # link time optimization
376
            ("LTO", "-flto"),  # link time optimization
347
            ]
377
        ]
348
        ld_hardening_flags += [
378
        ld_hardening_flags += [
349
            ('stripall', "-Wl,--strip-all"),    # Strip binaries
379
            ("stripall", "-Wl,--strip-all"),  # Strip binaries
350
            ]
380
        ]
351
381
352
    if ctx.options.enable_debug:
382
    if ctx.options.enable_debug:
353
        ctx.define("DEBUG", 1, comment="Enable debug mode")
383
        ctx.define("DEBUG", 1, comment="Enable debug mode")
Lines 361-375 def configure(ctx): Link Here
361
            # "-Wcast-align",         # fails on RasPi, needs fixing.
391
            # "-Wcast-align",         # fails on RasPi, needs fixing.
362
            # "-Wbad-function-cast",  # ntpd casts long<->double a lot
392
            # "-Wbad-function-cast",  # ntpd casts long<->double a lot
363
            # "-Wformat-nonliteral",  # complains about a used feature
393
            # "-Wformat-nonliteral",  # complains about a used feature
364
            "-Winline",               # some OS have inline issues.
394
            "-Winline",  # some OS have inline issues.
365
            # "-Wmissing-format-attribute", # false positives
395
            # "-Wmissing-format-attribute", # false positives
366
            # "-Wnested-externs",     # incompatible w/ Unity...
396
            # "-Wnested-externs",     # incompatible w/ Unity...
367
            # "-Wpadded",             # duck... over 3k warnings
397
            # "-Wpadded",             # duck... over 3k warnings
368
            # "-Wredundant-decls",    # incompatible w/ Unity
398
            # "-Wredundant-decls",    # incompatible w/ Unity
369
            "-Wswitch-default",       # warns on Bison bug
399
            "-Wswitch-default",  # warns on Bison bug
370
        ] + ctx.env.CFLAGS
400
        ] + ctx.env.CFLAGS
371
        cc_test_flags += [
401
        cc_test_flags += [
372
            ('w_implicit_fallthru', "-Wimplicit-fallthrough=3"),
402
            ("w_implicit_fallthru", "-Wimplicit-fallthrough=3"),
373
            # Fails on Solaris, OpenBSD 6, and RasPi
403
            # Fails on Solaris, OpenBSD 6, and RasPi
374
            # Complains about a Bison bug
404
            # Complains about a Bison bug
375
            # Cannot be suppressed
405
            # Cannot be suppressed
Lines 378-384 def configure(ctx): Link Here
378
            # ('w_suggest_attribute_const', "-Wsuggest-attribute=const"),
408
            # ('w_suggest_attribute_const', "-Wsuggest-attribute=const"),
379
            # fails on clang, lot's of false positives and Unity complaints
409
            # fails on clang, lot's of false positives and Unity complaints
380
            # ('w_suggest_attribute_pure', "-Wsuggest-attribute=pure"),
410
            # ('w_suggest_attribute_pure', "-Wsuggest-attribute=pure"),
381
            ]
411
        ]
382
412
383
    ctx.env.CFLAGS = [
413
    ctx.env.CFLAGS = [
384
        # -O1 will turn on -D_FORTIFY_SOURCE=2 for us
414
        # -O1 will turn on -D_FORTIFY_SOURCE=2 for us
Lines 389-416 def configure(ctx): Link Here
389
        "-Wstrict-prototypes",
419
        "-Wstrict-prototypes",
390
        "-Wundef",
420
        "-Wundef",
391
        "-Wunused",
421
        "-Wunused",
392
        ] + ctx.env.CFLAGS
422
    ] + ctx.env.CFLAGS
393
423
394
    # gotta be tricky to test for -Wsuggest-attribute=const
424
    # gotta be tricky to test for -Wsuggest-attribute=const
395
    FRAGMENT = '''
425
    FRAGMENT = """
396
int tmp;
426
int tmp;
397
int main(int argc, char **argv) {
427
int main(int argc, char **argv) {
398
        (void)argc; (void)argv;
428
        (void)argc; (void)argv;
399
        tmp = argc;
429
        tmp = argc;
400
        return argc;
430
        return argc;
401
}
431
}
402
'''
432
"""
403
433
404
    # check if C compiler supports some flags
434
    # check if C compiler supports some flags
405
    old_run_build_cls = ctx.run_build_cls
435
    old_run_build_cls = ctx.run_build_cls
406
    ctx.run_build_cls = 'oc'
436
    ctx.run_build_cls = "oc"
407
    for (name, ccflag) in cc_test_flags:
437
    for (name, ccflag) in cc_test_flags:
408
        ctx.check(cflags=ccflag,
438
        ctx.check(
409
                  define_name='HAS_' + name,
439
            cflags=ccflag,
410
                  fragment=FRAGMENT,
440
            define_name="HAS_" + name,
411
                  mandatory=False,
441
            fragment=FRAGMENT,
412
                  msg='Checking if C compiler supports ' + ccflag,
442
            mandatory=False,
413
                  run_build_cls='oc')
443
            msg="Checking if C compiler supports " + ccflag,
444
            run_build_cls="oc",
445
        )
414
446
415
    ctx.run_build_cls = old_run_build_cls
447
    ctx.run_build_cls = old_run_build_cls
416
448
Lines 420-433 int main(int argc, char **argv) { Link Here
420
    if ctx.env.HAS_PIE:
452
    if ctx.env.HAS_PIE:
421
        ctx.env.LINKFLAGS_NTPD += [
453
        ctx.env.LINKFLAGS_NTPD += [
422
            "-pie",
454
            "-pie",
423
            ]
455
        ]
424
        ctx.env.CFLAGS_bin = ["-fPIE", "-pie"] + ctx.env.CFLAGS
456
        ctx.env.CFLAGS_bin = ["-fPIE", "-pie"] + ctx.env.CFLAGS
425
        ld_hardening_flags += [
457
        ld_hardening_flags += [
426
            ('relro', "-Wl,-z,relro"),  # hardening, marks some read only,
458
            ("relro", "-Wl,-z,relro"),  # hardening, marks some read only,
427
            ]
459
        ]
428
460
429
    if ctx.env.HAS_unused:
461
    if ctx.env.HAS_unused:
430
        ctx.env.CFLAGS = ['-Qunused-arguments'] + ctx.env.CFLAGS
462
        ctx.env.CFLAGS = ["-Qunused-arguments"] + ctx.env.CFLAGS
431
463
432
    # XXX: -flto currently breaks link of ntpd
464
    # XXX: -flto currently breaks link of ntpd
433
    if ctx.env.HAS_LTO and False:
465
    if ctx.env.HAS_LTO and False:
Lines 435-495 int main(int argc, char **argv) { Link Here
435
467
436
    # debug warnings that are not available with all compilers
468
    # debug warnings that are not available with all compilers
437
    if ctx.env.HAS_w_implicit_fallthru:
469
    if ctx.env.HAS_w_implicit_fallthru:
438
        ctx.env.CFLAGS = ['-Wimplicit-fallthrough=3'] + ctx.env.CFLAGS
470
        ctx.env.CFLAGS = ["-Wimplicit-fallthrough=3"] + ctx.env.CFLAGS
439
    if ctx.env.HAS_w_suggest_attribute_const:
471
    if ctx.env.HAS_w_suggest_attribute_const:
440
        ctx.env.CFLAGS = ['-Wsuggest-attribute=const'] + ctx.env.CFLAGS
472
        ctx.env.CFLAGS = ["-Wsuggest-attribute=const"] + ctx.env.CFLAGS
441
    if ctx.env.HAS_w_suggest_attribute_noreturn:
473
    if ctx.env.HAS_w_suggest_attribute_noreturn:
442
        ctx.env.CFLAGS = ['-Wsuggest-attribute=noreturn'] + ctx.env.CFLAGS
474
        ctx.env.CFLAGS = ["-Wsuggest-attribute=noreturn"] + ctx.env.CFLAGS
443
    if ctx.env.HAS_w_suggest_attribute_pure:
475
    if ctx.env.HAS_w_suggest_attribute_pure:
444
        ctx.env.CFLAGS = ['-Wsuggest-attribute=pure'] + ctx.env.CFLAGS
476
        ctx.env.CFLAGS = ["-Wsuggest-attribute=pure"] + ctx.env.CFLAGS
445
    if ctx.env.HAS_w_format_security:
477
    if ctx.env.HAS_w_format_security:
446
        ctx.env.CFLAGS = ['-Wformat-security'] + ctx.env.CFLAGS
478
        ctx.env.CFLAGS = ["-Wformat-security"] + ctx.env.CFLAGS
447
    if ctx.env.HAS_w_format_signedness:
479
    if ctx.env.HAS_w_format_signedness:
448
        ctx.env.CFLAGS = ['-Wformat-signedness'] + ctx.env.CFLAGS
480
        ctx.env.CFLAGS = ["-Wformat-signedness"] + ctx.env.CFLAGS
449
    # should be before other -Wformat-* in CFLAGS
481
    # should be before other -Wformat-* in CFLAGS
450
    if ctx.env.HAS_w_format:
482
    if ctx.env.HAS_w_format:
451
        ctx.env.CFLAGS = ['-Wformat'] + ctx.env.CFLAGS
483
        ctx.env.CFLAGS = ["-Wformat"] + ctx.env.CFLAGS
452
    if ctx.env.HAS_w_float_equal:
484
    if ctx.env.HAS_w_float_equal:
453
        ctx.env.CFLAGS = ['-Wfloat-equal'] + ctx.env.CFLAGS
485
        ctx.env.CFLAGS = ["-Wfloat-equal"] + ctx.env.CFLAGS
454
    if ctx.env.HAS_w_init_self:
486
    if ctx.env.HAS_w_init_self:
455
        ctx.env.CFLAGS = ['-Winit-self'] + ctx.env.CFLAGS
487
        ctx.env.CFLAGS = ["-Winit-self"] + ctx.env.CFLAGS
456
    if ctx.env.HAS_w_write_strings:
488
    if ctx.env.HAS_w_write_strings:
457
        ctx.env.CFLAGS = ['-Wwrite-strings'] + ctx.env.CFLAGS
489
        ctx.env.CFLAGS = ["-Wwrite-strings"] + ctx.env.CFLAGS
458
    if ctx.env.HAS_w_pointer_arith:
490
    if ctx.env.HAS_w_pointer_arith:
459
        ctx.env.CFLAGS = ['-Wpointer-arith'] + ctx.env.CFLAGS
491
        ctx.env.CFLAGS = ["-Wpointer-arith"] + ctx.env.CFLAGS
460
    if ctx.env.HAS_w_invalid_pch:
492
    if ctx.env.HAS_w_invalid_pch:
461
        ctx.env.CFLAGS = ['-Winvalid-pch'] + ctx.env.CFLAGS
493
        ctx.env.CFLAGS = ["-Winvalid-pch"] + ctx.env.CFLAGS
462
    if ctx.env.HAS_w_implicit_function_declaration:
494
    if ctx.env.HAS_w_implicit_function_declaration:
463
        ctx.env.CFLAGS = ['-Wimplicit-function-declaration'] + ctx.env.CFLAGS
495
        ctx.env.CFLAGS = ["-Wimplicit-function-declaration"] + ctx.env.CFLAGS
464
    if ctx.env.HAS_w_disabled_optimization:
496
    if ctx.env.HAS_w_disabled_optimization:
465
        ctx.env.CFLAGS = ['-Wdisabled-optimization'] + ctx.env.CFLAGS
497
        ctx.env.CFLAGS = ["-Wdisabled-optimization"] + ctx.env.CFLAGS
466
    # if ctx.env.HAS_w_cast_align:
498
    # if ctx.env.HAS_w_cast_align:
467
    #     ctx.env.CFLAGS = ['-Wcast-align'] + ctx.env.CFLAGS
499
    #     ctx.env.CFLAGS = ['-Wcast-align'] + ctx.env.CFLAGS
468
    if ctx.env.HAS_w_missing_declarations:
500
    if ctx.env.HAS_w_missing_declarations:
469
        ctx.env.CFLAGS = ['-Wmissing-declarations'] + ctx.env.CFLAGS
501
        ctx.env.CFLAGS = ["-Wmissing-declarations"] + ctx.env.CFLAGS
470
    if ctx.env.HAS_w_cast_qual:
502
    if ctx.env.HAS_w_cast_qual:
471
        ctx.env.CFLAGS = ['-Wcast-qual'] + ctx.env.CFLAGS
503
        ctx.env.CFLAGS = ["-Wcast-qual"] + ctx.env.CFLAGS
472
    if ctx.env.HAS_w_packed:
504
    if ctx.env.HAS_w_packed:
473
        ctx.env.CFLAGS = ['-Wpacked'] + ctx.env.CFLAGS
505
        ctx.env.CFLAGS = ["-Wpacked"] + ctx.env.CFLAGS
474
    if ctx.env.HAS_w_shadow:
506
    if ctx.env.HAS_w_shadow:
475
        ctx.env.CFLAGS = ['-Wshadow'] + ctx.env.CFLAGS
507
        ctx.env.CFLAGS = ["-Wshadow"] + ctx.env.CFLAGS
476
    # if ctx.env.HAS_w_sign_conversion:
508
    # if ctx.env.HAS_w_sign_conversion:
477
    #     ctx.env.CFLAGS = ['-Wsign-conversion'] + ctx.env.CFLAGS
509
    #     ctx.env.CFLAGS = ['-Wsign-conversion'] + ctx.env.CFLAGS
478
    if ctx.env.HAS_f_stack_protector_all:
510
    if ctx.env.HAS_f_stack_protector_all:
479
        ctx.env.CFLAGS = ['-fstack-protector-all'] + ctx.env.CFLAGS
511
        ctx.env.CFLAGS = ["-fstack-protector-all"] + ctx.env.CFLAGS
480
512
481
    # old gcc takes -z,relro, but then barfs if -fPIE available and used.
513
    # old gcc takes -z,relro, but then barfs if -fPIE available and used.
482
    # ("relro", "-Wl,-z,relro"), # marks some sections read only
514
    # ("relro", "-Wl,-z,relro"), # marks some sections read only
483
    old_run_build_cls = ctx.run_build_cls
515
    old_run_build_cls = ctx.run_build_cls
484
    ctx.run_build_cls = 'oc'
516
    ctx.run_build_cls = "oc"
485
    for (name, ldflag) in ld_hardening_flags:
517
    for (name, ldflag) in ld_hardening_flags:
486
        ctx.check(define_name='HAS_' + name,
518
        ctx.check(
487
                  fragment=FRAGMENT,
519
            define_name="HAS_" + name,
488
                  ldflags=ldflag,
520
            fragment=FRAGMENT,
489
                  mandatory=False,
521
            ldflags=ldflag,
490
                  msg='Checking if linker supports ' + ldflag,
522
            mandatory=False,
491
                  run_build_cls='oc')
523
            msg="Checking if linker supports " + ldflag,
492
        if ctx.env['HAS_' + name]:
524
            run_build_cls="oc",
525
        )
526
        if ctx.env["HAS_" + name]:
493
            ctx.env.LDFLAGS += [ldflag]
527
            ctx.env.LDFLAGS += [ldflag]
494
528
495
    ctx.run_build_cls = old_run_build_cls
529
    ctx.run_build_cls = old_run_build_cls
Lines 509-538 int main(int argc, char **argv) { Link Here
509
            #    ] + ctx.env.CFLAGS
543
            #    ] + ctx.env.CFLAGS
510
            ctx.env.LDFLAGS += [
544
            ctx.env.LDFLAGS += [
511
                "-Wl,-z,relro",  # hardening, marks some section read only,
545
                "-Wl,-z,relro",  # hardening, marks some section read only,
512
                ]
546
            ]
513
    # else:  # gcc, probably
547
    # else:  # gcc, probably
514
548
515
    # Exclude Unity's support for printing floating point numbers
549
    # Exclude Unity's support for printing floating point numbers
516
    # since it triggers warnings
550
    # since it triggers warnings
517
    # with -Wfloat-equal
551
    # with -Wfloat-equal
518
    ctx.env.CFLAGS = ['-DUNITY_EXCLUDE_FLOAT_PRINT'] + ctx.env.CFLAGS
552
    ctx.env.CFLAGS = ["-DUNITY_EXCLUDE_FLOAT_PRINT"] + ctx.env.CFLAGS
519
553
520
    # XXX: hack
554
    # XXX: hack
521
    if ctx.env.DEST_OS in ["freebsd"]:
555
    if ctx.env.DEST_OS in ["freebsd"]:
522
        ctx.env.INCLUDES = ["/usr/local/include"]
556
        ctx.env.INCLUDES = ["/usr/local/include"]
523
        ctx.env.LIBPATH = ["/usr/local/lib"]
557
        ctx.env.LIBPATH = ["/usr/local/lib"]
524
        if os.path.isdir("/usr/local/ssl/"):
558
        if os.path.isdir("/usr/local/ssl/"):
525
          # This assumes OpenSSL is the only thing that was in /usr/local/
559
            # This assumes OpenSSL is the only thing that was in /usr/local/
526
          ctx.env.INCLUDES = ["/usr/local/ssl/include"]
560
            ctx.env.INCLUDES = ["/usr/local/ssl/include"]
527
          ctx.env.LIBPATH = ["/usr/local/ssl/lib"]
561
            ctx.env.LIBPATH = ["/usr/local/ssl/lib"]
528
    elif ctx.env.DEST_OS == "netbsd" and os.path.isdir("/usr/pkg/include"):
562
    elif ctx.env.DEST_OS == "netbsd" and os.path.isdir("/usr/pkg/include"):
529
        ctx.env.INCLUDES = ["/usr/pkg/include"]
563
        ctx.env.INCLUDES = ["/usr/pkg/include"]
530
        ctx.env.LIBPATH = ["/usr/pkg/lib"]
564
        ctx.env.LIBPATH = ["/usr/pkg/lib"]
531
        ctx.env.LDFLAGS += ["-rpath=/usr/pkg/lib"]
565
        ctx.env.LDFLAGS += ["-rpath=/usr/pkg/lib"]
532
        if os.path.isdir("/usr/local/ssl/"):
566
        if os.path.isdir("/usr/local/ssl/"):
533
          # This assumes OpenSSL is the only thing that was in /usr/pkg/
567
            # This assumes OpenSSL is the only thing that was in /usr/pkg/
534
          ctx.env.INCLUDES = ["/usr/local/ssl/include"]
568
            ctx.env.INCLUDES = ["/usr/local/ssl/include"]
535
          ctx.env.LIBPATH = ["/usr/local/ssl/lib"]
569
            ctx.env.LIBPATH = ["/usr/local/ssl/lib"]
536
    elif ctx.env.DEST_OS == "linux" and os.path.isdir("/usr/local/ssl/"):
570
    elif ctx.env.DEST_OS == "linux" and os.path.isdir("/usr/local/ssl/"):
537
        # This supports building OpenSSL from source
571
        # This supports building OpenSSL from source
538
        # That allows using OpenSSL 1.1.1 on older CentOS
572
        # That allows using OpenSSL 1.1.1 on older CentOS
Lines 540-548 int main(int argc, char **argv) { Link Here
540
        # see HOWTO-OpenSSL
574
        # see HOWTO-OpenSSL
541
        ctx.env.INCLUDES = ["/usr/local/ssl/include"]
575
        ctx.env.INCLUDES = ["/usr/local/ssl/include"]
542
        if os.path.isdir("/usr/local/ssl/lib64/"):
576
        if os.path.isdir("/usr/local/ssl/lib64/"):
543
          ctx.env.LIBPATH = ["/usr/local/ssl/lib64"]
577
            ctx.env.LIBPATH = ["/usr/local/ssl/lib64"]
544
        else:
578
        else:
545
          ctx.env.LIBPATH = ["/usr/local/ssl/lib"]
579
            ctx.env.LIBPATH = ["/usr/local/ssl/lib"]
546
    elif ctx.env.DEST_OS == "darwin":
580
    elif ctx.env.DEST_OS == "darwin":
547
        # macports location
581
        # macports location
548
        if os.path.isdir("/opt/local/include"):
582
        if os.path.isdir("/opt/local/include"):
Lines 550-557 int main(int argc, char **argv) { Link Here
550
        if os.path.isdir("/opt/local/lib"):
584
        if os.path.isdir("/opt/local/lib"):
551
            ctx.env.LIBPATH = ["/opt/local/lib"]
585
            ctx.env.LIBPATH = ["/opt/local/lib"]
552
        # OS X needs this for IPv6
586
        # OS X needs this for IPv6
553
        ctx.define("__APPLE_USE_RFC_3542", 1,
587
        ctx.define("__APPLE_USE_RFC_3542", 1, comment="Needed for IPv6 support")
554
                   comment="Needed for IPv6 support")
555
    elif ctx.env.DEST_OS == "sunos":
588
    elif ctx.env.DEST_OS == "sunos":
556
        # Declare compatibility with the POSIX.1-2001 standard, and any
589
        # Declare compatibility with the POSIX.1-2001 standard, and any
557
        # headers/interfaces not in conflict with that standard
590
        # headers/interfaces not in conflict with that standard
Lines 559-574 int main(int argc, char **argv) { Link Here
559
        ctx.define("__EXTENSIONS__", "1", quote=False)
592
        ctx.define("__EXTENSIONS__", "1", quote=False)
560
593
561
    # Borrowed from waf-1.9, when type_name and field_name were valid keywords
594
    # Borrowed from waf-1.9, when type_name and field_name were valid keywords
562
    SNIP_TYPE = '''
595
    SNIP_TYPE = """
563
    int main(int argc, char **argv) {
596
    int main(int argc, char **argv) {
564
        (void)argc; (void)argv;
597
        (void)argc; (void)argv;
565
        if ((%(type_name)s *) 0) return 0;
598
        if ((%(type_name)s *) 0) return 0;
566
        if (sizeof (%(type_name)s)) return 0;
599
        if (sizeof (%(type_name)s)) return 0;
567
        return 1;
600
        return 1;
568
    }
601
    }
569
    '''
602
    """
570
603
571
    SNIP_FIELD = '''
604
    SNIP_FIELD = """
572
    #include <stddef.h>
605
    #include <stddef.h>
573
    int main(int argc, char **argv) {
606
    int main(int argc, char **argv) {
574
        char *off;
607
        char *off;
Lines 576-586 int main(int argc, char **argv) { Link Here
576
        off = (char*) &((%(type_name)s*)0)->%(field_name)s;
609
        off = (char*) &((%(type_name)s*)0)->%(field_name)s;
577
        return (size_t) off < sizeof(%(type_name)s);
610
        return (size_t) off < sizeof(%(type_name)s);
578
    }
611
    }
579
    '''
612
    """
580
613
581
    def to_header(header_name):
614
    def to_header(header_name):
582
        return ''.join(['#include <%s>\n' %
615
        return "".join(["#include <%s>\n" % x for x in Utils.to_list(header_name)])
583
                       x for x in Utils.to_list(header_name)])
584
616
585
    structures = (
617
    structures = (
586
        ("struct if_laddrconf", ["sys/types.h", "net/if6.h"], False),
618
        ("struct if_laddrconf", ["sys/types.h", "net/if6.h"], False),
Lines 590-597 int main(int argc, char **argv) { Link Here
590
    )
622
    )
591
    for (s, h, r) in structures:
623
    for (s, h, r) in structures:
592
        ctx.check_cc(
624
        ctx.check_cc(
593
            fragment=to_header(h) + SNIP_TYPE % {'type_name': s},
625
            fragment=to_header(h) + SNIP_TYPE % {"type_name": s},
594
            msg='Checking for type %s' % s,
626
            msg="Checking for type %s" % s,
595
            define_name=ctx.have_define(s.upper()),
627
            define_name=ctx.have_define(s.upper()),
596
            mandatory=r,
628
            mandatory=r,
597
        )
629
        )
Lines 605-621 int main(int argc, char **argv) { Link Here
605
    )
637
    )
606
    for (s, f, h) in structure_fields:
638
    for (s, f, h) in structure_fields:
607
        ctx.check_cc(
639
        ctx.check_cc(
608
            fragment=(to_header(h) + SNIP_FIELD %
640
            fragment=(to_header(h) + SNIP_FIELD % {"type_name": s, "field_name": f}),
609
                      {'type_name': s, 'field_name': f}),
641
            msg="Checking for field %s in %s" % (f, s),
610
            msg='Checking for field %s in %s' % (f, s),
642
            define_name=ctx.have_define((s + "_" + f).upper()),
611
            define_name=ctx.have_define((s + '_' + f).upper()),
612
            mandatory=False,
643
            mandatory=False,
613
        )
644
        )
614
645
615
    # mostly used by timetoa.h and timespecops.h
646
    # mostly used by timetoa.h and timespecops.h
616
    sizeofs = [
647
    sizeofs = [
617
        ("time.h",      "time_t"),
648
        ("time.h", "time_t"),
618
        (None,          "long"),
649
        (None, "long"),
619
    ]
650
    ]
620
651
621
    for header, sizeof in sorted(sizeofs, key=lambda x: x[1:]):
652
    for header, sizeof in sorted(sizeofs, key=lambda x: x[1:]):
Lines 624-661 int main(int argc, char **argv) { Link Here
624
    if not ctx.options.disable_nts:
655
    if not ctx.options.disable_nts:
625
        # Check via pkg-config first, then fall back to a direct search
656
        # Check via pkg-config first, then fall back to a direct search
626
        if not ctx.check_cfg(
657
        if not ctx.check_cfg(
627
            package='libssl', uselib_store='SSL',
658
            package="libssl",
628
            args=['--cflags', '--libs'],
659
            uselib_store="SSL",
660
            args=["--cflags", "--libs"],
629
            msg="Checking for OpenSSL/libssl (via pkg-config)",
661
            msg="Checking for OpenSSL/libssl (via pkg-config)",
630
            define_name='', mandatory=False,
662
            define_name="",
663
            mandatory=False,
631
        ):
664
        ):
632
            ctx.check_cc(msg="Checking for OpenSSL's ssl library",
665
            ctx.check_cc(
633
                         lib="ssl", mandatory=True)
666
                msg="Checking for OpenSSL's ssl library", lib="ssl", mandatory=True
667
            )
634
668
635
    # Check via pkg-config first, then fall back to a direct search
669
    # Check via pkg-config first, then fall back to a direct search
636
    if not ctx.check_cfg(
670
    if not ctx.check_cfg(
637
        package='libcrypto', uselib_store='CRYPTO',
671
        package="libcrypto",
638
        args=['--cflags', '--libs'],
672
        uselib_store="CRYPTO",
673
        args=["--cflags", "--libs"],
639
        msg="Checking for OpenSSL/libcrypto (via pkg-config)",
674
        msg="Checking for OpenSSL/libcrypto (via pkg-config)",
640
        define_name='', mandatory=False,
675
        define_name="",
676
        mandatory=False,
641
    ):
677
    ):
642
        ctx.check_cc(msg="Checking for OpenSSL's crypto library",
678
        ctx.check_cc(
643
                     lib="crypto", mandatory=True)
679
            msg="Checking for OpenSSL's crypto library", lib="crypto", mandatory=True
680
        )
644
681
645
    # Optional functions.  Do all function checks here, otherwise
682
    # Optional functions.  Do all function checks here, otherwise
646
    # we're likely to duplicate them.
683
    # we're likely to duplicate them.
647
    optional_functions = (
684
    optional_functions = (
648
        ('_Unwind_Backtrace', ["unwind.h"]),
685
        ("_Unwind_Backtrace", ["unwind.h"]),
649
        ('adjtimex', ["sys/time.h", "sys/timex.h"]),
686
        ("adjtimex", ["sys/time.h", "sys/timex.h"]),
650
        ('backtrace_symbols_fd', ["execinfo.h"]),
687
        ("backtrace_symbols_fd", ["execinfo.h"]),
651
        ('ntp_adjtime', ["sys/time.h", "sys/timex.h"]),     # BSD
688
        ("ntp_adjtime", ["sys/time.h", "sys/timex.h"]),  # BSD
652
        ('ntp_gettime', ["sys/time.h", "sys/timex.h"]),     # BSD
689
        ("ntp_gettime", ["sys/time.h", "sys/timex.h"]),  # BSD
653
        ('res_init', ["netinet/in.h", "arpa/nameser.h", "resolv.h"]),
690
        ("res_init", ["netinet/in.h", "arpa/nameser.h", "resolv.h"]),
654
        ('strlcpy', ["string.h"]),
691
        ("strlcpy", ["string.h"]),
655
        ('strlcat', ["string.h"]),
692
        ("strlcat", ["string.h"]),
656
        ('timegm', ["time.h"]),
693
        ("timegm", ["time.h"]),
657
        # Hack.  It's not a function, but this works.
694
        # Hack.  It's not a function, but this works.
658
        ('PRIV_NTP_ADJTIME', ["sys/priv.h"])            # FreeBSD
695
        ("PRIV_NTP_ADJTIME", ["sys/priv.h"]),  # FreeBSD
659
    )
696
    )
660
    for ft in optional_functions:
697
    for ft in optional_functions:
661
        probe_function(ctx, function=ft[0], prerequisites=ft[1])
698
        probe_function(ctx, function=ft[0], prerequisites=ft[1])
Lines 667-701 int main(int argc, char **argv) { Link Here
667
    # Sanity checks to give a sensible error message
704
    # Sanity checks to give a sensible error message
668
    required_functions = (
705
    required_functions = (
669
        # MacOS doesn't have timer_create ??
706
        # MacOS doesn't have timer_create ??
670
        ('timer_create', ["signal.h", "time.h"], "RT", False),
707
        ("timer_create", ["signal.h", "time.h"], "RT", False),
671
        # Very old versions of OpenSSL don't have cmac.h
708
        # Very old versions of OpenSSL don't have cmac.h
672
        #  We could add ifdefs, but old crypto is deprecated in favor of CMAC
709
        #  We could add ifdefs, but old crypto is deprecated in favor of CMAC
673
        #  and so far, all the systems that we want to support are new enough.
710
        #  and so far, all the systems that we want to support are new enough.
674
        ('CMAC_CTX_new', ["openssl/cmac.h"], "CRYPTO", True),
711
        ("CMAC_CTX_new", ["openssl/cmac.h"], "CRYPTO", True),
675
	# Next should be above, but it needs a library
712
        # Next should be above, but it needs a library
676
	# EVP_PKEY_new_CMAC_key added in OpenSSL 1.1.1
713
        # EVP_PKEY_new_CMAC_key added in OpenSSL 1.1.1
677
        ('EVP_PKEY_new_CMAC_key', ["openssl/cmac.h"], "CRYPTO", False))
714
        ("EVP_PKEY_new_CMAC_key", ["openssl/cmac.h"], "CRYPTO", False),
715
    )
678
    for ft in required_functions:
716
    for ft in required_functions:
679
        probe_function(ctx, function=ft[0],
717
        probe_function(
680
                       prerequisites=ft[1], use=ft[2],
718
            ctx, function=ft[0], prerequisites=ft[1], use=ft[2], mandatory=ft[3]
681
                       mandatory=ft[3])
719
        )
682
720
683
    # check for BSD versions outside of libc
721
    # check for BSD versions outside of libc
684
    if not ctx.get_define("HAVE_STRLCAT"):
722
    if not ctx.get_define("HAVE_STRLCAT"):
685
        ret = probe_function(ctx, function='strlcat',
723
        ret = probe_function(ctx, function="strlcat", prerequisites=["bsd/string.h"])
686
                             prerequisites=['bsd/string.h'])
687
        if ret:
724
        if ret:
688
            ctx.define("HAVE_STRLCAT", 1, comment="Using bsd/strlcat")
725
            ctx.define("HAVE_STRLCAT", 1, comment="Using bsd/strlcat")
689
726
690
    if not ctx.get_define("HAVE_STRLCPY"):
727
    if not ctx.get_define("HAVE_STRLCPY"):
691
        ret = probe_function(ctx, function='strlcpy',
728
        ret = probe_function(ctx, function="strlcpy", prerequisites=["bsd/string.h"])
692
                             prerequisites=['bsd/string.h'])
693
        if ret:
729
        if ret:
694
            ctx.define("HAVE_STRLCPY", 1, comment="Using bsd/strlcpy")
730
            ctx.define("HAVE_STRLCPY", 1, comment="Using bsd/strlcpy")
695
731
696
    # Nobody uses the symbol, but this seems like a good sanity check.
732
    # Nobody uses the symbol, but this seems like a good sanity check.
697
    ctx.check_cc(header_name="stdbool.h", mandatory=True,
733
    ctx.check_cc(header_name="stdbool.h", mandatory=True, comment="Sanity check.")
698
                 comment="Sanity check.")
699
734
700
    # This is a list of every optional include header in the
735
    # This is a list of every optional include header in the
701
    # codebase that is guarded by a directly corresponding HAVE_*_H symbol.
736
    # codebase that is guarded by a directly corresponding HAVE_*_H symbol.
Lines 711-728 int main(int argc, char **argv) { Link Here
711
    optional_headers = (
746
    optional_headers = (
712
        "alloca.h",
747
        "alloca.h",
713
        ("arpa/nameser.h", ["sys/types.h"]),
748
        ("arpa/nameser.h", ["sys/types.h"]),
714
        "bsd/string.h",     # bsd emulation
749
        "bsd/string.h",  # bsd emulation
715
        ("ifaddrs.h", ["sys/types.h"]),
750
        ("ifaddrs.h", ["sys/types.h"]),
716
        ("linux/if_addr.h", ["sys/socket.h"]),
751
        ("linux/if_addr.h", ["sys/socket.h"]),
717
        ("linux/rtnetlink.h", ["sys/socket.h"]),
752
        ("linux/rtnetlink.h", ["sys/socket.h"]),
718
        "linux/serial.h",
753
        "linux/serial.h",
719
        "net/if6.h",
754
        "net/if6.h",
720
        ("net/route.h", ["sys/types.h", "sys/socket.h", "net/if.h"]),
755
        ("net/route.h", ["sys/types.h", "sys/socket.h", "net/if.h"]),
721
        "priv.h",           # Solaris
756
        "priv.h",  # Solaris
722
        "stdatomic.h",
757
        "stdatomic.h",
723
        "sys/clockctl.h",   # NetBSD
758
        "sys/clockctl.h",  # NetBSD
724
        "sys/ioctl.h",
759
        "sys/ioctl.h",
725
        "sys/modem.h",      # Apple
760
        "sys/modem.h",  # Apple
726
        "sys/sockio.h",
761
        "sys/sockio.h",
727
        ("sys/sysctl.h", ["sys/types.h"]),
762
        ("sys/sysctl.h", ["sys/types.h"]),
728
        ("timepps.h", ["inttypes.h"]),
763
        ("timepps.h", ["inttypes.h"]),
Lines 731-738 int main(int argc, char **argv) { Link Here
731
    )
766
    )
732
    for hdr in optional_headers:
767
    for hdr in optional_headers:
733
        if isinstance(hdr, str):
768
        if isinstance(hdr, str):
734
            if ctx.check_cc(header_name=hdr, mandatory=False,
769
            if ctx.check_cc(
735
                            comment="<%s> header" % hdr):
770
                header_name=hdr, mandatory=False, comment="<%s> header" % hdr
771
            ):
736
                continue
772
                continue
737
        else:
773
        else:
738
            (hdr, prereqs) = hdr
774
            (hdr, prereqs) = hdr
Lines 742-765 int main(int argc, char **argv) { Link Here
742
            # Sanity check...
778
            # Sanity check...
743
            print("Compilation check failed but include exists %s" % hdr)
779
            print("Compilation check failed but include exists %s" % hdr)
744
780
745
    if ((ctx.get_define("HAVE_TIMEPPS_H") or
781
    if ctx.get_define("HAVE_TIMEPPS_H") or ctx.get_define("HAVE_SYS_TIMEPPS_H"):
746
            ctx.get_define("HAVE_SYS_TIMEPPS_H"))):
747
        ctx.define("HAVE_PPSAPI", 1, comment="Enable the PPS API")
782
        ctx.define("HAVE_PPSAPI", 1, comment="Enable the PPS API")
748
783
749
    # Check for Solaris capabilities
784
    # Check for Solaris capabilities
750
    if ctx.get_define("HAVE_PRIV_H") and ctx.env.DEST_OS == "sunos":
785
    if ctx.get_define("HAVE_PRIV_H") and ctx.env.DEST_OS == "sunos":
751
        ctx.define("HAVE_SOLARIS_PRIVS", 1,
786
        ctx.define(
752
                   comment="Enable Solaris Privileges (Solaris only)")
787
            "HAVE_SOLARIS_PRIVS", 1, comment="Enable Solaris Privileges (Solaris only)"
788
        )
753
789
754
    from wafhelpers.check_sockaddr import check_sockaddr
790
    from wafhelpers.check_sockaddr import check_sockaddr
791
755
    check_sockaddr(ctx)
792
    check_sockaddr(ctx)
756
793
757
    from wafhelpers.check_strerror import check_strerror
794
    from wafhelpers.check_strerror import check_strerror
795
758
    check_strerror(ctx)
796
    check_strerror(ctx)
759
797
760
    # Check for Solaris's service configuration facility library
798
    # Check for Solaris's service configuration facility library
761
    ctx.check_cc(header_name="libscf.h", lib="scf", mandatory=False,
799
    ctx.check_cc(header_name="libscf.h", lib="scf", mandatory=False, uselib_store="SCF")
762
                 uselib_store="SCF")
763
800
764
    # Some systems don't have sys/timex.h eg OS X, OpenBSD...
801
    # Some systems don't have sys/timex.h eg OS X, OpenBSD...
765
    if ctx.get_define("HAVE_SYS_TIMEX_H"):
802
    if ctx.get_define("HAVE_SYS_TIMEX_H"):
Lines 767-772 int main(int argc, char **argv) { Link Here
767
804
768
    if ctx.options.refclocks:
805
    if ctx.options.refclocks:
769
        from wafhelpers.refclock import refclock_config
806
        from wafhelpers.refclock import refclock_config
807
770
        refclock_config(ctx)
808
        refclock_config(ctx)
771
        # timegm needed by refclock_nmea, it's not in POSIX
809
        # timegm needed by refclock_nmea, it's not in POSIX
772
        # It's in Linux, FreeBSD, and NetBSD
810
        # It's in Linux, FreeBSD, and NetBSD
Lines 782-822 int main(int argc, char **argv) { Link Here
782
    # ctx.define("OS_MISSES_SPECIFIC_ROUTE_UPDATES", 1)
820
    # ctx.define("OS_MISSES_SPECIFIC_ROUTE_UPDATES", 1)
783
821
784
    if ctx.options.enable_leap_smear:
822
    if ctx.options.enable_leap_smear:
785
        ctx.define("ENABLE_LEAP_SMEAR", 1,
823
        ctx.define(
786
                   comment="Enable experimental leap smearing code")
824
            "ENABLE_LEAP_SMEAR", 1, comment="Enable experimental leap smearing code"
825
        )
787
826
788
    if ctx.options.enable_mssntp:
827
    if ctx.options.enable_mssntp:
789
        ctx.define("ENABLE_MSSNTP", 1,
828
        ctx.define(
790
                   comment="Enable MS-SNTP extensions "
829
            "ENABLE_MSSNTP",
791
                   " https://msdn.microsoft.com/en-us/library/cc212930.aspx")
830
            1,
831
            comment="Enable MS-SNTP extensions "
832
            " https://msdn.microsoft.com/en-us/library/cc212930.aspx",
833
        )
792
834
793
    if ctx.options.enable_attic:
835
    if ctx.options.enable_attic:
794
        ctx.env.ENABLE_ATTIC = True
836
        ctx.env.ENABLE_ATTIC = True
795
837
796
    if ctx.options.disable_nts:
838
    if ctx.options.disable_nts:
797
        ctx.env.DISABLE_NTS = True
839
        ctx.env.DISABLE_NTS = True
798
        ctx.define("DISABLE_NTS", 1,
840
        ctx.define("DISABLE_NTS", 1, comment="Disable NTS")
799
                   comment="Disable NTS")
800
841
801
    if not ctx.options.disable_droproot:
842
    if not ctx.options.disable_droproot:
802
        ctx.define("ENABLE_DROPROOT", 1,
843
        ctx.define("ENABLE_DROPROOT", 1, comment="Drop root after initialising")
803
                   comment="Drop root after initialising")
804
    if ctx.options.enable_early_droproot:
844
    if ctx.options.enable_early_droproot:
805
        ctx.define("ENABLE_EARLY_DROPROOT", 1,
845
        ctx.define("ENABLE_EARLY_DROPROOT", 1, comment="Enable early drop root")
806
                   comment="Enable early drop root")
807
    if not ctx.options.disable_fuzz:
846
    if not ctx.options.disable_fuzz:
808
        ctx.define("ENABLE_FUZZ", 1,
847
        ctx.define("ENABLE_FUZZ", 1, comment="Enable fuzzing low bits of time")
809
                   comment="Enable fuzzing low bits of time")
810
848
811
    # SO_REUSEADDR socket option is needed to open a socket on an
849
    # SO_REUSEADDR socket option is needed to open a socket on an
812
    # interface when the port number is already in use on another
850
    # interface when the port number is already in use on another
813
    # interface. Linux needs this, NetBSD does not, status on
851
    # interface. Linux needs this, NetBSD does not, status on
814
    # other platforms is unknown.  It is probably harmless to
852
    # other platforms is unknown.  It is probably harmless to
815
    # have it on everywhere.
853
    # have it on everywhere.
816
    ctx.define("NEED_REUSEADDR_FOR_IFADDRBIND", 1,
854
    ctx.define(
817
               comment="Whether SO_REUSEADDR is needed to open "
855
        "NEED_REUSEADDR_FOR_IFADDRBIND",
818
               "same sockets on alternate interfaces, required "
856
        1,
819
               "by Linux at least")
857
        comment="Whether SO_REUSEADDR is needed to open "
858
        "same sockets on alternate interfaces, required "
859
        "by Linux at least",
860
    )
820
861
821
    # Check for directory separator
862
    # Check for directory separator
822
    if ctx.env.DEST_OS == "win32":
863
    if ctx.env.DEST_OS == "win32":
Lines 824-835 int main(int argc, char **argv) { Link Here
824
    else:
865
    else:
825
        sep = "/"
866
        sep = "/"
826
867
827
    ctx.define("DIR_SEP", "'%s'" % sep, quote=False,
868
    ctx.define("DIR_SEP", "'%s'" % sep, quote=False, comment="Directory separator used")
828
               comment="Directory separator used")
829
869
830
    if ctx.get_define("HAVE_SYS_SYSCTL_H"):
870
    if ctx.get_define("HAVE_SYS_SYSCTL_H"):
831
        ctx.define("HAVE_IFLIST_SYSCTL", 1,
871
        ctx.define("HAVE_IFLIST_SYSCTL", 1, comment="Whether sysctl interface exists")
832
                   comment="Whether sysctl interface exists")
833
872
834
    # Header/library checks
873
    # Header/library checks
835
874
Lines 838-845 int main(int argc, char **argv) { Link Here
838
        ctx.check_cc(header_name="sys/capability.h", mandatory=False)
877
        ctx.check_cc(header_name="sys/capability.h", mandatory=False)
839
        ctx.check_cc(lib="cap", comment="Capability library", mandatory=False)
878
        ctx.check_cc(lib="cap", comment="Capability library", mandatory=False)
840
879
841
        if ((ctx.get_define("HAVE_SYS_CAPABILITY_H") and
880
        if (
842
                ctx.get_define("HAVE_SYS_PRCTL_H") and ctx.env.LIB_CAP)):
881
            ctx.get_define("HAVE_SYS_CAPABILITY_H")
882
            and ctx.get_define("HAVE_SYS_PRCTL_H")
883
            and ctx.env.LIB_CAP
884
        ):
843
            ctx.define("HAVE_LINUX_CAPABILITY", 1)
885
            ctx.define("HAVE_LINUX_CAPABILITY", 1)
844
886
845
    if ctx.options.enable_seccomp:
887
    if ctx.options.enable_seccomp:
Lines 848-863 int main(int argc, char **argv) { Link Here
848
890
849
        # Check via pkg-config first, then fall back to a direct search
891
        # Check via pkg-config first, then fall back to a direct search
850
        if not ctx.check_cfg(
892
        if not ctx.check_cfg(
851
            package='libseccomp', args=['--libs', '--cflags'],
893
            package="libseccomp",
852
            uselib_store='SECCOMP', define_name='HAVE_SECCOMP_H',
894
            args=["--libs", "--cflags"],
853
            mandatory=False
895
            uselib_store="SECCOMP",
896
            define_name="HAVE_SECCOMP_H",
897
            mandatory=False,
854
        ):
898
        ):
855
            ctx.check_cc(header_name="seccomp.h")
899
            ctx.check_cc(header_name="seccomp.h")
856
            ctx.check_cc(lib="seccomp")
900
            ctx.check_cc(lib="seccomp")
857
901
858
    if not ctx.options.disable_mdns_registration:
902
    if not ctx.options.disable_mdns_registration:
859
        ctx.check_cc(header_name="dns_sd.h", lib="dns_sd", mandatory=False,
903
        ctx.check_cc(
860
                     uselib_store="DNS_SD")
904
            header_name="dns_sd.h", lib="dns_sd", mandatory=False, uselib_store="DNS_SD"
905
        )
861
906
862
    # Solaris needs -lsocket and -lnsl for socket code
907
    # Solaris needs -lsocket and -lnsl for socket code
863
    if ctx.env.DEST_OS == "sunos":
908
    if ctx.env.DEST_OS == "sunos":
Lines 880-885 int main(int argc, char **argv) { Link Here
880
    if not ctx.env.DISABLE_NTS:
925
    if not ctx.env.DISABLE_NTS:
881
        from wafhelpers.openssl import check_libssl_tls13
926
        from wafhelpers.openssl import check_libssl_tls13
882
        from wafhelpers.openssl import check_openssl_bad_version
927
        from wafhelpers.openssl import check_openssl_bad_version
928
883
        check_libssl_tls13(ctx)
929
        check_libssl_tls13(ctx)
884
        check_openssl_bad_version(ctx)
930
        check_openssl_bad_version(ctx)
885
931
Lines 919-924 int main(int argc, char **argv) { Link Here
919
    msg_setting("Build Docs", yesno(ctx.env.BUILD_DOC))
965
    msg_setting("Build Docs", yesno(ctx.env.BUILD_DOC))
920
    msg_setting("Build Manpages", yesno(ctx.env.BUILD_MAN))
966
    msg_setting("Build Manpages", yesno(ctx.env.BUILD_MAN))
921
967
968
    if ctx.env["ntpc"] == "none":
969
        return
922
    ctx.recurse("pylib")
970
    ctx.recurse("pylib")
923
    ctx.env.PYSHEBANG = ctx.options.pyshebang
971
    ctx.env.PYSHEBANG = ctx.options.pyshebang
924
    msg_setting("PYSHEBANG", ctx.env.PYSHEBANG)
972
    msg_setting("PYSHEBANG", ctx.env.PYSHEBANG)
Lines 931-949 int main(int argc, char **argv) { Link Here
931
979
932
980
933
class check(BuildContext):
981
class check(BuildContext):
934
    cmd = 'check'
982
    cmd = "check"
935
    variant = "main"
983
    variant = "main"
936
984
937
985
938
def bin_test(ctx):
986
def bin_test(ctx):
939
    """Run binary check, use after tests."""
987
    """Run binary check, use after tests."""
940
    from wafhelpers.bin_test import cmd_bin_test
988
    from wafhelpers.bin_test import cmd_bin_test
989
941
    cmd_bin_test(ctx)
990
    cmd_bin_test(ctx)
942
991
943
992
944
def bin_test_summary(ctx):
993
def bin_test_summary(ctx):
945
    """Display results of binary check, use after tests."""
994
    """Display results of binary check, use after tests."""
946
    from wafhelpers.bin_test import bin_test_summary
995
    from wafhelpers.bin_test import bin_test_summary
996
947
    bin_test_summary(ctx)
997
    bin_test_summary(ctx)
948
998
949
999
Lines 960-965 variant_cmd = ( Link Here
960
for v in ["host", "main"]:
1010
for v in ["host", "main"]:
961
    # the reason for creating these subclasses is just for __doc__ below...
1011
    # the reason for creating these subclasses is just for __doc__ below...
962
    for cmd, cls in variant_cmd:
1012
    for cmd, cls in variant_cmd:
1013
963
        class tmp(cls):
1014
        class tmp(cls):
964
            __doc__ = "%s %s" % (cmd, v)
1015
            __doc__ = "%s %s" % (cmd, v)
965
            cmd = "%s_%s" % (cmd, v)
1016
            cmd = "%s_%s" % (cmd, v)
Lines 968-981 for v in ["host", "main"]: Link Here
968
1019
969
def init_handler(ctx):
1020
def init_handler(ctx):
970
    cmd = ctx.cmd
1021
    cmd = ctx.cmd
971
    if cmd == 'init_handler':
1022
    if cmd == "init_handler":
972
        cmd = 'build'
1023
        cmd = "build"
973
1024
974
    def make_context(name):
1025
    def make_context(name):
975
        for x in Context.classes:
1026
        for x in Context.classes:
976
            if x.cmd == name and x.fun != 'init_handler':
1027
            if x.cmd == name and x.fun != "init_handler":
977
                return x()
1028
                return x()
978
        ctx.fatal('No class for %r' % cmd)
1029
        ctx.fatal("No class for %r" % cmd)
979
1030
980
    # By default we want to iterate over each variant.
1031
    # By default we want to iterate over each variant.
981
    for v in ["host", "main"]:
1032
    for v in ["host", "main"]:
Lines 996-1010 commands = ( Link Here
996
1047
997
1048
998
for command, func, descr in commands:
1049
for command, func, descr in commands:
1050
999
    class tmp1(Context.Context):
1051
    class tmp1(Context.Context):
1000
        if descr:
1052
        if descr:
1001
            __doc__ = descr
1053
            __doc__ = descr
1002
        cmd = command
1054
        cmd = command
1003
        fun = func
1055
        fun = func
1004
        if ((command in
1056
        if command in "install uninstall build clean list step":
1005
            'install uninstall build clean list step'
1006
             )):
1007
            execute = Scripting.autoconfigure(Context.Context.execute)
1057
            execute = Scripting.autoconfigure(Context.Context.execute)
1058
1059
1008
# end borrowed code
1060
# end borrowed code
1009
1061
1010
1062
Lines 1018-1032 def afterparty(ctx): Link Here
1018
    # Note that this setup is applied to the build tree, not the
1070
    # Note that this setup is applied to the build tree, not the
1019
    # source tree.  Only the build-tree copies of the programs are
1071
    # source tree.  Only the build-tree copies of the programs are
1020
    # expected to work.
1072
    # expected to work.
1021
    for x in ("ntpclients", "tests/pylib",):
1073
    if "none" == ctx.env["ntpc"]:
1074
        return
1075
    for x in (
1076
        "ntpclients",
1077
        "tests/pylib",
1078
    ):
1022
        # List used to be longer...
1079
        # List used to be longer...
1023
        path_build = ctx.bldnode.make_node("pylib")
1080
        path_build = ctx.bldnode.make_node("pylib")
1024
        path_source = ctx.bldnode.make_node(x + "/ntp")
1081
        path_source = ctx.bldnode.make_node(x + "/ntp")
1025
        relpath = (("../" * (x.count("/")+1)) +
1082
        relpath = ("../" * (x.count("/") + 1)) + path_build.path_from(ctx.bldnode)
1026
                   path_build.path_from(ctx.bldnode))
1083
        if ctx.cmd in ("install", "build"):
1027
        if ctx.cmd in ('install', 'build'):
1084
            if (
1028
            if ((not path_source.exists() or
1085
                not path_source.exists()
1029
                    os.readlink(path_source.abspath()) != relpath)):
1086
                or os.readlink(path_source.abspath()) != relpath
1087
            ):
1030
                try:
1088
                try:
1031
                    os.remove(path_source.abspath())
1089
                    os.remove(path_source.abspath())
1032
                except OSError:
1090
                except OSError:
Lines 1046-1055 python_scripts = { Link Here
1046
1104
1047
1105
1048
def build(ctx):
1106
def build(ctx):
1107
    global python_scripts
1049
    from waflib.Logs import verbose
1108
    from waflib.Logs import verbose
1050
    ctx.load('waf', tooldir='wafhelpers/')
1109
1051
    ctx.load('asciidoc', tooldir='wafhelpers/')
1110
    ctx.load("waf", tooldir="wafhelpers/")
1052
    ctx.load('rtems_trace', tooldir='wafhelpers/')
1111
    ctx.load("asciidoc", tooldir="wafhelpers/")
1112
    ctx.load("rtems_trace", tooldir="wafhelpers/")
1053
1113
1054
    if ctx.variant == "host":
1114
    if ctx.variant == "host":
1055
        ctx.recurse("ntpd")
1115
        ctx.recurse("ntpd")
Lines 1062-1070 def build(ctx): Link Here
1062
        ctx.add_pre_fun(lambda ctx: ctx.exec_command("rm -f pylib/*.py[co]"))
1122
        ctx.add_pre_fun(lambda ctx: ctx.exec_command("rm -f pylib/*.py[co]"))
1063
        # Start purging ntp.ntpc files from build dir
1123
        # Start purging ntp.ntpc files from build dir
1064
        # so old extension won't clobber FFI or reverse
1124
        # so old extension won't clobber FFI or reverse
1065
        bldnode = ctx.bldnode.make_node('pylib')
1125
        bldnode = ctx.bldnode.make_node("pylib")
1066
        bldnode.mkdir()
1126
        bldnode.mkdir()
1067
        target3 = bldnode.ant_glob('*ntpc*')
1127
        target3 = bldnode.ant_glob("*ntpc*")
1068
        for _ in target3:
1128
        for _ in target3:
1069
            ctx.exec_command("rm -f %s" % _.abspath())
1129
            ctx.exec_command("rm -f %s" % _.abspath())
1070
        # Finish purging ntp.ntpc
1130
        # Finish purging ntp.ntpc
Lines 1075-1125 def build(ctx): Link Here
1075
        ctx.recurse("libparse")
1135
        ctx.recurse("libparse")
1076
    ctx.recurse("libntp")
1136
    ctx.recurse("libntp")
1077
    if not ctx.env.DISABLE_NTS:
1137
    if not ctx.env.DISABLE_NTS:
1078
      ctx.recurse("libaes_siv")
1138
        ctx.recurse("libaes_siv")
1079
    ctx.recurse("ntpd")
1139
    ctx.recurse("ntpd")
1080
    ctx.recurse("ntpfrob")
1140
    ctx.recurse("ntpfrob")
1081
    ctx.recurse("ntptime")
1141
    ctx.recurse("ntptime")
1082
    ctx.recurse("pylib")
1142
    ctx.recurse("pylib")
1083
    if ctx.env.ENABLE_ATTIC:
1143
    if ctx.env.ENABLE_ATTIC:
1084
      ctx.recurse("attic")
1144
        ctx.recurse("attic")
1085
    ctx.recurse("etc")
1145
    ctx.recurse("etc")
1086
    ctx.recurse("tests")
1146
    ctx.recurse("tests")
1087
1147
1088
    if ctx.env['PYTHON_ARGPARSE']:
1148
    if ctx.env["PYTHON_ARGPARSE"]:
1089
        python_scripts.add("ntpclients/ntplogtemp.py")
1149
        python_scripts.add("ntpclients/ntplogtemp.py")
1090
        python_scripts.add("ntpclients/ntpviz.py")
1150
        python_scripts.add("ntpclients/ntpviz.py")
1091
    if ctx.env['PYTHON_ARGPARSE'] and ctx.env['PYTHON_GPS']:
1151
    if ctx.env["PYTHON_ARGPARSE"] and ctx.env["PYTHON_GPS"]:
1092
        python_scripts.add("ntpclients/ntploggps.py")
1152
        python_scripts.add("ntpclients/ntploggps.py")
1093
    if ctx.env['PYTHON_CURSES']:
1153
    if ctx.env["PYTHON_CURSES"]:
1094
        python_scripts.add("ntpclients/ntpmon.py")
1154
        python_scripts.add("ntpclients/ntpmon.py")
1095
1155
    if "none" == ctx.env["ntpc"]:
1096
    # Make sure the python scripts compile, but don't install them
1156
        python_scripts = []
1097
    ctx(
1157
    else:
1098
        features="py",
1158
        # Make sure the python scripts compile, but don't install them
1099
        source=python_scripts,
1159
        ctx(
1100
        install_path=None,
1160
            features="py",
1101
    )
1161
            source=python_scripts,
1162
            install_path=None,
1163
        )
1102
1164
1103
    scripts = ["ntpclients/ntpleapfetch"] + list(python_scripts)
1165
    scripts = ["ntpclients/ntpleapfetch"] + list(python_scripts)
1104
1166
1105
    ctx(
1167
    ctx(
1106
        features="subst",
1168
        features="subst",
1107
        source=scripts,
1169
        source=scripts,
1108
        target=[x.replace('.py', '') for x in scripts],
1170
        target=[x.replace(".py", "") for x in scripts],
1109
        chmod=Utils.O755,
1171
        chmod=Utils.O755,
1110
        install_path='${BINDIR}',
1172
        install_path="${BINDIR}",
1111
    )
1173
    )
1112
1174
1113
    ctx.add_post_fun(afterparty)
1175
    ctx.add_post_fun(afterparty)
1114
    if ctx.cmd == 'clean':
1176
    if ctx.cmd == "clean":
1115
        afterparty(ctx)
1177
        afterparty(ctx)
1116
1178
1117
    if ctx.env['PYTHON_ARGPARSE']:
1179
    if ctx.env["PYTHON_ARGPARSE"]:
1118
        ctx.manpage(1, "ntpclients/ntplogtemp-man.adoc")
1180
        ctx.manpage(1, "ntpclients/ntplogtemp-man.adoc")
1119
        ctx.manpage(1, "ntpclients/ntpviz-man.adoc")
1181
        ctx.manpage(1, "ntpclients/ntpviz-man.adoc")
1120
    if ctx.env['PYTHON_ARGPARSE'] and ctx.env['PYTHON_GPS']:
1182
    if ctx.env["PYTHON_ARGPARSE"] and ctx.env["PYTHON_GPS"]:
1121
        ctx.manpage(1, "ntpclients/ntploggps-man.adoc")
1183
        ctx.manpage(1, "ntpclients/ntploggps-man.adoc")
1122
    if ctx.env['PYTHON_CURSES']:
1184
    if ctx.env["PYTHON_CURSES"]:
1123
        ctx.manpage(1, "ntpclients/ntpmon-man.adoc")
1185
        ctx.manpage(1, "ntpclients/ntpmon-man.adoc")
1124
    ctx.manpage(1, "ntpclients/ntpdig-man.adoc")
1186
    ctx.manpage(1, "ntpclients/ntpdig-man.adoc")
1125
    ctx.manpage(1, "ntpclients/ntpq-man.adoc")
1187
    ctx.manpage(1, "ntpclients/ntpq-man.adoc")
Lines 1132-1137 def build(ctx): Link Here
1132
1194
1133
    # Skip running unit tests on a cross compile build
1195
    # Skip running unit tests on a cross compile build
1134
    from waflib import Options
1196
    from waflib import Options
1197
1135
    if not ctx.env.ENABLE_CROSS:
1198
    if not ctx.env.ENABLE_CROSS:
1136
        # Force re-running of tests.  Same as 'waf --alltests'
1199
        # Force re-running of tests.  Same as 'waf --alltests'
1137
        if ctx.cmd == "check":
1200
        if ctx.cmd == "check":
Lines 1159-1169 def build(ctx): Link Here
1159
1222
1160
    if ctx.cmd == "build":
1223
    if ctx.cmd == "build":
1161
        if "PYTHONPATH" not in os.environ:
1224
        if "PYTHONPATH" not in os.environ:
1162
            print("--- PYTHONPATH is not set, "
1225
            print(
1163
                  "loading the Python ntp library may be troublesome ---")
1226
                "--- PYTHONPATH is not set, "
1227
                "loading the Python ntp library may be troublesome ---"
1228
            )
1164
        elif ctx.env.PYTHONARCHDIR not in os.environ["PYTHONPATH"]:
1229
        elif ctx.env.PYTHONARCHDIR not in os.environ["PYTHONPATH"]:
1165
            print("--- PYTHONARCHDIR not in PYTHONPATH, "
1230
            print(
1166
                  "loading the Python ntp library may be troublesome ---")
1231
                "--- PYTHONARCHDIR not in PYTHONPATH, "
1232
                "loading the Python ntp library may be troublesome ---"
1233
            )
1234
1167
1235
1168
#
1236
#
1169
# Miscellaneous utility productions
1237
# Miscellaneous utility productions
Lines 1183-1196 def loccount(ctx): Link Here
1183
1251
1184
def cxfreeze(ctx):
1252
def cxfreeze(ctx):
1185
    "Create standalone binaries from Python scripts."
1253
    "Create standalone binaries from Python scripts."
1186
    ctx.exec_command("for prog in " + " ".join(python_scripts) +
1254
    ctx.exec_command(
1187
                     "; do cxfreeze $prog; done")
1255
        "for prog in " + " ".join(python_scripts) + "; do cxfreeze $prog; done"
1256
    )
1188
1257
1189
1258
1190
def linkcheck(ctx):
1259
def linkcheck(ctx):
1191
    "Report references without anchors in the documentation."
1260
    "Report references without anchors in the documentation."
1192
    ctx.exec_command("devel/linkcheck docs/")
1261
    ctx.exec_command("devel/linkcheck docs/")
1193
1262
1263
1194
# The following sets edit modes for GNU EMACS
1264
# The following sets edit modes for GNU EMACS
1195
# Local Variables:
1265
# Local Variables:
1196
# mode:python
1266
# mode:python
1197
- 

Return to bug 852143