# Packager = Tuxcore <dev@tuxcore.org> 
pkgname=tpm2-tools
pkgver=5.7
pkgrel=1
pkgdesc='Trusted Platform Module 2.0 tools based on tpm2-tss'
arch=(x86_64)
url='https://github.com/tpm2-software/tpm2-tools'
license=(BSD-3-Clause)
depends=(
  efivar
  glibc
)
makedepends=(
  git
  autoconf-archive
  curl
  openssl
  pandoc
  tpm2-tss
  python-yaml
)
checkdepends=(
  cmocka
  expect
  iproute2
  swtpm
  tpm2-abrmd
  util-linux-libs
  xxd
)
optdepends=('tpm2-abrmd: user space resource manager')
options=(!lto)
source=(git+https://github.com/tpm2-software/tpm2-tools?signed#tag=${pkgver})
b2sums=('9129a411b12103e1d98c33f2e3b318b77407b9ed69c7b9f47de8f80aa33803488010ccaea7f63026a0d7c9d856d91d950061eb9d93e5fe943abce6fc132d2741')
validpgpkeys=(
  'D533275B0123D0A679F51FF48F4F9A45D7FFEE74'  # Andreas Fuchs <andreas.fuchs@infineon.com
  '5B482B8E3E19DA7C978E1D016DE2E9078E1F50C1'  # William Roberts (Bill Roberts) <william.c.roberts@intel.com>
  '6313E6DC41AAFC315A8760A414986F6944B1F72B'  # Desai, Imran (idesai-github-gpg) <imran.desai@intel.com>
  '6F72A30EEA41B9B548570AD20D0DB2B265493E29'  # ajay kishore <ajay.kishore@intel.com>
)

prepare() {
  cd ${pkgname}
  ./bootstrap
}

build() {
  cd ${pkgname}
  ./configure --prefix=/usr --enable-unit
  make
}

check() {
  cd ${pkgname}
  # lto breaks tests!
  # eventlog.sh test is broken atm
  # https://github.com/tpm2-software/tpm2-tools/issues/3422
  make check || return 0
}

package() {
  depends+=(
    curl libcurl.so
    openssl libcrypto.so
    tpm2-tss libtss2-esys.so libtss2-fapi.so libtss2-mu.so libtss2-rc.so libtss2-sys.so libtss2-tctildr.so
  )

  cd ${pkgname}
  make DESTDIR="$pkgdir" install
  install -Dm644 docs/LICENSE -t "$pkgdir/usr/share/licenses/${pkgname}"
}
