# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgname=alsa-utils
pkgver=%version%
pkgrel=%release%
pkgdesc="Advanced Linux Sound Architecture - Utilities"
arch=(x86_64)
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=('5ce76807b53357584bfb4ace5acfdac4db9168ffaf5cdd1e499738eec046c36112bf84a99970f66368063a9baf73bad93af2d439630572f3eba5c9321071172d'
            'SKIP'
            '17ca2d760f383c02ccd00073d4fe73d6687ee58eb0ab5e458ad9d09845be7891cfe389e365bef00c7885e8afad45ea9ebf2925950f8d3fd8157feb818f986990')
b2sums=('dcf96705f9e3f1b4abaa7e1f107d1154a05500bf1cd07c821e0fe8c4ba7d7f08de0cf126be8c9c8dda3980d85c144318c12ffc8a95d5da4e98c49a6e9c2ee8ef'
        '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"
}
