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

set my_name         gnupg
name                ${my_name}2
version             2.4.8
revision            0

# Putting the SHA1 hash because that is published on the website
checksums           rmd160  a9626023371d2d19fe5b668944967e1e64fea281 \
                    sha1    c704085aa7cc131a67edd0b7c0c90e5c35ee4adb \
                    sha256  b58c80d79b04d3243ff49c1c3fc6b5f83138eb3784689563bcdd060595318616 \
                    size    8017685

# https://trac.macports.org/ticket/63552
epoch               1

categories          mail security
maintainers         {jann @roederja} {ionic @Ionic} openmaintainer
license             GPL-3+
installs_libs       no

description         GNU Privacy Guard
long_description    GnuPG is a complete and free replacement for PGP. Because       \
                    it does not use the patented IDEA algorithm, it can be used     \
                    without any restrictions. GnuPG is a RFC4880 (OpenPGP)          \
                    compliant application.
homepage            https://www.gnupg.org
distname            ${my_name}-${version}
master_sites        ${my_name}:${my_name}

use_bzip2           yes
default_variants    +openldap

platform darwin {
    if {![variant_isset pinentry] && ![variant_isset pinentry_mac]} {
        # Automatically switch between pinentry and pinentry-mac, with pinentry-mac being
        # preferred.
        # 10.7 and below are not supported by pinentry-mac, though, and will default to
        # pinentry. Just like pure darwin without OS X will.
        if {${os.subplatform} ne "macosx" ||
            ${xcodeversion} eq "none" ||
            [vercmp ${xcodeversion} {5.0}] < 0 ||
            ${os.major} < 12 || (![catch {registry_active pinentry}] &&
                                 [catch {registry_active pinentry-mac}])} {
            default_variants-append +pinentry
        } else {
            default_variants-append +pinentry_mac
        }
    }

    if {${os.major} < 9} {
        patchfiles-append   patch-common_sysutils.c-fix-unsetenv-usage-on-10.4.diff
    }
}

compiler.c_standard 2011

depends_build       port:gettext \
                    path:bin/pkg-config:pkgconfig

depends_lib         port:libiconv           \
                    port:gettext-runtime    \
                    port:zlib               \
                    port:bzip2              \
                    port:libassuan          \
                    port:libksba            \
                    port:libgcrypt          \
                    port:libgpg-error       \
                    port:readline           \
                    path:lib/pkgconfig/gnutls.pc:gnutls             \
                    port:libusb-compat      \
                    port:npth               \
                    port:sqlite3

post-destroot {
    ln -s ${prefix}/bin/gpg ${destroot}${prefix}/bin/gpg2
}

platform darwin 10 {
    # Rosetta misdetects the arch and gives a warning of a mismatch:
    # *** The config script "/opt/local/bin/gpgrt-config --libdir=/opt/local/lib gpg-error" was
    # *** built for powerpc-apple-darwin10 and thus may not match the used host x86_64-apple-darwin10.8.0.
    if {${build_arch} eq "ppc"} {
        configure.args-append --build=powerpc-apple-darwin${os.major}
    }
}

variant pinentry conflicts pinentry_mac description {Handle user input via pinentry.} {
    depends_lib-append      port:pinentry
    configure.args-append   --with-pinentry-pgm=${prefix}/bin/pinentry
}

variant pinentry_mac conflicts pinentry description {Handle user input via pinentry-mac. Only compatible with OS X 10.8+.} {
    depends_lib-append      port:pinentry-mac
    configure.args-append   --with-pinentry-pgm=${applications_dir}/pinentry-mac.app/Contents/MacOS/pinentry-mac
}

configure.args-append --disable-ldap --with-ldap=no
variant openldap description {Support openldap} {
    depends_lib-append      path:lib/libldap.dylib:openldap
    configure.cppflags-append \
                            -DLDAP_DEPRECATED=1
    configure.args-delete   --disable-ldap
    configure.args-delete   --with-ldap=no
    configure.args-append   --with-ldap=${prefix}
}

test.run            yes
test.dir            ${worksrcpath}/tests
test.target         check

livecheck.type      regex
livecheck.url       https://www.gnupg.org
livecheck.regex     "The current version of GnuPG is (\\d+(?:\\.\\d+)*)"
