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

github.setup        heimdal heimdal 7.8.0 heimdal-
revision            0
github.tarball_from releases
checksums           rmd160  eca6006e800cf93e598326b60f06deb49947d16a \
                    sha256  fd87a207846fa650fd377219adc4b8a8193e55904d8a752c2c3715b4155d8d38 \
                    size    10024936

maintainers         nomaintainer
categories          net security

license             BSD
homepage            https://www.heimdal.software
description         Heimdal is a Kerberos 5 implementation.
long_description    \
    Heimdal is an implementation of Kerberos 5 (and some more stuff) largely \
    written in Sweden (which was important when we started writing it, less so now).

depends_build       port:pkgconfig \
                    bin:makeinfo:texinfo

depends_lib         port:readline \
                    port:gettext \
                    port:libtasn1 \
                    port:libcomerr

# Use a separate prefix to avoid conflicts with the port kerberos5
# (and openssl, if that variant is selected)
configure.pre_args  --prefix=${prefix}/libexec/heimdal
configure.args      \
    --sysconfdir=${prefix}/etc \
    --disable-mdb-db           \
    --disable-ndbm-db          \
    --disable-silent-rules     \
    --enable-shared            \
    --enable-static            \
    --enable-pthread-support   \
    --with-readline=${prefix}  \
    --without-libedit          \
    --with-libintl=${prefix}   \
    --without-berkeley-db      \
    --without-x                \
    --without-openldap         \
    --without-openssl          \
    --without-sqlite3

build.env-append    LC_CTYPE=C

variant x11 description \
    {Enable X11 use in libraries, and build X11-related applications} {
    depends_lib-append      port:xorg-libice \
                            port:xorg-libXau \
                            port:xorg-libXt \
                            port:xorg-libsm \
                            port:xorg-libX11 \
                            port:xorg-libXdmcp
    configure.args-replace  --without-x --with-x=${prefix}
}

variant openldap description \
    {Enable LDAP database support for keeping track of Kerberos information} {
    depends_lib-append      path:lib/libldap.dylib:openldap
    configure.args-replace --without-openldap --with-openldap=${prefix}
}

variant openssl description \
    {Use OpenSSL libraries instead of internal ones for crypto and ssl related functions} {
    depends_lib-append     path:lib/libssl.dylib:openssl
    configure.args-replace --without-openssl --with-openssl=${prefix}
}

variant sqlite3 description \
    {Enable SQLite3 database support for keeping track of Kerberos information} {
    depends_lib-append      port:sqlite3
    configure.args-replace  --without-sqlite3 --with-sqlite3=${prefix}
}

post-patch {
    # older systems do not have the CommonCrypto support needed for -openssl
    # evp-cc.c:103:5: error: use of undeclared identifier 'CCMode'
    if {${os.platform} eq "darwin" && ${os.major} < 11} {
        reinplace "s:def __APPLE__: 0:" ${worksrcpath}/lib/hcrypto/evp-cc.c
    }
}

platform darwin powerpc {
    # heimdal has its own fallback, use it on powerpc
    # until libdispatch is fixed and confirmed to work.
    configure.args-append \
                    ac_cv_prog_GCD_MIG=no
}

test.run            yes
test.target         check

github.livecheck.regex  {(\d+(?:\.\d+)*)}
