[Git][NTPsec/ntpsec][master] 5 commits: probes.py: conform to pep8

Gary E. Miller gitlab at mg.gitlab.com
Wed Jan 4 00:10:58 UTC 2017


Gary E. Miller pushed to branch master at NTPsec / ntpsec


Commits:
5e6d745c by Gary E. Miller at 2017-01-03T14:59:25-08:00
probes.py: conform to pep8

- - - - -
4f84b26b by Gary E. Miller at 2017-01-03T15:05:46-08:00
options.py: conform to pep8

- - - - -
c66704c4 by Gary E. Miller at 2017-01-03T16:03:59-08:00
configure.py: conform to pep8

- - - - -
035f12d8 by Gary E. Miller at 2017-01-03T16:08:04-08:00
check_vsprintfm.py: conform to pep8

- - - - -
abf72ae0 by Gary E. Miller at 2017-01-03T16:09:55-08:00
check_type.py: conform to pep8

- - - - -


5 changed files:

- wafhelpers/check_type.py
- wafhelpers/check_vsprintfm.py
- wafhelpers/configure.py
- wafhelpers/options.py
- wafhelpers/probes.py


Changes:

=====================================
wafhelpers/check_type.py
=====================================
--- a/wafhelpers/check_type.py
+++ b/wafhelpers/check_type.py
@@ -8,17 +8,18 @@ int main(void) {
 }
 """
 
+
 @conf
 def check_type(ctx, typename, headers=[], mandatory=False):
-        name = "HAVE_%s" % typename.upper().replace(" ", "_")
-        src = ""
-        for hdr in headers:
-                src += "#include <%s>\n" % hdr
-        ctx.check_cc(
-                fragment        = src + TYPE_FRAG % (typename),
-                define_name = name,
-                execute     = False,
-                msg         = "Checking for type %s" % (typename),
-                mandatory       = mandatory,
-                comment         = "Whether type '%s' exists." % typename
-        )
+    name = "HAVE_%s" % typename.upper().replace(" ", "_")
+    src = ""
+    for hdr in headers:
+        src += "#include <%s>\n" % hdr
+    ctx.check_cc(
+        fragment=src + TYPE_FRAG % (typename),
+        define_name=name,
+        execute=False,
+        msg="Checking for type %s" % (typename),
+        mandatory=mandatory,
+        comment="Whether type '%s' exists." % typename
+    )


=====================================
wafhelpers/check_vsprintfm.py
=====================================
--- a/wafhelpers/check_vsprintfm.py
+++ b/wafhelpers/check_vsprintfm.py
@@ -33,19 +33,20 @@ int main(void)
 }
 '''
 
+
 def check_vsprintfm(ctx):
-        "Check for %m expanding to strerror(error) in glibc style."
-        ctx.check_cc(
-                fragment='''
+    "Check for %m expanding to strerror(error) in glibc style."
+    ctx.check_cc(
+        fragment='''
 #include <features.h>
 int main(void)
 {
-#ifndef __GLIBC__
-# error __GLIBC__ is not defined
-#endif
+        #ifndef __GLIBC__
+        # error __GLIBC__ is not defined
+        #endif
 }
 ''',
-                define_name="VSNPRINTF_PERCENT_M",
-                msg = "Checking for %m expansion in vsnprintf(3)",
-                mandatory = False,
-                comment="%m expanding to strerror(error) in glibc style")
+        define_name="VSNPRINTF_PERCENT_M",
+        msg="Checking for %m expansion in vsnprintf(3)",
+        mandatory=False,
+        comment="%m expanding to strerror(error) in glibc style")


=====================================
wafhelpers/configure.py
=====================================
--- a/wafhelpers/configure.py
+++ b/wafhelpers/configure.py
@@ -1,538 +1,599 @@
 from __future__ import print_function
 
-import sys, os, platform
-from wafhelpers.probes import probe_header_with_prerequisites, probe_function_with_prerequisites
+import sys
+import os
+import platform
+from wafhelpers.probes \
+    import probe_header_with_prerequisites, probe_function_with_prerequisites
 from wafhelpers.util import msg, msg_setting
 
-def cmd_configure(ctx, config):
-        srcnode = ctx.srcnode.abspath()
-        bldnode = ctx.bldnode.abspath()
-
-        ctx.run_build_cls = 'check'
-        ctx.load('waf', tooldir='wafhelpers/')
-        ctx.load('waf_unit_test')
-
-        from wafhelpers.util import parse_version
-        parse_version(config)
-
-        ctx.env.NTPSEC_VERSION_MAJOR = config["NTPSEC_VERSION_MAJOR"]
-        ctx.env.NTPSEC_VERSION_MINOR = config["NTPSEC_VERSION_MINOR"]
-        ctx.env.NTPSEC_VERSION_REV = config["NTPSEC_VERSION_REV"]
-
-        ctx.env.NTPSEC_VERSION = "%s.%s.%s" % (ctx.env.NTPSEC_VERSION_MAJOR, ctx.env.NTPSEC_VERSION_MINOR, ctx.env.NTPSEC_VERSION_REV)
-        ctx.define("NTPSEC_VERSION_MAJOR", ctx.env.NTPSEC_VERSION_MAJOR, comment="Major version number")
-        ctx.define("NTPSEC_VERSION_MINOR", ctx.env.NTPSEC_VERSION_MINOR, comment="Minor version number")
-        ctx.define("NTPSEC_VERSION_REV", ctx.env.NTPSEC_VERSION_REV, comment="Revision version number")
-
-        ctx.env.OPT_STORE = config["OPT_STORE"]
-
-        opt_map = {}
-        # Wipe out and override flags with those from the commandline
-        for flag in ctx.env.OPT_STORE:
-                if flag == "--undefine":
-                        for sym in ctx.env.OPT_STORE[flag]:
-                                ctx.undefine(sym)
-                elif flag == "--define":
-                        for symval in ctx.env.OPT_STORE[flag]:
-                                (sym, val) = symval.split("=")
-                                try:
-                                        ctx.define(sym, int(val))
-                                except ValueError:
-                                        ctx.define(sym, val)
-                else:
-                        opt = flag.replace("--", "").upper()
-                        opt_map[opt] = ctx.env.OPT_STORE[flag]
-
-        msg("--- Configuring host ---")
-        ctx.setenv('host', ctx.env.derive())
-
-        ctx.load('compiler_c')
-        ctx.load('bison')
-
-        for opt in opt_map:
-                ctx.env[opt] = opt_map[opt]
-
-        from wafhelpers.check_compiler import check_compiler
-        check_compiler(ctx)
-
-        if ctx.options.enable_rtems_trace:
-                ctx.find_program("rtems-tld", var="BIN_RTEMS_TLD", path_list=[ctx.options.rtems_trace_path, ctx.env.BINDIR])
-                ctx.env.RTEMS_TEST_ENABLE = True
-                ctx.env.RTEMS_TEST_FLAGS = ["-C", "%s/devel/trace/ntpsec-trace.ini" % srcnode,
-                                                                        "-W", "%s/ntpsec-wrapper" % bldnode,
-                                                                        "-P", "%s/devel/trace/" % srcnode,
-                                                                        "-f", "-I%s" % bldnode,
-                                                                        "-f", "-I%s/include/" % srcnode,
-                                                                        "-f", "-I%s/libisc/include/" % srcnode,
-                                                                        "-f", "-I%s/libisc/unix/include/" % srcnode]
-
-        # Not needed to build.  Used by utility scripts.
-        ctx.find_program("awk", var="BIN_AWK", mandatory=False)
-        ctx.find_program("sh", var="BIN_SH", mandatory=False)
-
-        # used to make man and html pages
-        ctx.find_program("asciidoc", var="BIN_ASCIIDOC", mandatory=False)
-        # make sure asciidoc is new enough. based on check_python_version() from waf
-        if ctx.env.BIN_ASCIIDOC:
-                # https://lists.ntpsec.org/pipermail/devel/2016-July/001778.html
-                asciidocminver = (8, 6, 0)
-                # Get asciidoc version string
-                cmd = ctx.env.BIN_ASCIIDOC + ['--version']
-                # example output: asciidoc 8.6.9
-                lines = ctx.cmd_and_log(cmd).split()[1].split(".")
-                assert len(lines) == 3, "found %r lines, expected 3: %r" % (len(lines), lines)
-                asciidocver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]))
-
-                # Compare asciidoc version with the minimum required
-                result = (asciidocver_tuple >= asciidocminver)
-
-                asciidocver_full = '.'.join(map(str, asciidocver_tuple[:3]))
-                asciidocminver_str = '.'.join(map(str, asciidocminver))
-                ctx.msg('Checking for asciidoc version >= %s' % (asciidocminver_str,), asciidocver_full, color=result and 'GREEN' or 'YELLOW')
-
-                if not result:
-                        del ctx.env.BIN_ASCIIDOC
-        ctx.find_program("a2x", var="BIN_A2X", mandatory=False)
-        ctx.find_program("xsltproc", var="BIN_XSLTPROC", mandatory=False)
-
-        ctx.env.ENABLE_DOC = False
-        if ctx.env.BIN_ASCIIDOC and ctx.env.BIN_XSLTPROC and ctx.env.BIN_A2X:
-                ctx.env.ENABLE_DOC = True
-
-        if (ctx.options.enable_doc or ctx.options.enable_doc_only) and not ctx.env.ENABLE_DOC:
-                ctx.fatal("asciidoc and xsltproc are required in order to build documentation")
-        elif (ctx.options.enable_doc or ctx.options.enable_doc_only):
-                ctx.env.ASCIIDOC_FLAGS = ["-f", "%s/docs/asciidoc.conf" % ctx.srcnode.abspath()]
-                ctx.env.ENABLE_DOC_ONLY = ctx.options.enable_doc_only
-                ctx.env.ENABLE_DOC_USER = ctx.options.enable_doc
-                ctx.env.HTMLDIR = ctx.options.htmldir
-
-        # XXX: conditionally build this with --disable-man?  Should it build without docs enabled?
-        ctx.env.A2X_FLAGS = ["--format", "manpage", "--asciidoc-opts=--conf-file=%s/docs/asciidoc.conf" % ctx.srcnode.abspath()]
-        if not ctx.options.enable_a2x_xmllint:
-                ctx.env.A2X_FLAGS += ["--no-xmllint"]
-
-        # Disable manpages within build()
-        if ctx.options.disable_manpage:
-                ctx.env.DISABLE_MANPAGE = True
-
-        ctx.env.SBINDIR = ctx.options.sbindir
-        ctx.env.MANDIR = ctx.options.mandir
-
-        from os.path import exists
-        from waflib.Utils import subprocess
-        if exists(".git") and ctx.find_program("git", var="BIN_GIT", mandatory=False):
-                ctx.start_msg("DEVEL: Getting revision")
-                cmd = ["git", "log", "-1", "--format=%H"]
-                p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
-                ctx.env.NTPSEC_REVISION, stderr = p.communicate()
-                ctx.env.NTPSEC_REVISION = ctx.env.NTPSEC_REVISION.replace("\n", "")
-                ctx.end_msg(ctx.env.NTPSEC_REVISION)
-
-        ctx.start_msg("Building version")
-        ctx.env.NTPSEC_VERSION_STRING = ctx.env.NTPSEC_VERSION
-
-        if ctx.env.NTPSEC_REVISION:
-                ctx.env.NTPSEC_VERSION_STRING += "-%s" % ctx.env.NTPSEC_REVISION[:7]
-
-        if ctx.options.build_version_tag:
-                ctx.env.NTPSEC_VERSION_STRING += "-%s" % ctx.options.build_version_tag
-
-        ctx.define("NTPSEC_VERSION_STRING", ctx.env.NTPSEC_VERSION_STRING)
-        ctx.end_msg(ctx.env.NTPSEC_VERSION_STRING)
-
-        msg("--- Configuring main ---")
-        ctx.setenv("main", ctx.env.derive())
-
-        # XXX: temp hack to fix --enable-doc-only
-        ctx.env.ENABLE_DOC_ONLY = ctx.options.enable_doc_only
-
-        # The rest is not needed for documentation building.
-        if ctx.options.enable_doc_only:
-                return
-
-        from wafhelpers.check_type import check_type
-        from wafhelpers.check_sizeof import check_sizeof
-        from wafhelpers.check_structfield import check_structfield
-
-        for opt in opt_map:
-                ctx.env[opt] = opt_map[opt]
-
-        if ctx.options.cross_compiler:
-                ctx.env.ENABLE_CROSS = True
-
-                ctx.start_msg("Using Cross compiler CC:")
-#               ctx.get_cc_version(ctx.env.CC, gcc=True)
-                ctx.end_msg(ctx.options.cross_compiler)
-
-                ctx.env.CC = [ctx.options.cross_compiler]
-                ctx.env.LINK_CC = [ctx.options.cross_compiler]
-
-                if ctx.env["CROSS-CFLAGS"]:
-                        ctx.env.CFLAGS = opt_map["CROSS-CFLAGS"]
-
-                if ctx.env["CROSS-LDFLAGS"]:
-                        ctx.env.LDFLAGS = opt_map["CROSS-LDFLAGS"]
 
-        if ctx.options.list:
-                from wafhelpers.refclock import refclock_map
-                print("ID    Description")
-                print("~~    ~~~~~~~~~~~")
-                for id in refclock_map:
-                        print("%-5s %s" % (id, refclock_map[id]["descr"]))
-
-                return
-
-        # This needs to be at the top since it modifies CC and AR
-        if ctx.options.enable_fortify:
-                from wafhelpers.check_fortify import check_fortify
-                check_fortify(ctx)
-
-        if ctx.options.enable_debug_gdb:
-                ctx.env.CFLAGS += ["-g"]
-
-        if not ctx.options.disable_debug:
-                ctx.define("DEBUG", 1, comment="Enable debug mode")
-                ctx.env.BISONFLAGS += ["--debug"]
-
-        ctx.env.CFLAGS += ["-Wall", "-Wextra", "-Wstrict-prototypes"]
-        # We require some things that C99 doesn't enable, like pthreads.
-        # Thus -std=gnu99 rather than -std=c99 here, if the compiler supports
-        # it.
-        if ctx.env.COMPILER_SUNCC:
-                ctx.env.CFLAGS += ["-std=c99"]
-        else:
-                ctx.env.CFLAGS += ["-std=gnu99"]
-
-        # Check target platform.
-        ctx.start_msg("Checking build target")
-        if sys.platform == "win32":
-                ctx.env.PLATFORM_TARGET = "win"
-        elif sys.platform == "darwin":
-                ctx.env.PLATFORM_TARGET = "osx"
-        elif sys.platform.startswith("freebsd"):
-                ctx.env.PLATFORM_TARGET = "freebsd"
-        elif sys.platform.startswith("netbsd"):
-                ctx.env.PLATFORM_TARGET = "netbsd"
-        elif sys.platform.startswith("openbsd"):
-                ctx.env.PLATFORM_TARGET = "openbsd"
-        else:
-                ctx.env.PLATFORM_TARGET = "unix"
-        ctx.end_msg(ctx.env.PLATFORM_TARGET     )
-
-        ctx.define("PLATFORM_%s" % ctx.env.PLATFORM_TARGET.upper(), 1, comment="Operating system detected by Python (%s)" % platform)
-
-        # XXX: hack
-        if ctx.env.PLATFORM_TARGET in ["freebsd", "osx", "openbsd"]:
-                ctx.env.PLATFORM_INCLUDES = ["/usr/local/include"]
-                ctx.env.PLATFORM_LIBPATH = ["/usr/local/lib"]
-        elif ctx.env.PLATFORM_TARGET == "netbsd":
-                ctx.env.PLATFORM_LIBPATH = ["/usr/lib"]
-        elif ctx.env.PLATFORM_TARGET == "win":
-                ctx.load("msvc")
-
-        # OS X needs this for IPv6
-        if ctx.env.PLATFORM_TARGET == "osx":
-                ctx.define("__APPLE_USE_RFC_3542", 1, comment="Needed for IPv6 support")
-
-        ctx.define("PLATFORM_FULL", platform.platform())
-
-        # int32_t and uint32_t probes aren't really needed, POSIX guarantees
-        # them.  But int64_t and uint64_t are not guaranteed to exist on 32-bit
-        # machines.  The calendar and ISC code needs them.
-        types = ["uint64_t"]
-
-        for inttype in sorted(types):
-                check_type(ctx, inttype, ["stdint.h", "sys/types.h"])
-
-        net_types = (
-                ("struct if_laddrconf", ["sys/types.h", "net/if6.h"]),
-                ("struct if_laddrreq", ["sys/types.h", "net/if6.h"]),
-        )
-        for (f, h) in net_types:
-                check_type(ctx, f, h)
-
-        structures = (
-                ("struct timex", ["sys/time.h", "sys/timex.h"]),
-                ("struct ntptimeval", ["sys/time.h", "sys/timex.h"]),
-        )
-        for (s, h) in structures:
-                check_type(ctx, s, h)
-
-        structure_fields = (
-                ("time_tick", "timex", ["sys/time.h", "sys/timex.h"]),
-                ("modes", "timex", ["sys/time.h", "sys/timex.h"]),
-                ("time.tv_nsec", "ntptimeval", ["sys/time.h", "sys/timex.h"]),
-                ("tai", "ntptimeval", ["sys/time.h", "sys/timex.h"]), # first in glibc 2.12
-        )
-        for (f, s, h) in structure_fields:
-                check_structfield(ctx, f, s, h)
-
-        # mostly used by timetoa.h and timespecops.h
-        sizeofs = [
-                ("time.h",              "time_t"),
-                (None,                  "int"),
-                (None,                  "long"),
-                (None,                  "long long"),
-        ]
-
-        for header, sizeof in sorted(sizeofs, key=lambda x: x[1:]):
-                check_sizeof(ctx, header, sizeof)
-
-        ctx.define("NTP_KEYSDIR", "%s/etc" % ctx.env.PREFIX, comment="NTP key file directory")
-        ctx.define("GETSOCKNAME_SOCKLEN_TYPE", "socklen_t", quote=False, comment="socklen type")
-        ctx.define("DFLT_RLIMIT_STACK", 50, comment="Default stack size")
-
-        ctx.define("TYPEOF_IP_MULTICAST_LOOP", "u_char", quote=False, comment="Multicast loop type") #XXX: check for mcast type
-
-        # These are helpful and don't break Linux or *BSD
-        ctx.define("OPEN_BCAST_SOCKET", 1, comment="Whether to open a broadcast socket")
-        ctx.define("HAS_ROUTING_SOCKET", 1, comment="Whether a routing socket exists")
-
-        ctx.check_cc(lib="m", comment="Math library")
-        ctx.check_cc(lib="rt", mandatory=False, comment="realtime library")
-
-        # Find OpenSSL. Must happen before function checks
-        if ctx.options.enable_crypto:
-                from wafhelpers.check_openssl import configure_ssl
-                configure_ssl(ctx)
-
-        # Optional functions.  Do all function checks here, otherwise
-        # we're likely to duplicate them.
-        functions = (
-                ('adjtimex', ["sys/time.h", "sys/timex.h"]),
-                ('closefrom', ["stdlib.h"]),
-                ('clock_gettime', ["time.h"], "RT"),
-                ('clock_settime', ["time.h"], "RT"),
-                ('EVP_MD_do_all_sorted', ["openssl/evp.h"], "CRYPTO"),
-                ('getdtablesize', ["unistd.h"]),
-                ('getrusage', ["sys/time.h", "sys/resource.h"]),
-                ('MD5Init', ["md5.h"], "CRYPTO"),
-                ('ntp_adjtime', ["sys/time.h", "sys/timex.h"]),         # BSD
-                ('ntp_gettime', ["sys/time.h", "sys/timex.h"]),         # BSD
-                ('res_init', ["resolv.h"]),
-                ('sched_setscheduler', ["sched.h"]),
-                ('strlcpy', ["string.h"]),
-                ('strlcat', ["string.h"]),
-                ('timer_create', ["time.h"])
-        )
-        for ft in functions:
-                if len(ft) == 2:
-                        probe_function_with_prerequisites(ctx, function=ft[0],
-                                                          prerequisites=ft[1])
-                else:
-                        probe_function_with_prerequisites(ctx, function=ft[0],
-                                                          prerequisites=ft[1],
-                                                          use=ft[2])
-
-        # Nobody uses the symbol, but this seems like a good sanity check.
-        ctx.check_cc(header_name="stdbool.h", mandatory=True, comment="Sanity check.")
-
-        # This is a list of every optional include header in the
-        # codebase that is guarded by a directly corresponding HAVE_*_H symbol.
-        #
-        # In some cases one HAVE symbol controls inclusion of more
-        # than one header.  In these cases only the one header name
-        # matching the pattern of the HAVE_*_H symbol name is listed
-        # here, so we can invert the relationship to generate tests
-        # for all the symbols.
-        #
-        # Some of these are cruft from ancient big-iron systems and should
-        # be removed.
-        optional_headers = (
-                "alloca.h",
-                ("arpa/nameser.h", ["sys/types.h"]),
-                "dns_sd.h",             # NetBSD, Apple, mDNS
-                ("ifaddrs.h", ["sys/types.h"]),
-                ("libscf.h", ["sys/time.h"]),  # Solaris
-                ("linux/if_addr.h", ["sys/socket.h"]),
-                ("linux/rtnetlink.h", ["sys/socket.h"]),
-                "linux/serial.h",
-                ("md5.h", ["sys/types.h"]),
-                "net/if6.h",
-                ("net/route.h", ["sys/types.h", "sys/socket.h", "net/if.h"]),
-                "netinfo/ni.h",         # Apple
-                "priv.h",               # Solaris
-                ("resolv.h", ["sys/types.h", "netinet/in.h", "arpa/nameser.h"]),
-                "semaphore.h",
-                "stdatomic.h",
-                "sys/clockctl.h",       # NetBSD
-                "sys/ioctl.h",
-                "sys/modem.h",          # Apple
-                "sys/sockio.h",
-                ("sys/sysctl.h", ["sys/types.h"]),
-                ("timepps.h", ["inttypes.h"]),
-                ("sys/timepps.h", ["inttypes.h", "sys/time.h"]),
-                "utmpx.h",       # missing on RTEMS and OpenBSD
-                ("sys/timex.h", ["sys/time.h"]),
-        )
-        for hdr in optional_headers:
-                if isinstance(hdr, str):
-                        if ctx.check_cc(header_name=hdr, mandatory=False, comment="<%s> header" % hdr):
-                                continue
-                else:
-                        (hdr, prereqs) = hdr
-                        if probe_header_with_prerequisites(ctx, hdr, prereqs):
-                                continue
-                if os.path.exists("/usr/include/" + hdr):
-                        # Sanity check...
-                        print("Compilation check failed but include exists %s" % hdr)
-
-        if ctx.get_define("HAVE_TIMEPPS_H") or ctx.get_define("HAVE_SYS_TIMEPPS_H"):
-                ctx.define("HAVE_PPSAPI", 1, comment="Enable the PPS API")
-
-        # Check for Solaris capabilities
-        if ctx.get_define("HAVE_PRIV_H") and sys.platform.startswith("sunos"):
-                ctx.define("HAVE_SOLARIS_PRIVS", 1, comment="Enable Solaris Privileges (Solaris only)")
-
-        from wafhelpers.check_sockaddr import check_sockaddr
-        check_sockaddr(ctx)
-
-        # Some systems don't have sys/timex.h eg OS X, OpenBSD...
-        if ctx.get_define("HAVE_SYS_TIMEX_H"):
-                ctx.env.HEADER_SYS_TIMEX_H = True
-
-        if ctx.options.refclocks:
-                from wafhelpers.refclock import refclock_config
-                refclock_config(ctx)
-
-        # NetBSD (used to) need to recreate sockets on changed routing.
-        # Perhaps it still does. If so, this should be set.  The autoconf
-        # build set it "if the OS clears cached routes when more specifics
-        # become available".
-        # ctx.define("OS_MISSES_SPECIFIC_ROUTE_UPDATES", 1)
-
-        if ctx.options.enable_leap_smear:
-                ctx.define("ENABLE_LEAP_SMEAR", 1, comment="Enable experimental leap smearing code")
-
-        if ctx.options.enable_mssntp:
-                ctx.define("ENABLE_MSSNTP", 1, comment="Enable MS-SNTP extensions https://msdn.microsoft.com/en-us/library/cc212930.aspx")
-
-        if ctx.options.enable_lockclock:
-            if ctx.env.REFCLOCK_LOCAL:
-                ctx.define("ENABLE_LOCKCLOCK", 1, comment="Enable NIST 'lockclock'")
-            else:
-                import waflib.Errors
-                raise waflib.Errors.WafError("NIST 'lockclock' requires refclock 'local'")
-
-        if not ctx.options.disable_droproot:
-                ctx.define("ENABLE_DROPROOT", 1, comment="Drop root after initialising")
-        if ctx.options.enable_early_droproot:
-                ctx.define("ENABLE_EARLY_DROPROOT", 1, comment="Enable early drop root")
-        if ctx.options.enable_seccomp:
-                ctx.define("ENABLE_SECCOMP", 1, comment="Enable seccomp")
-
-        if not ctx.options.disable_dns_lookup:
-                ctx.define("ENABLE_DNS_LOOKUP", 1, comment="Enable DNS lookup of hostnames")
-
-        if not ctx.options.disable_dns_retry:
-                ctx.define("ENABLE_DNS_RETRY", 1, comment="Retry DNS lookups after an initial failure")
-
-        # This is true under every Unix-like OS.
-        ctx.define("HAVE_WORKING_FORK", 1, comment="Whether a working fork() exists")
-
-        # Does the kernel implement a phase-locked loop for timing?
-        # All modern Unixes (in particular Linux and *BSD) have this.
-        #
-        # The README for the (now deleted) kernel directory says this:
-        # "If the precision-time kernel (KERNEL_PLL define) is
-        # configured, the installation process requires the header
-        # file /usr/include/sys/timex.h for the particular
-        # architecture to be in place."
-        #
-        if ctx.get_define("HAVE_SYS_TIMEX_H") and not ctx.options.disable_kernel_pll:
-                ctx.define("HAVE_KERNEL_PLL", 1, comment="Whether phase-locked loop for timing exists and is enabled")
-
-        # SO_REUSEADDR socket option is needed to open a socket on an
-        # interface when the port number is already in use on another
-        # interface. Linux needs this, NetBSD does not, status on
-        # other platforms is unknown.  It is probably harmless to
-        # have it on everywhere.
-        ctx.define("NEED_REUSEADDR_FOR_IFADDRBIND", 1, comment="Whether SO_REUSEADDR is needed to open same sockets on alternate interfaces, required by Linux at least")
-
-        # These are required by the SHA2 code and various refclocks
-        if sys.byteorder == "little":
-                pass
-        elif sys.byteorder == "big":
-                ctx.define("WORDS_BIGENDIAN", 1)
+def cmd_configure(ctx, config):
+    srcnode = ctx.srcnode.abspath()
+    bldnode = ctx.bldnode.abspath()
+
+    ctx.run_build_cls = 'check'
+    ctx.load('waf', tooldir='wafhelpers/')
+    ctx.load('waf_unit_test')
+
+    from wafhelpers.util import parse_version
+    parse_version(config)
+
+    ctx.env.NTPSEC_VERSION_MAJOR = config["NTPSEC_VERSION_MAJOR"]
+    ctx.env.NTPSEC_VERSION_MINOR = config["NTPSEC_VERSION_MINOR"]
+    ctx.env.NTPSEC_VERSION_REV = config["NTPSEC_VERSION_REV"]
+
+    ctx.env.NTPSEC_VERSION = "%s.%s.%s" % (ctx.env.NTPSEC_VERSION_MAJOR,
+                                           ctx.env.NTPSEC_VERSION_MINOR,
+                                           ctx.env.NTPSEC_VERSION_REV)
+    ctx.define("NTPSEC_VERSION_MAJOR", ctx.env.NTPSEC_VERSION_MAJOR,
+               comment="Major version number")
+    ctx.define("NTPSEC_VERSION_MINOR", ctx.env.NTPSEC_VERSION_MINOR,
+               comment="Minor version number")
+    ctx.define("NTPSEC_VERSION_REV", ctx.env.NTPSEC_VERSION_REV,
+               comment="Revision version number")
+
+    ctx.env.OPT_STORE = config["OPT_STORE"]
+
+    opt_map = {}
+    # Wipe out and override flags with those from the commandline
+    for flag in ctx.env.OPT_STORE:
+        if flag == "--undefine":
+            for sym in ctx.env.OPT_STORE[flag]:
+                ctx.undefine(sym)
+        elif flag == "--define":
+            for symval in ctx.env.OPT_STORE[flag]:
+                (sym, val) = symval.split("=")
+                try:
+                    ctx.define(sym, int(val))
+                except ValueError:
+                    ctx.define(sym, val)
         else:
-                print("Can't determine byte order!")
-
-        from wafhelpers.check_vsprintfm import check_vsprintfm
-        check_vsprintfm(ctx)
-
-        # Define CFLAGS/LDCFLAGS for -vv support.
-        ctx.define("NTPSEC_CFLAGS", " ".join(ctx.env.CFLAGS).replace("\"", "\\\""), comment="CFLAGS used when compiled")
-        ctx.define("NTPSEC_LDFLAGS", " ".join(ctx.env.LDFLAGS).replace("\"", "\\\""), comment="LDFLAGS used when compiled")
-
-        # Check for directory separator
-        if ctx.env.PLATFORM_TARGET == "win":
-                sep = "\\"
+            opt = flag.replace("--", "").upper()
+            opt_map[opt] = ctx.env.OPT_STORE[flag]
+
+    msg("--- Configuring host ---")
+    ctx.setenv('host', ctx.env.derive())
+
+    ctx.load('compiler_c')
+    ctx.load('bison')
+
+    for opt in opt_map:
+        ctx.env[opt] = opt_map[opt]
+
+    from wafhelpers.check_compiler import check_compiler
+    check_compiler(ctx)
+
+    if ctx.options.enable_rtems_trace:
+        ctx.find_program("rtems-tld", var="BIN_RTEMS_TLD",
+                         path_list=[ctx.options.rtems_trace_path,
+                                    ctx.env.BINDIR])
+        ctx.env.RTEMS_TEST_ENABLE = True
+        ctx.env.RTEMS_TEST_FLAGS = [
+            "-C", "%s/devel/trace/ntpsec-trace.ini" % srcnode,
+            "-W", "%s/ntpsec-wrapper" % bldnode,
+            "-P", "%s/devel/trace/" % srcnode,
+            "-f", "-I%s" % bldnode,
+            "-f", "-I%s/include/" % srcnode,
+            "-f", "-I%s/libisc/include/" % srcnode,
+            "-f", "-I%s/libisc/unix/include/" % srcnode]
+
+    # Not needed to build.  Used by utility scripts.
+    ctx.find_program("awk", var="BIN_AWK", mandatory=False)
+    ctx.find_program("sh", var="BIN_SH", mandatory=False)
+
+    # used to make man and html pages
+    ctx.find_program("asciidoc", var="BIN_ASCIIDOC", mandatory=False)
+    # make sure asciidoc is new enough.
+    # based on check_python_version() from waf
+    if ctx.env.BIN_ASCIIDOC:
+        # https://lists.ntpsec.org/pipermail/devel/2016-July/001778.html
+        asciidocminver = (8, 6, 0)
+        # Get asciidoc version string
+        cmd = ctx.env.BIN_ASCIIDOC + ['--version']
+        # example output: asciidoc 8.6.9
+        lines = ctx.cmd_and_log(cmd).split()[1].split(".")
+        assert len(lines) == 3, "found %r lines, expected 3: %r" \
+            % (len(lines), lines)
+        asciidocver_tuple = (int(lines[0]), int(lines[1]), int(lines[2]))
+
+        # Compare asciidoc version with the minimum required
+        result = (asciidocver_tuple >= asciidocminver)
+
+        asciidocver_full = '.'.join(map(str, asciidocver_tuple[:3]))
+        asciidocminver_str = '.'.join(map(str, asciidocminver))
+        ctx.msg('Checking for asciidoc version >= %s' % (asciidocminver_str,),
+                asciidocver_full, color=result and 'GREEN' or 'YELLOW')
+
+        if not result:
+            del ctx.env.BIN_ASCIIDOC
+    ctx.find_program("a2x", var="BIN_A2X", mandatory=False)
+    ctx.find_program("xsltproc", var="BIN_XSLTPROC", mandatory=False)
+
+    ctx.env.ENABLE_DOC = False
+    if ctx.env.BIN_ASCIIDOC and ctx.env.BIN_XSLTPROC and ctx.env.BIN_A2X:
+        ctx.env.ENABLE_DOC = True
+
+    if (((ctx.options.enable_doc or ctx.options.enable_doc_only)
+         and not ctx.env.ENABLE_DOC)):
+        ctx.fatal("asciidoc and xsltproc are required in order "
+                  "to build documentation")
+    elif (ctx.options.enable_doc or ctx.options.enable_doc_only):
+        ctx.env.ASCIIDOC_FLAGS = ["-f", "%s/docs/asciidoc.conf"
+                                  % ctx.srcnode.abspath()]
+        ctx.env.ENABLE_DOC_ONLY = ctx.options.enable_doc_only
+        ctx.env.ENABLE_DOC_USER = ctx.options.enable_doc
+        ctx.env.HTMLDIR = ctx.options.htmldir
+
+    # XXX: conditionally build this with --disable-man?
+    # Should it build without docs enabled?
+    ctx.env.A2X_FLAGS = ["--format", "manpage",
+                         "--asciidoc-opts=--conf-file=%s/docs/asciidoc.conf"
+                         % ctx.srcnode.abspath()]
+    if not ctx.options.enable_a2x_xmllint:
+        ctx.env.A2X_FLAGS += ["--no-xmllint"]
+
+    # Disable manpages within build()
+    if ctx.options.disable_manpage:
+        ctx.env.DISABLE_MANPAGE = True
+
+    ctx.env.SBINDIR = ctx.options.sbindir
+    ctx.env.MANDIR = ctx.options.mandir
+
+    from os.path import exists
+    from waflib.Utils import subprocess
+    if ((exists(".git")
+         and ctx.find_program("git", var="BIN_GIT", mandatory=False))):
+        ctx.start_msg("DEVEL: Getting revision")
+        cmd = ["git", "log", "-1", "--format=%H"]
+        p = subprocess.Popen(cmd, stdin=subprocess.PIPE,
+                             stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE, universal_newlines=True)
+        ctx.env.NTPSEC_REVISION, stderr = p.communicate()
+        ctx.env.NTPSEC_REVISION = ctx.env.NTPSEC_REVISION.replace("\n", "")
+        ctx.end_msg(ctx.env.NTPSEC_REVISION)
+
+    ctx.start_msg("Building version")
+    ctx.env.NTPSEC_VERSION_STRING = ctx.env.NTPSEC_VERSION
+
+    if ctx.env.NTPSEC_REVISION:
+        ctx.env.NTPSEC_VERSION_STRING += "-%s" % ctx.env.NTPSEC_REVISION[:7]
+
+    if ctx.options.build_version_tag:
+        ctx.env.NTPSEC_VERSION_STRING += "-%s" % ctx.options.build_version_tag
+
+    ctx.define("NTPSEC_VERSION_STRING", ctx.env.NTPSEC_VERSION_STRING)
+    ctx.end_msg(ctx.env.NTPSEC_VERSION_STRING)
+
+    msg("--- Configuring main ---")
+    ctx.setenv("main", ctx.env.derive())
+
+    # XXX: temp hack to fix --enable-doc-only
+    ctx.env.ENABLE_DOC_ONLY = ctx.options.enable_doc_only
+
+    # The rest is not needed for documentation building.
+    if ctx.options.enable_doc_only:
+        return
+
+    from wafhelpers.check_type import check_type
+    from wafhelpers.check_sizeof import check_sizeof
+    from wafhelpers.check_structfield import check_structfield
+
+    for opt in opt_map:
+        ctx.env[opt] = opt_map[opt]
+
+    if ctx.options.cross_compiler:
+        ctx.env.ENABLE_CROSS = True
+
+        ctx.start_msg("Using Cross compiler CC:")
+#           ctx.get_cc_version(ctx.env.CC, gcc=True)
+        ctx.end_msg(ctx.options.cross_compiler)
+
+        ctx.env.CC = [ctx.options.cross_compiler]
+        ctx.env.LINK_CC = [ctx.options.cross_compiler]
+
+        if ctx.env["CROSS-CFLAGS"]:
+            ctx.env.CFLAGS = opt_map["CROSS-CFLAGS"]
+
+        if ctx.env["CROSS-LDFLAGS"]:
+            ctx.env.LDFLAGS = opt_map["CROSS-LDFLAGS"]
+
+    if ctx.options.list:
+        from wafhelpers.refclock import refclock_map
+        print("ID    Description")
+        print("~~    ~~~~~~~~~~~")
+        for id in refclock_map:
+            print("%-5s %s" % (id, refclock_map[id]["descr"]))
+
+        return
+
+    # This needs to be at the top since it modifies CC and AR
+    if ctx.options.enable_fortify:
+        from wafhelpers.check_fortify import check_fortify
+        check_fortify(ctx)
+
+    if ctx.options.enable_debug_gdb:
+        ctx.env.CFLAGS += ["-g"]
+
+    if not ctx.options.disable_debug:
+        ctx.define("DEBUG", 1, comment="Enable debug mode")
+        ctx.env.BISONFLAGS += ["--debug"]
+
+    ctx.env.CFLAGS += ["-Wall", "-Wextra", "-Wstrict-prototypes"]
+    # We require some things that C99 doesn't enable, like pthreads.
+    # Thus -std=gnu99 rather than -std=c99 here, if the compiler supports
+    # it.
+    if ctx.env.COMPILER_SUNCC:
+        ctx.env.CFLAGS += ["-std=c99"]
+    else:
+        ctx.env.CFLAGS += ["-std=gnu99"]
+
+    # Check target platform.
+    ctx.start_msg("Checking build target")
+    if sys.platform == "win32":
+        ctx.env.PLATFORM_TARGET = "win"
+    elif sys.platform == "darwin":
+        ctx.env.PLATFORM_TARGET = "osx"
+    elif sys.platform.startswith("freebsd"):
+        ctx.env.PLATFORM_TARGET = "freebsd"
+    elif sys.platform.startswith("netbsd"):
+        ctx.env.PLATFORM_TARGET = "netbsd"
+    elif sys.platform.startswith("openbsd"):
+        ctx.env.PLATFORM_TARGET = "openbsd"
+    else:
+        ctx.env.PLATFORM_TARGET = "unix"
+    ctx.end_msg(ctx.env.PLATFORM_TARGET)
+
+    ctx.define("PLATFORM_%s" % ctx.env.PLATFORM_TARGET.upper(), 1,
+               comment="Operating system detected by Python (%s)" % platform)
+
+    # XXX: hack
+    if ctx.env.PLATFORM_TARGET in ["freebsd", "osx", "openbsd"]:
+        ctx.env.PLATFORM_INCLUDES = ["/usr/local/include"]
+        ctx.env.PLATFORM_LIBPATH = ["/usr/local/lib"]
+    elif ctx.env.PLATFORM_TARGET == "netbsd":
+        ctx.env.PLATFORM_LIBPATH = ["/usr/lib"]
+    elif ctx.env.PLATFORM_TARGET == "win":
+        ctx.load("msvc")
+
+    # OS X needs this for IPv6
+    if ctx.env.PLATFORM_TARGET == "osx":
+        ctx.define("__APPLE_USE_RFC_3542", 1,
+                   comment="Needed for IPv6 support")
+
+    ctx.define("PLATFORM_FULL", platform.platform())
+
+    # int32_t and uint32_t probes aren't really needed, POSIX guarantees
+    # them.  But int64_t and uint64_t are not guaranteed to exist on 32-bit
+    # machines.  The calendar and ISC code needs them.
+    types = ["uint64_t"]
+
+    for inttype in sorted(types):
+        check_type(ctx, inttype, ["stdint.h", "sys/types.h"])
+
+    net_types = (
+        ("struct if_laddrconf", ["sys/types.h", "net/if6.h"]),
+        ("struct if_laddrreq", ["sys/types.h", "net/if6.h"]),
+    )
+    for (f, h) in net_types:
+        check_type(ctx, f, h)
+
+    structures = (
+        ("struct timex", ["sys/time.h", "sys/timex.h"]),
+        ("struct ntptimeval", ["sys/time.h", "sys/timex.h"]),
+    )
+    for (s, h) in structures:
+        check_type(ctx, s, h)
+
+    structure_fields = (
+        ("time_tick", "timex", ["sys/time.h", "sys/timex.h"]),
+        ("modes", "timex", ["sys/time.h", "sys/timex.h"]),
+        ("time.tv_nsec", "ntptimeval", ["sys/time.h", "sys/timex.h"]),
+        ("tai", "ntptimeval", ["sys/time.h", "sys/timex.h"]),
+        # first in glibc 2.12
+    )
+    for (f, s, h) in structure_fields:
+        check_structfield(ctx, f, s, h)
+
+    # mostly used by timetoa.h and timespecops.h
+    sizeofs = [
+        ("time.h",          "time_t"),
+        (None,          "int"),
+        (None,          "long"),
+        (None,          "long long"),
+    ]
+
+    for header, sizeof in sorted(sizeofs, key=lambda x: x[1:]):
+        check_sizeof(ctx, header, sizeof)
+
+    ctx.define("NTP_KEYSDIR", "%s/etc" % ctx.env.PREFIX,
+               comment="NTP key file directory")
+    ctx.define("GETSOCKNAME_SOCKLEN_TYPE", "socklen_t", quote=False,
+               comment="socklen type")
+    ctx.define("DFLT_RLIMIT_STACK", 50, comment="Default stack size")
+
+    ctx.define("TYPEOF_IP_MULTICAST_LOOP", "u_char", quote=False,
+               comment="Multicast loop type")   # XXX: check for mcast type
+
+    # These are helpful and don't break Linux or *BSD
+    ctx.define("OPEN_BCAST_SOCKET", 1,
+               comment="Whether to open a broadcast socket")
+    ctx.define("HAS_ROUTING_SOCKET", 1,
+               comment="Whether a routing socket exists")
+
+    ctx.check_cc(lib="m", comment="Math library")
+    ctx.check_cc(lib="rt", mandatory=False, comment="realtime library")
+
+    # Find OpenSSL. Must happen before function checks
+    if ctx.options.enable_crypto:
+        from wafhelpers.check_openssl import configure_ssl
+        configure_ssl(ctx)
+
+    # Optional functions.  Do all function checks here, otherwise
+    # we're likely to duplicate them.
+    functions = (
+        ('adjtimex', ["sys/time.h", "sys/timex.h"]),
+        ('closefrom', ["stdlib.h"]),
+        ('clock_gettime', ["time.h"], "RT"),
+        ('clock_settime', ["time.h"], "RT"),
+        ('EVP_MD_do_all_sorted', ["openssl/evp.h"], "CRYPTO"),
+        ('getdtablesize', ["unistd.h"]),
+        ('getrusage', ["sys/time.h", "sys/resource.h"]),
+        ('MD5Init', ["md5.h"], "CRYPTO"),
+        ('ntp_adjtime', ["sys/time.h", "sys/timex.h"]),     # BSD
+        ('ntp_gettime', ["sys/time.h", "sys/timex.h"]),     # BSD
+        ('res_init', ["resolv.h"]),
+        ('sched_setscheduler', ["sched.h"]),
+        ('strlcpy', ["string.h"]),
+        ('strlcat', ["string.h"]),
+        ('timer_create', ["time.h"])
+    )
+    for ft in functions:
+        if len(ft) == 2:
+            probe_function_with_prerequisites(ctx, function=ft[0],
+                                              prerequisites=ft[1])
         else:
-                sep = "/"
-
-        ctx.define("DIR_SEP", "'%s'" % sep, quote=False, comment="Directory separator used")
-
-        # libisc/
-        # XXX: Hack that needs to be fixed properly for all platforms
-        ctx.define("ISC_PLATFORM_NORETURN_PRE", "", quote=False)
-        ctx.define("ISC_PLATFORM_NORETURN_POST", "__attribute__((__noreturn__))", quote=False)
-
-        if ctx.get_define("HAVE_SYS_SYSCTL_H"):
-                ctx.define("HAVE_IFLIST_SYSCTL", 1, comment="Whether sysctl interface exists")
-
-        # Header/library checks
-        from wafhelpers.check_cap import check_cap
-        check_cap(ctx)
-
-        from wafhelpers.check_seccomp import check_seccomp
-        check_seccomp(ctx)
-
-        from wafhelpers.check_pthread import check_pthread_header_lib
-        check_pthread_header_lib(ctx)
-
-        if not ctx.options.disable_mdns_registration:
-                from wafhelpers.check_mdns import check_mdns_header
-                check_mdns_header(ctx)
-
-        if not ctx.options.disable_dns_retry:
-            from wafhelpers.check_pthread import check_pthread_run
-            check_pthread_run(ctx)
-
-        if not ctx.options.disable_mdns_registration:
-            from wafhelpers.check_mdns import check_mdns_run
-            check_mdns_run(ctx)
-
-        if ctx.options.enable_classic_mode:
-            ctx.define("ENABLE_CLASSIC_MODE", 1)
+            probe_function_with_prerequisites(ctx, function=ft[0],
+                                              prerequisites=ft[1],
+                                              use=ft[2])
+
+    # Nobody uses the symbol, but this seems like a good sanity check.
+    ctx.check_cc(header_name="stdbool.h", mandatory=True,
+                 comment="Sanity check.")
+
+    # This is a list of every optional include header in the
+    # codebase that is guarded by a directly corresponding HAVE_*_H symbol.
+    #
+    # In some cases one HAVE symbol controls inclusion of more
+    # than one header.  In these cases only the one header name
+    # matching the pattern of the HAVE_*_H symbol name is listed
+    # here, so we can invert the relationship to generate tests
+    # for all the symbols.
+    #
+    # Some of these are cruft from ancient big-iron systems and should
+    # be removed.
+    optional_headers = (
+        "alloca.h",
+        ("arpa/nameser.h", ["sys/types.h"]),
+        "dns_sd.h",         # NetBSD, Apple, mDNS
+        ("ifaddrs.h", ["sys/types.h"]),
+        ("libscf.h", ["sys/time.h"]),  # Solaris
+        ("linux/if_addr.h", ["sys/socket.h"]),
+        ("linux/rtnetlink.h", ["sys/socket.h"]),
+        "linux/serial.h",
+        ("md5.h", ["sys/types.h"]),
+        "net/if6.h",
+        ("net/route.h", ["sys/types.h", "sys/socket.h", "net/if.h"]),
+        "netinfo/ni.h",     # Apple
+        "priv.h",           # Solaris
+        ("resolv.h", ["sys/types.h", "netinet/in.h", "arpa/nameser.h"]),
+        "semaphore.h",
+        "stdatomic.h",
+        "sys/clockctl.h",       # NetBSD
+        "sys/ioctl.h",
+        "sys/modem.h",      # Apple
+        "sys/sockio.h",
+        ("sys/sysctl.h", ["sys/types.h"]),
+        ("timepps.h", ["inttypes.h"]),
+        ("sys/timepps.h", ["inttypes.h", "sys/time.h"]),
+        "utmpx.h",       # missing on RTEMS and OpenBSD
+        ("sys/timex.h", ["sys/time.h"]),
+    )
+    for hdr in optional_headers:
+        if isinstance(hdr, str):
+            if ctx.check_cc(header_name=hdr, mandatory=False,
+                            comment="<%s> header" % hdr):
+                continue
         else:
-            ctx.undefine("ENABLE_CLASSIC_MODE")
-
-        if ctx.options.enable_debug_timing:
-            ctx.define("ENABLE_DEBUG_TIMING", 1)
+            (hdr, prereqs) = hdr
+            if probe_header_with_prerequisites(ctx, hdr, prereqs):
+                continue
+        if os.path.exists("/usr/include/" + hdr):
+            # Sanity check...
+            print("Compilation check failed but include exists %s" % hdr)
+
+    if ((ctx.get_define("HAVE_TIMEPPS_H")
+         or ctx.get_define("HAVE_SYS_TIMEPPS_H"))):
+        ctx.define("HAVE_PPSAPI", 1, comment="Enable the PPS API")
+
+    # Check for Solaris capabilities
+    if ctx.get_define("HAVE_PRIV_H") and sys.platform.startswith("sunos"):
+        ctx.define("HAVE_SOLARIS_PRIVS", 1,
+                   comment="Enable Solaris Privileges (Solaris only)")
+
+    from wafhelpers.check_sockaddr import check_sockaddr
+    check_sockaddr(ctx)
+
+    # Some systems don't have sys/timex.h eg OS X, OpenBSD...
+    if ctx.get_define("HAVE_SYS_TIMEX_H"):
+        ctx.env.HEADER_SYS_TIMEX_H = True
+
+    if ctx.options.refclocks:
+        from wafhelpers.refclock import refclock_config
+        refclock_config(ctx)
+
+    # NetBSD (used to) need to recreate sockets on changed routing.
+    # Perhaps it still does. If so, this should be set.  The autoconf
+    # build set it "if the OS clears cached routes when more specifics
+    # become available".
+    # ctx.define("OS_MISSES_SPECIFIC_ROUTE_UPDATES", 1)
+
+    if ctx.options.enable_leap_smear:
+        ctx.define("ENABLE_LEAP_SMEAR", 1,
+                   comment="Enable experimental leap smearing code")
+
+    if ctx.options.enable_mssntp:
+        ctx.define("ENABLE_MSSNTP", 1,
+                   comment="Enable MS-SNTP extensions "
+                   " https://msdn.microsoft.com/en-us/library/cc212930.aspx")
+
+    if ctx.options.enable_lockclock:
+        if ctx.env.REFCLOCK_LOCAL:
+            ctx.define("ENABLE_LOCKCLOCK", 1,
+                       comment="Enable NIST 'lockclock'")
         else:
-            ctx.undefine("ENABLE_DEBUG_TIMING")
-
-        ctx.start_msg("Writing configuration header:")
-        ctx.write_config_header("config.h")
-        ctx.end_msg("config.h", "PINK")
-
-        def yesno(x):
-                if x:
-                        return "Yes"
-                return "No"
-
+            import waflib.Errors
+            raise waflib.Errors.WafError(
+                "NIST 'lockclock' requires refclock 'local'")
+
+    if not ctx.options.disable_droproot:
+        ctx.define("ENABLE_DROPROOT", 1,
+                   comment="Drop root after initialising")
+    if ctx.options.enable_early_droproot:
+        ctx.define("ENABLE_EARLY_DROPROOT", 1,
+                   comment="Enable early drop root")
+    if ctx.options.enable_seccomp:
+        ctx.define("ENABLE_SECCOMP", 1,
+                   comment="Enable seccomp")
+
+    if not ctx.options.disable_dns_lookup:
+        ctx.define("ENABLE_DNS_LOOKUP", 1,
+                   comment="Enable DNS lookup of hostnames")
+
+    if not ctx.options.disable_dns_retry:
+        ctx.define("ENABLE_DNS_RETRY", 1,
+                   comment="Retry DNS lookups after an initial failure")
+
+    # This is true under every Unix-like OS.
+    ctx.define("HAVE_WORKING_FORK", 1,
+               comment="Whether a working fork() exists")
+
+    # Does the kernel implement a phase-locked loop for timing?
+    # All modern Unixes (in particular Linux and *BSD) have this.
+    #
+    # The README for the (now deleted) kernel directory says this:
+    # "If the precision-time kernel (KERNEL_PLL define) is
+    # configured, the installation process requires the header
+    # file /usr/include/sys/timex.h for the particular
+    # architecture to be in place."
+    #
+    if ((ctx.get_define("HAVE_SYS_TIMEX_H")
+         and not ctx.options.disable_kernel_pll)):
+        ctx.define("HAVE_KERNEL_PLL", 1,
+                   comment="Whether phase-locked loop for timing "
+                   "exists and is enabled")
+
+    # SO_REUSEADDR socket option is needed to open a socket on an
+    # interface when the port number is already in use on another
+    # interface. Linux needs this, NetBSD does not, status on
+    # other platforms is unknown.  It is probably harmless to
+    # have it on everywhere.
+    ctx.define("NEED_REUSEADDR_FOR_IFADDRBIND", 1,
+               comment="Whether SO_REUSEADDR is needed to open "
+               "same sockets on alternate interfaces, required "
+               "by Linux at least")
+
+    # These are required by the SHA2 code and various refclocks
+    if sys.byteorder == "little":
+        pass
+    elif sys.byteorder == "big":
+        ctx.define("WORDS_BIGENDIAN", 1)
+    else:
+        print("Can't determine byte order!")
+
+    from wafhelpers.check_vsprintfm import check_vsprintfm
+    check_vsprintfm(ctx)
+
+    # Define CFLAGS/LDCFLAGS for -vv support.
+    ctx.define("NTPSEC_CFLAGS",
+               " ".join(ctx.env.CFLAGS).replace("\"", "\\\""),
+               comment="CFLAGS used when compiled")
+    ctx.define("NTPSEC_LDFLAGS",
+               " ".join(ctx.env.LDFLAGS).replace("\"", "\\\""),
+               comment="LDFLAGS used when compiled")
+
+    # Check for directory separator
+    if ctx.env.PLATFORM_TARGET == "win":
+        sep = "\\"
+    else:
+        sep = "/"
+
+    ctx.define("DIR_SEP", "'%s'" % sep, quote=False,
+               comment="Directory separator used")
+
+    # libisc/
+    # XXX: Hack that needs to be fixed properly for all platforms
+    ctx.define("ISC_PLATFORM_NORETURN_PRE", "", quote=False)
+    ctx.define("ISC_PLATFORM_NORETURN_POST",
+               "__attribute__((__noreturn__))", quote=False)
+
+    if ctx.get_define("HAVE_SYS_SYSCTL_H"):
+        ctx.define("HAVE_IFLIST_SYSCTL", 1,
+                   comment="Whether sysctl interface exists")
+
+    # Header/library checks
+    from wafhelpers.check_cap import check_cap
+    check_cap(ctx)
+
+    from wafhelpers.check_seccomp import check_seccomp
+    check_seccomp(ctx)
+
+    from wafhelpers.check_pthread import check_pthread_header_lib
+    check_pthread_header_lib(ctx)
+
+    if not ctx.options.disable_mdns_registration:
+        from wafhelpers.check_mdns import check_mdns_header
+        check_mdns_header(ctx)
+
+    if not ctx.options.disable_dns_retry:
+        from wafhelpers.check_pthread import check_pthread_run
+        check_pthread_run(ctx)
+
+    if not ctx.options.disable_mdns_registration:
+        from wafhelpers.check_mdns import check_mdns_run
+        check_mdns_run(ctx)
+
+    if ctx.options.enable_classic_mode:
+        ctx.define("ENABLE_CLASSIC_MODE", 1)
+    else:
+        ctx.undefine("ENABLE_CLASSIC_MODE")
+
+    if ctx.options.enable_debug_timing:
+        ctx.define("ENABLE_DEBUG_TIMING", 1)
+    else:
+        ctx.undefine("ENABLE_DEBUG_TIMING")
+
+    ctx.start_msg("Writing configuration header:")
+    ctx.write_config_header("config.h")
+    ctx.end_msg("config.h", "PINK")
+
+    def yesno(x):
+        if x:
+            return "Yes"
+        return "No"
+
+    msg("")
+    msg("Build Options")
+    msg_setting("CC", " ".join(ctx.env.CC))
+    msg_setting("CFLAGS", " ".join(ctx.env.CFLAGS))
+    msg_setting("LDFLAGS", " ".join(ctx.env.LDFLAGS))
+    msg_setting("PREFIX", ctx.env.PREFIX)
+    msg_setting("Debug Support", yesno(not ctx.options.disable_debug))
+    msg_setting("Refclocks", ", ".join(ctx.env.REFCLOCK_LIST))
+    msg_setting("Build Manpages",
+                yesno(ctx.env.ENABLE_DOC and not ctx.env.DISABLE_MANPAGE))
+
+    if ctx.options.enable_debug:
+        msg("")
+        msg("*** --enable-debug ignored.  (default on now)")
         msg("")
-        msg("Build Options")
-        msg_setting("CC", " ".join(ctx.env.CC))
-        msg_setting("CFLAGS", " ".join(ctx.env.CFLAGS))
-        msg_setting("LDFLAGS", " ".join(ctx.env.LDFLAGS))
-        msg_setting("PREFIX", ctx.env.PREFIX)
-        msg_setting("Debug Support", yesno(not ctx.options.disable_debug))
-        msg_setting("Refclocks", ", ".join(ctx.env.REFCLOCK_LIST))
-        msg_setting("Build Manpages", yesno(ctx.env.ENABLE_DOC and not ctx.env.DISABLE_MANPAGE))
-
-        if ctx.options.enable_debug:
-                msg("")
-                msg("*** --enable-debug ignored.  (default on now)")
-                msg("")


=====================================
wafhelpers/options.py
=====================================
--- a/wafhelpers/options.py
+++ b/wafhelpers/options.py
@@ -1,60 +1,112 @@
 def options_cmd(ctx, config):
-	ctx.load("compiler_c")
-	ctx.load("msvc")
-	ctx.load('waf_unit_test')
-
-	def callback_flags(option, opt, value, parser):
-		config["OPT_STORE"].setdefault(opt, []).append(value)
-
-	grp = ctx.add_option_group("NTP configure options")
-	grp.add_option('--enable-debug', action='store_true', default=False, help="(ignored)")
-	grp.add_option('--disable-debug', action='store_true', default=False, help="Disable debugging code")
-	grp.add_option('--enable-debug-gdb', action='store_true', default=False, help="Enable GDB debugging symbols")
-	grp.add_option('--enable-crypto', action='store_true', default=False, help="Enable OpenSSL.")
-	grp.add_option('--disable-droproot', action='store_true', default=False, help="Disable dropping root.")
-	grp.add_option('--enable-early-droproot', action='store_true', default=False, help="Droproot earlier (breaks SHM and NetBSD).")
-	grp.add_option('--enable-seccomp', action='store_true', default=False, help="Enable seccomp (restricts syscalls).")
-	grp.add_option('--disable-dns-lookup', action='store_true', default=False, help="Disable DNS lookups.")
-	grp.add_option('--disable-dns-retry', action='store_true', default=False, help="Disable retrying DNS lookups.")
-	grp.add_option('--disable-kernel-pll', action='store_true', default=False, help="Disable kernel PLL.")
-	grp.add_option('--disable-mdns-registration', action='store_true', default=False, help="Disable MDNS registration.")
-	grp.add_option('--enable-classic-mode', action='store_true', default=False, help="Strict configuration and log-format compatibility with NTP Classic")
-	grp.add_option('--enable-debug-timing', action='store_true', default=False, help="Collect timing statistics for debugging.")
-
-	grp = ctx.add_option_group("NTP cross compile options")
-	grp.add_option('--cross-compiler', type='string', help="Path to cross compiler CC. (enables cross-compiling)")
-	grp.add_option('--cross-cflags', type='string',  action="callback", callback=callback_flags, help="Cross compiler CFLAGS.")
-	grp.add_option('--cross-ldflags', type='string', action="callback", callback=callback_flags, help="Cross compiler LDFLAGS.")
-
-	grp = ctx.add_option_group("NTP configure features")
-	grp.add_option('--enable-leap-smear', action='store_true', default=False, help="Enable Leap Smearing.")
-	grp.add_option('--enable-mssntp', action='store_true', default=False, help="Enable Samba MS SNTP support.")
-	grp.add_option('--enable-lockclock', action='store_true', default=False, help="Enable NIST lockclock scheme.")
-
-	grp = ctx.add_option_group("Refclock configure options")
-	grp.add_option('--refclock', dest='refclocks', help="Comma-separated list of Refclock IDs to build (or \"all\")", type='string')
-	grp.add_option('--list', action='store_true', default=False, help="List available Refclocks")
-
-	grp = ctx.add_option_group("NTP developer configure options")
-	grp.add_option('--build-version-tag', type='string', help="Append a tag to the version string.")
-	grp.add_option('--cflags', type='string', action="callback", callback=callback_flags, help="Users should use CFLAGS in their environment.")
-	grp.add_option('--ldflags', type='string', action="callback", callback=callback_flags, help="Users should use LDFLAGS in their environment.")
-	grp.add_option('--enable-fortify', action='store_true', help="Enable HP Fortify.")
-	grp.add_option('--fortify-flags', type='string', action='store', help="Fortify flags.")
-	grp.add_option('--check', action='store_true', default=False, help="Run tests")
-	grp.add_option('--enable-rtems-trace', action='store_true', default=False, help="Enable RTEMS Trace.")
-	grp.add_option('--rtems-trace-path', type='string', default="", help="Path to rtems-tld.")
-	grp.add_option('--define', type='string', action="callback", callback=callback_flags, help="Force definition of symbol, wants value of form SYM=VAL.")
-	grp.add_option('--undefine', type='string', action="callback", callback=callback_flags, help="Force undefinition of symbol.")
-	grp.add_option('--sbindir', type='string', action='store', default=None, help="Force ntpd installation directory.")
-
-	grp = ctx.add_option_group("NTP documentation configure options")
-	grp.add_option('--enable-doc', action='store_true', default=False, help="Build NTP documentation")
-	grp.add_option('--enable-doc-only', action='store_true', default=False, help="Only build NTP documentation")
-	grp.add_option('--enable-a2x-xmllint', action='store_true', default=False, help="Build NTP documentation with a2x XML lint")
-	grp.add_option('--disable-manpage', action='store_true', default=False, help="Disable Manpage building.")
-	grp.add_option('--htmldir', type='string', action='store', default=None, help="Force HTML installation directory.")
-	grp.add_option('--mandir', type='string', action='store', default=None, help="Force man page installation directory.")
-
-	grp = ctx.add_option_group("Not for general use")
-	grp.add_option('--build-snapshot', action='store_true', default=False, help="Generate source snapshot.")
+    ctx.load("compiler_c")
+    ctx.load("msvc")
+    ctx.load('waf_unit_test')
+
+    def callback_flags(option, opt, value, parser):
+        config["OPT_STORE"].setdefault(opt, []).append(value)
+
+    grp = ctx.add_option_group("NTP configure options")
+    grp.add_option('--enable-debug', action='store_true',
+                   default=False, help="(ignored)")
+    grp.add_option('--disable-debug', action='store_true',
+                   default=False, help="Disable debugging code")
+    grp.add_option('--enable-debug-gdb', action='store_true',
+                   default=False, help="Enable GDB debugging symbols")
+    grp.add_option('--enable-crypto', action='store_true',
+                   default=False, help="Enable OpenSSL.")
+    grp.add_option('--disable-droproot', action='store_true',
+                   default=False, help="Disable dropping root.")
+    grp.add_option('--enable-early-droproot', action='store_true',
+                   default=False,
+                   help="Droproot earlier (breaks SHM and NetBSD).")
+    grp.add_option('--enable-seccomp', action='store_true',
+                   default=False, help="Enable seccomp (restricts syscalls).")
+    grp.add_option('--disable-dns-lookup', action='store_true',
+                   default=False, help="Disable DNS lookups.")
+    grp.add_option('--disable-dns-retry', action='store_true',
+                   default=False, help="Disable retrying DNS lookups.")
+    grp.add_option('--disable-kernel-pll', action='store_true',
+                   default=False, help="Disable kernel PLL.")
+    grp.add_option('--disable-mdns-registration', action='store_true',
+                   default=False, help="Disable MDNS registration.")
+    grp.add_option(
+        '--enable-classic-mode', action='store_true',
+        default=False,
+        help="Strict configuration and log-format "
+             " compatibility with NTP Classic")
+    grp.add_option('--enable-debug-timing', action='store_true',
+                   default=False,
+                   help="Collect timing statistics for debugging.")
+
+    grp = ctx.add_option_group("NTP cross compile options")
+    grp.add_option('--cross-compiler', type='string',
+                   help="Path to cross compiler CC. (enables cross-compiling)")
+    grp.add_option('--cross-cflags', type='string',  action="callback",
+                   callback=callback_flags, help="Cross compiler CFLAGS.")
+    grp.add_option('--cross-ldflags', type='string', action="callback",
+                   callback=callback_flags, help="Cross compiler LDFLAGS.")
+
+    grp = ctx.add_option_group("NTP configure features")
+    grp.add_option('--enable-leap-smear', action='store_true',
+                   default=False, help="Enable Leap Smearing.")
+    grp.add_option('--enable-mssntp', action='store_true',
+                   default=False, help="Enable Samba MS SNTP support.")
+    grp.add_option('--enable-lockclock', action='store_true',
+                   default=False, help="Enable NIST lockclock scheme.")
+
+    grp = ctx.add_option_group("Refclock configure options")
+    grp.add_option(
+        '--refclock', dest='refclocks',
+        help="Comma-separated list of Refclock IDs to build (or \"all\")",
+        type='string')
+    grp.add_option('--list', action='store_true', default=False,
+                   help="List available Refclocks")
+
+    grp = ctx.add_option_group("NTP developer configure options")
+    grp.add_option('--build-version-tag', type='string',
+                   help="Append a tag to the version string.")
+    grp.add_option('--cflags', type='string', action="callback",
+                   callback=callback_flags,
+                   help="Users should use CFLAGS in their environment.")
+    grp.add_option('--ldflags', type='string', action="callback",
+                   callback=callback_flags,
+                   help="Users should use LDFLAGS in their environment.")
+    grp.add_option('--enable-fortify', action='store_true',
+                   help="Enable HP Fortify.")
+    grp.add_option('--fortify-flags', type='string', action='store',
+                   help="Fortify flags.")
+    grp.add_option('--check', action='store_true', default=False,
+                   help="Run tests")
+    grp.add_option('--enable-rtems-trace', action='store_true',
+                   default=False, help="Enable RTEMS Trace.")
+    grp.add_option('--rtems-trace-path', type='string', default="",
+                   help="Path to rtems-tld.")
+    grp.add_option(
+        '--define', type='string', action="callback",
+        callback=callback_flags,
+        help="Force definition of symbol, wants value of form SYM=VAL.")
+    grp.add_option('--undefine', type='string', action="callback",
+                   callback=callback_flags,
+                   help="Force undefinition of symbol.")
+    grp.add_option('--sbindir', type='string', action='store',
+                   default=None, help="Force ntpd installation directory.")
+
+    grp = ctx.add_option_group("NTP documentation configure options")
+    grp.add_option('--enable-doc', action='store_true',
+                   default=False, help="Build NTP documentation")
+    grp.add_option('--enable-doc-only', action='store_true',
+                   default=False, help="Only build NTP documentation")
+    grp.add_option('--enable-a2x-xmllint', action='store_true',
+                   default=False,
+                   help="Build NTP documentation with a2x XML lint")
+    grp.add_option('--disable-manpage', action='store_true',
+                   default=False, help="Disable Manpage building.")
+    grp.add_option('--htmldir', type='string', action='store',
+                   default=None, help="Force HTML installation directory.")
+    grp.add_option('--mandir', type='string', action='store',
+                   default=None, help="Force man page installation directory.")
+
+    grp = ctx.add_option_group("Not for general use")
+    grp.add_option('--build-snapshot', action='store_true',
+                   default=False, help="Generate source snapshot.")


=====================================
wafhelpers/probes.py
=====================================
--- a/wafhelpers/probes.py
+++ b/wafhelpers/probes.py
@@ -3,22 +3,25 @@ This module exists to contain custom probe functions so they don't clutter
 up the logic in the main configure.py.
 """
 
+
 def probe_header_with_prerequisites(ctx, header, prerequisites, use=None):
         "Check that a header (with its prerequisites) compiles."
         src = ""
         for hdr in prerequisites + [header]:
-                src += "#include <%s>\n" % hdr
+            src += "#include <%s>\n" % hdr
         src += "int main(void) { return 0; }\n"
-        have_name = "HAVE_%s" % header.replace(".", "_").replace("/", "_").upper()
+        have_name = "HAVE_%s" \
+            % header.replace(".", "_").replace("/", "_").upper()
         ctx.check_cc(
-                fragment=src,
-                define_name=have_name,
-                msg = "Checking for header %s" % header,
-                use = use or [],
-                mandatory = False,
-                comment = "<%s> header" % header)
+            fragment=src,
+            define_name=have_name,
+            msg="Checking for header %s" % header,
+            use=use or [],
+            mandatory=False,
+            comment="<%s> header" % header)
         return ctx.get_define(have_name)
 
+
 def probe_function_with_prerequisites(ctx, function, prerequisites, use=None):
         "Check that a function (with its prerequisites) compiles."
         src = ""
@@ -31,12 +34,12 @@ def probe_function_with_prerequisites(ctx, function, prerequisites, use=None):
 """ % function
         have_name = "HAVE_%s" % function.upper()
         ctx.check_cc(
-                fragment=src,
-                define_name=have_name,
-                msg = "Checking for function %s" % function,
-                use = use or [],
-                mandatory = False,
-                comment = "Whether %s() exists" % function)
+            fragment=src,
+            define_name=have_name,
+            msg="Checking for function %s" % function,
+            use=use or [],
+            mandatory=False,
+            comment="Whether %s() exists" % function)
         return ctx.get_define(have_name)
 
 # end



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/adfe834b30f71ad2238f4180a1ccce653cd59bc2...abf72ae0630979a0ec9475dcfb1620f2e58e886f
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20170104/6ec1147b/attachment.html>


More information about the vc mailing list