#!/usr/bin/bash
# JOBoRun		: Jwm OpenBox Obarun RUNit
# Maintainer	: Joe Bo Run <joborun@disroot.org>
# PkgSource		: url="https://gittea.disroot.org/joborun-pkg/jobcore/$pkgname"
# Website		: https://pozol.eu
#-----------------------------------------| DESCRIPTION |---------------------------------------

pkgname=tpm2-tss
pkgver=3.2.0
pkgrel=03
pkgdesc='Implementation of the TCG Trusted Platform Module 2.0 Software Stack (TSS2)'
arch=('x86_64')
url='https://github.com/tpm2-software/tpm2-tss'
depends=('curl' 'json-c' 'openssl' 'libjson-c.so')
makedepends=('cmocka' 'doxygen' 'libtpms')
checkdepends=('iproute2' 'swtpm' 'uthash')
provides=('libtss2-esys.so' 'libtss2-fapi.so' 'libtss2-mu.so' 'libtss2-rc.so' 'libtss2-sys.so' 'libtss2-tctildr.so')
backup=('etc/tpm2-tss/fapi-config.json'
        'etc/tpm2-tss/fapi-profiles/P_ECCP256SHA256.json'
        'etc/tpm2-tss/fapi-profiles/P_RSA2048SHA256.json')
#options=('debug' '!emptydirs' '!lto') # uncomment this to produce debug package and comment the next line
options=('!emptydirs' '!lto')
source=("$url/releases/download/$pkgver/$pkgname-$pkgver.tar.gz"{,.asc}
        'https://raw.githubusercontent.com/tpm2-software/tpm2-tss/e237e4d33cbf280292a480edd8ad061dcd3a37a2/lib/tss2-tcti-libtpms.map')

prepare() {
	cd "$pkgname-$pkgver"
	# Add file missing from release tarball (https://github.com/tpm2-software/tpm2-tss/issues/2313)
	cp "$srcdir/tss2-tcti-libtpms.map" lib
}

build() {
	cd "$pkgname-$pkgver"
	./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var \
	            --with-runstatedir=/run --with-sysusersdir=/usr/lib/sysusers.d \
	            --with-tmpfilesdir=/usr/lib/tmpfiles.d --with-udevrulesprefix=60- \
	            --enable-unit $( ((CHECKFUNC)) && echo --enable-integration)
	make
}
# fails some tests and gets stuck in one for long 
#check() {
#	cd "$pkgname-$pkgver"
#	make check
#}

package() {
	cd "$pkgname-$pkgver"
	make DESTDIR="$pkgdir" install
	install -Dm644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}

#---- license gpg-key sha256sums ----

license=('BSD')

validpgpkeys=('D6B4D8BAC7E0CC97DCD4AC7272E88B53F7A95D84' # Andreas Fuchs  <andreas.fuchs@sit.fraunhofer.de>
              '5B482B8E3E19DA7C978E1D016DE2E9078E1F50C1') # William Roberts (Bill Roberts) <william.c.roberts@intel.com> 

sha256sums=(48305e4144dcf6d10f3b25b7bccf0189fd2d1186feafd8cd68c6b17ecf0d7912 # tpm2-tss-3.2.0.tar.gz
	9579c6ad302ae7073c74f5249a60c797ebed4fcf4459a0016e6f1cc0b63058cb # tpm2-tss-3.2.0.tar.gz.asc
	41c37dc4b10b1e86023619150e5047739aeee93fd8f77315157d3eeb5fe6a981) # tss2-tcti-libtpms.map


