# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Cilyan Olowen <gaknar@gmail.com>
# Contributor: fill <mailbox@fillo.ru>
# Contributor: Anton Shestakov <engored*ya.ru>

pkgname=flashrom
pkgver=1.7.0
pkgrel=1
pkgdesc="Utility for reading, writing, erasing and verifying flash ROM chips"
arch=(x86_64 aarch64)
url="https://www.flashrom.org/"
license=(GPL-2.0-or-later)
depends=(
  libcrypto.so
  libftdi
  libusb
  pciutils
)
makedepends=(
  cmocka
  git
  meson
  python-sphinx
)
optdepends=('dmidecode: for SMBIOS/DMI table decoder support')
source=(
  "git+https://github.com/flashrom/flashrom.git#tag=v${pkgver}"
  cmocka-v2-compatibility.patch
  glibc-2.42-fix.patch
)
sha256sums=('920995ce4c5600006ed784d892b2841d3d6f9e57c3cc979e09ebe98c2e9a6bb9'
            '2f766927c1d066091e8c69dfb60a178f20d72110685967a3a24cbf5a2db87ea9'
            '3b842e0c3bd2ca42b24cef81ecfd58b79f812a190476b8d35798dd7aa7391a63')

prepare() {
  sed -i 's#GROUP="plugdev"#TAG+="uaccess"#g' flashrom/util/flashrom_udev.rules
  patch -Np1 -d flashrom < cmocka-v2-compatibility.patch
  patch -Np1 -d flashrom < glibc-2.42-fix.patch
}

build() {
  arch-meson ${pkgname} build
  meson compile -C build
}

# FYI, tests are incompatible with LTO enabled
# check() {
#   meson test -C build --print-errorlogs
# }

package() {
  meson install -C build --destdir "${pkgdir}"
  install -Dm644 flashrom/util/flashrom_udev.rules "${pkgdir}"/usr/lib/udev/rules.d/70-flashrom.rules
}
