# -*- 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       conflicts_build 1.0
PortGroup       gnu_info 1.0

# we will only use the muniversal PG on < 10.14
set using_muniversal_PG false
if {${os.platform} eq "darwin" && ${os.major} < 18} {

    set using_muniversal_PG true
    PortGroup muniversal 1.0

    merger_must_run_binaries yes
}

name            libgpg-error
version         1.61
revision        0

categories      devel
license         LGPL-2.1+
maintainers     {mps @Schamschula} openmaintainer
description     Common error values for all GnuPG components
long_description \
    libgpg-error is a library that defines common error values for all GnuPG components. \
    Among these are GPG, GPGSM, GPGME, GPG-Agent, libgcrypt, pinentry, SmartCard Daemon \
    and possibly more in the future.

homepage        https://www.gnupg.org
master_sites    gnupg

use_bzip2       yes

checksums       rmd160  2c751e85af92b893dc3f53d0e3c3ba04f52561fe \
                sha256  7a85413f2bc354f4f8aa832b718af122e48965e9e0eb9012ee659c13c6385c93 \
                size    1124751

depends_build   port:gettext \
                port:pkgconfig

depends_lib     port:gettext-runtime \
                port:libiconv

patchfiles      patch-src-spawn-posix.c.diff

use_autoreconf  yes
autoreconf.args --install --verbose --force

# enable install of deprecated gpg-error-config
# currently required to configure libgcrypt
# can be removed when this is no longer necessary
# see libgpg-error NOTES for more details
configure.args  --enable-install-gpg-error-config

# Also enable the building of static libs
configure.args-append \
                --enable-static

# fix build on Tiger see https://trac.macports.org/ticket/55145
platform darwin 8 {
    configure.cppflags-append -D__DARWIN_UNIX03
}

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

if {${universal_possible} && [variant_isset universal] && ${using_muniversal_PG}} {
    # muniversal's *.h merger does not handle \-continued lines properly
    patchfiles-append           patch-gen-posix-lock-obj_c.diff
    configure.cppflags-append   -DNO_LINE_CONT
}

test.run        yes
test.target     check

post-destroot {
    set docdir ${prefix}/share/doc/${name}-${version}
    xinstall -d ${destroot}${docdir}
    xinstall -m 0644 -W ${worksrcpath} ABOUT-NLS AUTHORS COPYING COPYING.LIB NEWS README \
        THANKS VERSION ${destroot}${docdir}
}

gnu_info.name   gpgrt

livecheck.type  regex
livecheck.url   https://gnupg.org/ftp/gcrypt/${name}/
livecheck.regex ${name}-(\\d+\\.\\d+)
