# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: judd <jvinet@zeroflux.org>

pkgname=alsa-utils
pkgver=1.2.12
pkgrel=1
pkgdesc="Advanced Linux Sound Architecture - Utilities"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
url="https://www.alsa-project.org"
license=(GPL-2.0-or-later)
depends=(
  gcc-libs
  glibc
  pciutils
  psmisc
)
makedepends=(
  alsa-lib
  docbook-xsl
  fftw
  libsamplerate
  ncurses
  python-docutils
  systemd
  xmlto
)
optdepends=(
  'bash: for alsa-info.sh and alsabat-test.sh'
  'fftw: for alsabat'
)
# we require /var/lib/alsa for state file
options=(emptydirs)
source=(
  $url/files/pub/utils/$pkgname-$pkgver.tar.bz2{,.sig}
  $pkgname.tmpfiles
)
sha512sums=('6631f9f8e32fbb1f7b06af086cdfb8349c2d70188c4509ab46fa105024fbde9985985d9cc738c7b5a743cacaaeae7a7006f8ef92f66a50762f7df5d714bf548b'
            'SKIP'
            '17ca2d760f383c02ccd00073d4fe73d6687ee58eb0ab5e458ad9d09845be7891cfe389e365bef00c7885e8afad45ea9ebf2925950f8d3fd8157feb818f986990')
b2sums=('3b049af3f829c475e0d9a58fbd8adb7278f0a7a84d404d1141ac8c8639f8d66594efe9e7da239a2b7a54f788639df1bbade127b5fde9912de5227e2b959a9b4d'
        'SKIP'
        '24b8e44833c7e8b142162878a837b10e1c2a862568280f2ce16fcb81ecc1383802654dbe88930f2cc13c345635c5003cbc3712e121e589dffc2e25c540749ee3')
validpgpkeys=('F04DF50737AC1A884C4B3D718380596DA6E59C91') # ALSA Release Team (Package Signing Key v1) <release@alsa-project.org>

prepare() {
  cd $pkgname-$pkgver
  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --disable-alsaconf
    --sbindir=/usr/bin
    --with-udev-rules-dir=/usr/lib/udev/rules.d
    --with-systemdsystemunitdir=/usr/lib/systemd/system
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"
  # prevent excessive overlinking due to libtool
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

check() {
  make -k check -C $pkgname-$pkgver
}

package() {
  depends+=(
    alsa-lib libasound.so libatopology.so
    ncurses libformw.so libmenuw.so libncursesw.so libpanelw.so
    libsamplerate libsamplerate.so
  )

  make DESTDIR="$pkgdir" install -C $pkgname-$pkgver
  install -vDm 644 $pkgname-$pkgver/README.md -t "$pkgdir/usr/share/doc/$pkgname/"

  # dir for ALSA state
  install -vdm 755 "$pkgdir/var/lib/alsa/"
  install -vDm 644 $pkgname.tmpfiles "$pkgdir/usr/lib/tmpfiles.d/$pkgname.conf"
}
