# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           legacysupport 1.1

# strnlen
legacysupport.newest_darwin_requires_legacy 10

name                chrony
version             4.8
revision            0
checksums           rmd160  aee2af27807c94b50ebbdb5045ecffccfe966dbb \
                    sha256  33ea8eb2a4daeaa506e8fcafd5d6d89027ed6f2f0609645c6f149b560d301706 \
                    size    649368

categories          sysutils net
maintainers         {@artkiver gmail.com:artkiver} openmaintainer
description         A versatile implementation of the Network Time Protocol (NTP)
license             GPL-2
long_description    Chrony can synchronise the system clock with NTP servers, \
                    reference clocks (e.g. GPS receiver), and manual input \
                    using wristwatch and keyboard. It can also operate as an \
                    NTPv4 (RFC 5905) server and peer to provide a time service \
                    to other computers in the network. \
                    It is designed to perform well in a wide range of \
                    conditions, including intermittent network connections, \
                    heavily congested networks, changing temperatures \
                    (ordinary computer clocks are sensitive to temperature), \
                    and systems that do not run continuosly, or run on a \
                    virtual machine.

homepage            https://chrony-project.org/
master_sites        https://chrony-project.org/releases/

depends_build       port:pkgconfig

configure.args      --localstatedir=${prefix}/var \
                    --sysconfdir=${prefix}/etc \
                    --with-pidfile=${prefix}/var/run/chronyd.pid \
                    --without-editline \
                    --without-gnutls \
                    --without-nettle \
                    --without-nss \
                    --without-tomcrypt

destroot.target     install install-docs
destroot.keepdirs   ${destroot}${prefix}/var/log/${name} \
                    ${destroot}${prefix}/var/run/${name}

variant gnutls description {Use gnutls for TLS} {
    depends_lib-append      path:lib/pkgconfig/gnutls.pc:gnutls
    configure.args-delete   --without-gnutls
}
variant libedit description {Use libedit for line editing} {
    depends_lib-append      port:libedit
    configure.args-delete   --without-editline
}
variant nettle conflicts tomcrypt description {Use nettle for additional hash support} {
    depends_lib-append      port:nettle
    configure.args-delete   --without-nettle
}
# disabling this variant for now since it does not work:
# chrony is looking for 'nsslowhash.h' which is not present in the nss port
#
#variant nss description {Use NSS for additional hash support} {
#    depends_lib-append      port:nss
#    configure.args-delete   --without-nss
#}
variant tomcrypt conflicts nettle description {Use tomcrypt for additional hash support} {
    depends_lib-append      port:libtomcrypt
    configure.args-delete   --without-tomcrypt
}

default_variants    +libedit

if {![variant_isset tomcrypt]} {
    default_variants-append +nettle
}

post-patch {
    reinplace -W ${worksrcpath} "s|/etc/|${prefix}/etc/|g" \
              examples/chrony.conf.example2 \
              examples/chrony.conf.example3
    reinplace -W ${worksrcpath} "s|/var/|${prefix}/var/|g" \
              examples/chrony.conf.example1 \
              examples/chrony.conf.example2 \
              examples/chrony.conf.example3
}
post-destroot {
    xinstall -d ${destroot}${prefix}/share/examples/${name}
    xinstall -d ${destroot}${prefix}/var/log/${name}
    xinstall -d ${destroot}${prefix}/var/run/${name}
    
    xinstall -m 0644 ${filespath}/chrony.conf \
                     ${destroot}${prefix}/etc/chrony.conf.dist
    reinplace -W ${destroot}${prefix} "s|@@prefix@@|${prefix}|g" \
              etc/chrony.conf.dist
    reinplace -W ${destroot}${prefix} "s|@@name@@|${name}|g" \
              etc/chrony.conf.dist
    
    xinstall -m 0644 {*}[glob ${worksrcpath}/examples/*.example*] \
                     ${destroot}${prefix}/share/examples/${name}
}
post-activate {
    if {![file exists ${prefix}/etc/chrony.conf]} {
        file copy ${prefix}/etc/chrony.conf.dist ${prefix}/etc/chrony.conf
    }
}

startupitem.create      yes
startupitem.netchange   yes
startupitem.executable  ${prefix}/sbin/chronyd -n

livecheck.regex         "chrony-(\\d+(?:\\.\\d+)*)\\${extract.suffix}"
