# Obarun        : 66 init/supervisor
# Maintainer    : Eric Vidal <eric@obarun.org>
# Maintainer    : Jean-Michel T.Dydak <jean-michel@obarun.org>
# Maintainer    : YianIris <yianiris At disroot Dot org>
# Obarun PkgSrc : https://framagit.org/pkg/obcore/p11-kit/
#----------------
# Maintainer    : Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor   : Ionut Biru <ibiru@archlinux.org>
# Arch PkrSrc   : https://www.archlinux.org/packages/core/x86_64/p11-kit/
#-----------------------------------------------------------------------
# Website       : https://p11-glue.freedesktop.org/
#-----------------------------------------------------------------------
#--DESCRIPTION----------------------------------------------------------

pkgbase=p11-kit
pkgname=(p11-kit libp11-kit)

pkgdesc="Loads and enumerates PKCS#11 modules"

pkgver=0.24.0
pkgrel=2

arch=(x86_64)

url='http://github.com/p11-glue/p11-kit'

target="$pkgver"
source=(https://github.com/p11-glue/p11-kit/releases/download/$pkgver/p11-kit-$pkgver.tar.xz{,.sig})

#--BUILD CONFIGURATION--------------------------------------------------

makedepends=(
    'gtk-doc'
    'git'
    'meson'
    'libtasn1'
    'libffi')

#--BUILD PREPARATION----------------------------------------------------

prepare() {
  cd p11-kit-$pkgver
}

#--BUILD CONTROL--------------------------------------------------------

_flags=(
    -Dgtk_doc=true
    -Dman=true
    -Dsystemd=disabled
    -Dbash_completion=disabled
    -Dtrust_paths=/etc/ca-certificates/trust-source:/usr/share/ca-certificates/trust-source
)

#--BUILD----------------------------------------------------------------

build() {
    arch-meson p11-kit-$pkgver build --buildtype=release "${_flags[@]}"
    meson compile -C $srcdir/build
}

#--CHECK----------------------------------------------------------------

check() {
    meson test -C build --print-errorlogs
}

#--SPLIT----------------------------------------------------------------

_pick() {
    local p="$1" f d; shift
    for f; do
      d="$srcdir/$p/${f#$pkgdir/}"
      mkdir -p "$(dirname "$d")"
      mv "$f" "$d"
      rmdir -p --ignore-fail-on-non-empty "$(dirname "$f")"
    done
}

#--PACKAGE--------------------------------------------------------------

package_p11-kit() {
    depends=("libp11-kit=$pkgver-$pkgrel" 'coreutils' 'libp11-kit.so')

    DESTDIR="$pkgdir" meson install -C build
    ln -srf "$pkgdir/usr/bin/update-ca-trust" "$pkgdir/usr/lib/p11-kit/trust-extract-compat"

    ## Split libp11-kit
    _pick lib "$pkgdir"/usr/include
    _pick lib "$pkgdir"/usr/lib/{p11-kit-proxy.so,libp11-kit.*}
    _pick lib "$pkgdir"/usr/lib/{pkcs11,pkgconfig}
    _pick lib "$pkgdir"/usr/share/{locale,p11-kit}
    install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 $pkgbase-$pkgver/COPYING
}

package_libp11-kit() {
    pkgdesc+=" (library)"
    depends=('glibc' 'libtasn1' 'libffi')
    provides=('libp11-kit.so')
    mv lib/* "$pkgdir"
    install -Dt "$pkgdir/usr/share/licenses/$pkgname" -m644 p11-kit-$pkgver/COPYING
}

#--SECURITY AND LICENCE-------------------------------------------------

validpgpkeys=(
	'462225C3B46F34879FC8496CD605848ED7E69871' # Daiki Ueno
	'C0F67099B808FB063E2C81117BFB1108D92765AF'  # Stef Walter
	)

sha512sums=(
    '48369d6fdae79b8c5a255c821fbdb982f0c649cce07c0d92f0ff0c16322fea8919faa94067cae2efede2da3646c0e69a71a3e399b769dc2327f247bcb113eb3c' #  p11-kit-0.24.0.tar.xz	
    'a35e3f8c9badabbef5ee8a18e6f59c59c1314cd0f09387c83a5c5714a28a9788f1b2b4775f7359e663581634afb1eb027f0d62124bd3f36592db734a0bdb3be7' #  p11-kit-0.24.0.tar.xz.sig
	)

license=(BSD)
