def build(ctx):

    libntp_source = [
        "assert.c",
        "authkeys.c",
        "authreadkeys.c",
        "clocktime.c",
        "decodenetnum.c",
        "dolfptoa.c",
        "getopt.c",
        "initnetwork.c",
        "isc_error.c",
        "isc_interfaceiter.c",
        "isc_net.c",
        "macencrypt.c",
        "netof.c",
        "ntp_endian.c",
        "ntp_random.c",
        "ntp_dns.c",
        "numtoa.c",
        "recvbuff.c",
        "refidsmear.c",
        "socket.c",
        "socktoa.c",
        "ssl_init.c",
        "syssignal.c",
    ]

    libntp_source_sharable = [
        "clockwork.c",
        "emalloc.c",
        "hextolfp.c",
        "lib_strbuf.c",
        "msyslog.c",
        "ntp_calendar.c",
        "prettydate.c",
        "statestr.c",
        "systime.c",
        "timespecops.c",
    ]

    if not ctx.env.HAVE_STRLCAT or not ctx.env.HAVE_STRLCPY:
        libntp_source_sharable += ["strl_obsd.c"]

    includes = ctx.env.PLATFORM_INCLUDES

    # C library
    ctx(
        features="c cstlib bld_include src_include",
        includes=includes,
        source=libntp_source + libntp_source_sharable,
        target="ntp",
        use="CRYPTO",
    )

    # Loadable Python extension
    #
    # In theory this should use PYTHONARCHDIR, but that doesn't work on
    # CentOS (at least), for some as-yet-undetermined reason.  On most
    # platforms, PYTHONARCHDIR == PYTHONDIR, anyway.
    ctx(
        features="c cshlib bld_include src_include pyext",
        install_path='${PYTHONDIR}/ntp',
        includes=includes,
        source=["pymodule.c"] + libntp_source_sharable,
        target="../pylib/ntpc",  # Put the output in the pylib directory
        use="M RT CRYPTO",
    )
