# Maintainer: Coelacanthus <uwu@coelacanthus.name>
# Contributor: Peter Cai <peter@typeblog.net>

pkgname=lpac-git
pkgver=2.3.0.r109.g3ff3559
pkgrel=1
pkgdesc="Local Profile Agent (LPA) for eSIM cards via PC/SC readers, or AT / APDU commands over stdio."
arch=(x86_64 aarch64 armv7h)
url="https://github.com/estkme-group/lpac"
license=('AGPL-3.0-only AND LGPL-2.0-only AND MIT')
depends=(
  glibc
  cjson
)
makedepends=(
  cmake
  git
  ninja
)
makedepends=(
  curl
  cmake
  git
  pcsclite
  libqmi
  libmbim
  ninja
)
optdepends=(
  'pcsclite: PC/SC support'
  'curl: cURL support'
  'libqmi: QMI support'
  'libmbim: MBIM support'
)
provides=(lpac)
conflicts=(lpac)
source=($pkgname::git+https://github.com/estkme-group/lpac)
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"
  git describe --tags --long --abbrev=7 | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

build() {
  cd "$srcdir/$pkgname"
  local cmake_options=(
    -G Ninja
    -DCMAKE_INSTALL_PREFIX="/usr"
    -DUSE_SYSTEM_DEPS=ON
    -DLPAC_DYNAMIC_DRIVERS=ON
    -DLPAC_DYNAMIC_LIBEUICC=ON
    -DLPAC_WITH_APDU_AT=ON
    -DLPAC_WITH_APDU_MBIM=ON
    -DLPAC_WITH_APDU_PCSC=ON
    -DLPAC_WITH_APDU_QMI=ON
    -DLPAC_WITH_APDU_QMI_QRTR=ON
  )
  cmake -S . -B build "${cmake_options[@]}"
  ninja -C build
}

package() {
  cd "$srcdir/$pkgname"
  DESTDIR="$pkgdir" ninja -C build install
  install -Dm644 -t "$pkgdir"/usr/share/licenses/"$pkgname" LICENSES/*
}

