# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

github.setup        p11-glue p11-kit 0.26.5
revision            1

license             Permissive
description         PKCS#11 module discovery and loading
long_description    Provides a way to load and enumerate PKCS#11 modules and a standard \
                    configuration setup for installing PKCS#11 modules in such a way that \
                    they are discoverable.
maintainers         nomaintainer
categories          security

github.tarball_from releases
use_xz              yes

checksums           rmd160  9ffc612957f05fa10e3930466a714195658ef5e6 \
                    sha256  f2cc09111e44bf3fea58f023180b33acea90aa82d042d6fbb623fbc5ba033bb7 \
                    size    1082584

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]

depends_build       port:gettext \
                    path:bin/pkg-config:pkgconfig \
                    port:python${py_ver_nodot}

depends_lib         port:gettext-runtime \
                    port:libtasn1 \
                    port:libffi \
                    port:libxslt

depends_run         path:share/curl/curl-ca-bundle.crt:curl-ca-bundle

# p11-kit/uri.gnu.c:93: error: redefinition of typedef 'CK_ULONG'
# pkcs11x.h:102: error: redefinition of typedef 'CK_TRUST'
# See: https://trac.macports.org/ticket/70399
# See: https://trac.macports.org/ticket/73614
compiler.c_standard 2011

configure.args      --disable-doc \
                    --disable-silent-rules \
                    --with-trust-paths=${prefix}/share/curl/curl-ca-bundle.crt:${prefix}/etc/openssl

# /usr/bin/python is Python 2.7 for older systems, and
# /usr/bin/python3 is too old (< 3.6) on older systems
# https://trac.macports.org/ticket/68739
configure.env       PYTHON=${prefix}/bin/python${py_ver}

# https://trac.macports.org/wiki/WimplicitFunctionDeclaration#strchr
configure.checks.implicit_function_declaration.whitelist-append strchr

post-destroot {
    set bash_comp_path ${destroot}${prefix}/share/bash-completion/completions
    xinstall -d ${bash_comp_path}
    xinstall -m 644 -W ${worksrcpath}/bash-completion ${name} trust ${bash_comp_path}

    set zsh_comp_path ${destroot}${prefix}/share/zsh/site-functions
    xinstall -d ${zsh_comp_path}
    xinstall -m 644 ${worksrcpath}/zsh-completion/${name}.zsh ${zsh_comp_path}/_${name}
    xinstall -m 644 ${worksrcpath}/zsh-completion/trust.zsh ${zsh_comp_path}/_trust
}

variant doc description {Build man pages and documentation} {
    depends_build-append    port:gtk-doc
    configure.args-replace  --disable-doc --enable-doc
}

test.run            yes
test.target         check
# See: https://bugs.freedesktop.org/show_bug.cgi?id=91602#c1
test.env            FAKED_MODE=1
