# -*- 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.51
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  9a0efcd8b435e908417d40e76decc5624a1e2a56 \
                sha256  be0f1b2db6b93eed55369cdf79f19f72750c8c7c39fc20b577e724545427e6b2 \
                size    1085510

depends_build   port:gettext

depends_lib     port:gettext-runtime \
                port:libiconv

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

# build with gawk 5.0.0 is broken see https://trac.macports.org/ticket/58356
configure.awk   /usr/bin/awk

# 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+)