# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Dan McGee <dan@archlinux.org>
# Contributor: Martin Striz <ms@poruba.net>

pkgname=irqbalance
pkgver=1.9.4
pkgrel=2
pkgdesc="IRQ balancing daemon for SMP systems"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://github.com/irqbalance/irqbalance"
license=(GPL-2.0-only)
backup=(etc/$pkgname.env)
depends=(
  glibc
  libnl
)
makedepends=(
  glib2
  libcap-ng
  meson
  ncurses
  numactl
  systemd
  systemd-libs
)
source=(
  $pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz
  $pkgname-1.9.4-fix-service-paths.patch
  $pkgname-1.9.4-remove-service-hardening.patch::$url/commit/f2c8309a4198d8f51069a783905049c5b7eb7600.patch
)
sha512sums=('abdcac9dccabb18ae644b73dc2a8528c03279811c1f9182a5a5b0af43b30c5982d7bb14e79d4430b5d4f2cea8e17115e6038851c74de1ff3bdfc4e303392479a'
            'f719cdc1acb966b6ff403d93869fd331be44ddb0e65d63665a1944003c95e0c621710345f791b602127c0f2c2b180727a56bc55d1c99c4e0c0c1bae3cf46c6c7'
            '275fa84c0d0558767ee00c9c5e44cf47d328a11baa6e0925e05f668e62051275ae96c5b7bf3974c92ff603e34a3f93fcb7ef4e17ddd151795f622a42b54ec17c')
b2sums=('6b8bf28e11686713ca9c00a1b98c5f3afb38c26e919a9d7de126145d12c4e8e23e8ea00b2534bb0339e5990ed5cb642291df975ba9868835e9c4e8a23c98f2ef'
        '7ccfc43e5c65842a500669834e2631686034a37936c06931a3b8a56168b4e16f21e53824bfc686e54d30188ece5a3ddca23a069744f0627c00700766729ab895'
        'aab767b61c6988627414db79d2902447e4c46384f82e7fb8e0c91dc5c4d43f9b909bdb455c17d08e1ecc9f8e1b8ebf5ef1bafb5344fc4d52232ff1492e653f0a')

prepare() {
  # remove problematic service hardening: https://gitlab.archlinux.org/archlinux/packaging/packages/irqbalance/-/issues/2
  patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-1.9.4-remove-service-hardening.patch
  # fix location of configuration and binary in service
  patch -Np1 -d $pkgname-$pkgver -i ../$pkgname-1.9.4-fix-service-paths.patch
}

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

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

package() {
  depends+=(
    glib2 libglib-2.0.so
    libcap-ng libcap-ng.so
    ncurses libncursesw.so
    numactl libnuma.so
    systemd-libs libsystemd.so
  )

  meson install -C build --destdir "$pkgdir"
  install -vDm 644 $pkgname-$pkgver/misc/irqbalance.service -t "$pkgdir/usr/lib/systemd/system/"
  install -vDm 644 $pkgname-$pkgver/misc/irqbalance.env -t "$pkgdir/etc/"
  install -vDm 644 $pkgname-$pkgver/{AUTHORS,README.md} -t "$pkgdir/usr/share/doc/$pkgname/"
}
