# -*- 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           github  1.0
PortGroup           cmake   1.1

github.setup        getdnsapi stubby 0.4.3 v
# Change github.tarball_from to 'releases' or 'archive' next update
github.tarball_from tarball
revision            1

categories          net
license             BSD

maintainers         {l2dy @l2dy} openmaintainer

description         an application that acts as a local DNS Privacy stub \
                    resolver (using DNS-over-TLS)

long_description    Stubby is the name given to a mode of using getdns which \
                    enables it to act as a local DNS Privacy stub resolver \
                    (using DNS-over-TLS). Stubby encrypts DNS queries sent from \
                    a client machine (desktop or laptop) to a DNS Privacy \
                    resolver increasing end user privacy.

homepage            https://dnsprivacy.org/wiki/display/DP/DNS+Privacy+Daemon+-+Stubby

checksums           rmd160  d6cebd33daf8316d3f97bb9eb38b0ae08d004b27 \
                    sha256  87cc7462e731708e6fc499b7492ffbb70487c9ce70972a26497a8b6619df83bc \
                    size    69393

depends_lib         port:getdns \
                    port:libyaml

destroot.env-append     DESTDIR=${destroot}

set stubbyconfdir       ${prefix}/etc/stubby

post-patch {
    reinplace "s|set(STUBBYCONFDIR.*|set(STUBBYCONFDIR \"${stubbyconfdir}\")|" \
        ${worksrcpath}/CMakeLists.txt
}

# stubby-ui-helper.c: error: ‘for’ loop initial declaration used outside C99 mode
configure.cflags-append -std=c99

post-destroot {
    move ${destroot}${prefix}/etc/stubby/stubby.yml ${destroot}${prefix}/etc/stubby/stubby.yml.example
}

post-activate {
    if {![file exists ${prefix}/etc/stubby/stubby.yml]} {
        file copy ${prefix}/etc/stubby/stubby.yml.example ${stubbyconfdir}/stubby.yml
    }
}

startupitem.create      yes
startupitem.executable  ${prefix}/bin/stubby -C ${stubbyconfdir}/stubby.yml
