# -*- 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

name                ldns

version             1.8.4
revision            0
categories          net devel
platforms           darwin
license             BSD
maintainers         nomaintainer

if {${subport} eq ${name}} {
    description         DNS library in C
    long_description    ldns is a library with the aim of simplifying DNS \
                        programming in C. It is heavily based upon the Net::DNS module from \
                        Perl.
}

homepage            https://www.nlnetlabs.nl/projects/ldns/about/
master_sites        https://www.nlnetlabs.nl/downloads/ldns/

conflicts           drill

checksums           rmd160  ccdb8052ab218713bc317614d16dc0f5125ede6e \
                    sha256  838b907594baaff1cd767e95466a7745998ae64bc74be038dccc62e2de2e4247 \
                    size    1301058

depends_build       bin:glibtool:libtool
depends_lib         port:libpcap

variant libressl conflicts openssl description {use LibreSSL} {
    depends_lib-append  path:lib/libtls.dylib:libressl
    configure.args --mandir=${prefix}/share/man --with-ssl --with-examples --with-drill --disable-dane-verify --disable-dane-ta-usage
}

variant openssl conflicts libressl description {use OpenSSL} {
    depends_lib-append  port:openssl
configure.args      --mandir=${prefix}/share/man --with-ssl --with-examples --with-drill
}

# We pass in our own SDK flags if necessary, and allowing configure
# to try to autodetect can break things.
# https://trac.macports.org/ticket/58998
configure.args-append   --with-xcode-sdk=no
configure.cppflags  -I${worksrcpath}/include
build.type          gnu

post-destroot {
    # Install pkg-config files not installed by the Makefile
    reinplace "s/-arch \[^ \]*//g" ${worksrcpath}/packaging/libldns.pc
    file mkdir ${destroot}${prefix}/lib/pkgconfig/
    file copy ${worksrcpath}/packaging/libldns.pc \
        ${destroot}${prefix}/lib/pkgconfig/libldns.pc
}

if {![catch {registry_active openssl}] && ![variant_isset libressl]} {
  # openssl is installed and the libressl variant isn't manually requested, default to openssl
  default_variants +openssl
} elseif {(![catch {registry_active libressl}] || ![catch {registry_active libressl-devel}]) && ![variant_isset openssl]} {
  # either libressl or libressl-devel are already installed, and the openssl variant is not explicitly requested, default to libressl
  default_variants +libressl
} elseif {![variant_isset openssl]} {
  # neither openssl nor libressl-devel are installed, and the openssl variant isn't selected, so libressl should be the default
  default_variants +libressl
}

livecheck.type      regex
livecheck.url       ${homepage}
livecheck.regex     ">LDNS (\\d+(?:\\.\\d+)*)</a>"
