# Maintainer: Mikko Nyman <mikko@nyman.xyz>
# Based on the Arch libfprint package by Jan Alexander Steffens (heftig).
#
# Omarchy's fingerprint setup installs this in place of stock libfprint, so
# readers upstream supports ahead of an Arch release reach users by bumping
# the pin here. Pinned to the commit adding the Synaptics reader USB
# 06cb:010b, missing from stock libfprint 1.94.100; the FocalTech MOC support
# carried by the previous pin is retained.
#
# On aarch64 it also carries the aurora driver for Apple Touch ID, which the
# aurora kernel's Secure Enclave driver exposes as /dev/sep-bio
# (aurora-apple-sep.patch, by Chris Kearney). The x86_64 build is unchanged.
# The driver accepts only /dev/sep-bio interface version 4
# (AURORA_BIO_IFACE_VERSION): a kernel that bumps it turns Touch ID off until
# this patch follows, so move the two together.

pkgname=libfprint-git
pkgver=1.94.100.r10.g6f9479c
pkgrel=2
# Retain the epoch used to supersede the previously published untested build.
epoch=1
pkgdesc="Library for fingerprint readers (pinned upstream snapshot with FocalTech and Synaptics 06cb:010b support, and Apple Touch ID on aarch64)"
url="https://fprint.freedesktop.org/"
arch=(x86_64 aarch64)
license=(LGPL-2.1-or-later)
depends=(
  gcc-libs
  glib2
  glibc
  libgudev
  libgusb
  openssl
  pixman
)
makedepends=(
  git
  glib2-devel
  gobject-introspection
  gtk-doc
  meson
  python-cairo
  python-gobject
  systemd
)
checkdepends=(
  cairo
  umockdev
)
# Versioned, so a package that requires a libfprint version still installs.
provides=("libfprint=$pkgver" libfprint-2.so)
conflicts=(libfprint)
groups=(fprint)
source=(
  "git+https://gitlab.freedesktop.org/libfprint/libfprint.git#commit=6f9479c3d55f847c1b3769f28ceb99227f9858cf"
  "focaltech_moc-add-pid-0xA97A.patch"
)
source_aarch64=("aurora-apple-sep.patch")
b2sums=(
  'SKIP'
  'SKIP'
)
b2sums_aarch64=('ec577996066baf6db6d741763abd681aae5556d52a8b67f7a52a60a4df7015c5d1edf3637835e563b2fb0edde2499173d61c50717b621f6bddf94a1f700075e5')

pkgver() {
  cd libfprint
  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null \
      | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g' \
      || printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd libfprint

  if ! grep -qi 'pid = 0xa97a' libfprint/drivers/focaltech_moc/focaltech_moc.c; then
    patch -p1 < "$srcdir/focaltech_moc-add-pid-0xA97A.patch"
  fi

  # Skipped only when every hunk is already in: a tree a failed run left
  # half-patched fails here instead of building.
  if [[ $CARCH == "aarch64" ]] &&
    ! patch -p1 -R --dry-run --silent --force < "$srcdir/aurora-apple-sep.patch" >/dev/null 2>&1; then
    patch -p1 --forward < "$srcdir/aurora-apple-sep.patch"
  fi
}

build() {
  local meson_options=(
    -D drivers=all
    -D installed-tests=false
  )
  arch-meson libfprint build "${meson_options[@]}"
  meson compile -C build
}

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

package() {
  meson install -C build --destdir "$pkgdir"
}

# vim:set sw=2 sts=-1 et:
