makedepends=(socat expect fuse2 glib json-glib libseccomp libtpms)

description="Libtpms-based TPM emulator with socket, character device, and Linux CUSE interface"
url="https://github.com/stefanberger/swtpm"

packager="Great-OS Team"
maintainer="Great-OS Team"

name="swtpm"
version="0.10.1"
release=1

PKGMK_KEEP_SOURCES="no"
source=(https://github.com/stefanberger/swtpm/archive/refs/tags/v$version.tar.gz)

prepare() {
  cd "$name-$version"

  sed -i 's/env //' samples/swtpm-create-tpmca samples/swtpm-create-user-config-files.in
  autoreconf -fiv
}
build () {

  cd "$name-$version"

  ./configure --prefix=/usr \
              --with-cuse \
              --with-gnutls \
              --with-seccomp

  make
  make DESTDIR="$PKG" install

  install -Dm644 LICENSE -t "$PKG/usr/share/licenses/$name-$version"

  echo 'u tss - "tss user for tpm2"' | install -Dm644 /dev/stdin "$PKG/usr/lib/sysusers.d/$name-$version.conf"
  echo 'z /var/lib/swtpm-localca 0750 tss root' | install -Dm644 /dev/stdin "$PKG/usr/lib/tmpfiles.d/$name-$version.conf"
  chmod 750 "$PKG/var/lib/swtpm-localca"
}
