# -*- 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.2
revision            0

# Putting the SHA1 hash because that is published on the website
checksums           rmd160  739d26af2bf57fdeba5eb43458b7c83f218eb060 \
                    sha1    3efd495a94dc81fd0ea8788bef6c69d1f13cedd7 \
                    sha256  97eb47df8ae5a3ff744f868005a090da5ab45cb48ee9836dbf5ee739a4e5cf49 \
                    size    7346587

# 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
conflicts           ${my_name}1
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 \
                    port: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+)*)"
