# -*- 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                gpgme
version             1.24.1
revision            0

checksums           rmd160  72924d1b5bb4ba7e7081938e5c0c869c89e43dbd \
                    sha256  ea05d0258e71061d61716584ec34cef59330a91340571edc46b78374973ba85f \
                    size    1891695

categories          devel security crypto
license             {LGPL-2.1+ GPL-3+}
maintainers         nomaintainer
description         A library for easy acces to GnuPG.
long_description    GnuPG Made Easy (GPGME) is a library designed to make access \
                    to GnuPG easier for applications. It provides a High-Level \
                    Crypto API for encryption, decryption, signing, signature \
                    verification and key management. Currently it uses GnuPG \
                    as its backend but the API isn't restricted to this engine \
                    in fact we have already developed a backend for CMS (S/MIME).

homepage            https://www.gnupg.org/related_software/gpgme/
master_sites        gnupg
use_bzip2           yes

depends_build       path:bin/pkg-config:pkgconfig

depends_lib         port:pth \
                    port:libgpg-error \
                    port:libassuan \
                    path:bin/gpg2:gnupg2

patchfiles          patch-configure.ac.diff \
                    patch-tests-gpg-Makefile.am.diff

post-patch {
    reinplace "s|@GPG@|${prefix}/bin/gpg2|" ${worksrcpath}/src/gpgme-config.in
    reinplace "s|thread_modules=\"\"|thread_modules=\"pthread\"|" ${worksrcpath}/src/gpgme-config.in
    reinplace "s|@GPGSM@|${prefix}/bin/gpgsm|" ${worksrcpath}/src/gpgme-config.in
}

compiler.cxx_standard 2017
# Build uses c++17 features, but incorrectly configures for c++11 only.
configure.cxxflags-append -std=c++17

# We are patching configure.ac.
use_autoreconf      yes
autoreconf.args     -fvi
configure.checks.implicit_function_declaration.whitelist-append strchr

# enable cl cpp language bindings for now to avoid opportunistic failures (#52341)
# TODO: add bindings for python
# Due to the requirement to support multiple Qt versions,
# gpgme Qt5 bindings will be handled in separate port
# see https://trac.macports.org/ticket/53122

lappend languages cl

# This has to be enabled, otherwise CMake config files are not installed,
# which breaks some dependents, like Poppler.
# Contrary to the earlier situation, it does build now against libstdc++.
# FIXME: on 10.4 it does not build: https://trac.macports.org/ticket/69279
if {${os.platform} eq "darwin" && ${os.major} > 8} {
    lappend languages cpp
}

# gpg regression tests run during build repeatedly fail with error
# gpg: can't connect to the agent: File name too long
# disable for now to avoid build error

configure.args      --enable-languages="${languages}" \
                    --enable-static \
                    --disable-gpg-test

post-configure {
    reinplace "s|CC -dynamiclib|CC -dynamiclib [get_canonical_archflags]|g" ${worksrcpath}/libtool
}

post-destroot {
    xinstall -m 755 -d ${destroot}${prefix}/share/doc/${name}
    xinstall -m 644 -W ${worksrcpath} AUTHORS COPYING COPYING.LESSER \
        ChangeLog INSTALL NEWS README THANKS TODO \
        ${destroot}${prefix}/share/doc/${name}
}

livecheck.type      regex
livecheck.url       https://gnupg.org/ftp/gcrypt/gpgme/
livecheck.regex     "${name}-(\\d+(?:\\.\\d+)*)${extract.suffix}"
