# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Tobias Powalowski <tpowa@archlinux.org>
# Contributor: Jochen Immendörfer <jochen dot immendoerfer at gmail dot com>

# NOTE: mixartloader/miXart8.elf is a blob lacking full RELRO and PIE
# https://mailman.alsa-project.org/pipermail/alsa-devel/2020-January/161887.html

pkgname=alsa-firmware
pkgver=1.2.4
pkgrel=4
pkgdesc="Firmware binaries for loader programs in alsa-tools and hotplug firmware loader"
arch=(any)
url="https://alsa-project.org/"
license=(BSD GPL2 LGPL2.1 custom)
source=(https://www.alsa-project.org/files/pub/firmware/$pkgname-$pkgver.tar.bz2{,.sig})
options=(!strip)
sha512sums=('041f54744fe30fa94781968c89c77ab9073fc9a828014d07a0f7e0f11c4185ace6846d5d2a313fcca6e9cda6e4837fd6f62e883b0fdb0a4e30a8c18ba7b2e05d'
            'SKIP')
b2sums=('0f844f6cc4859b72635f24d347b4c790469aee39aa60d9addb2c168dcf06b48e7e3cbba26ff21c7e1f5aa355641eec7ab934cb09bfac8ca116a6ac6a7db9d548'
        'SKIP')
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
    --enable-buildfw
    --with-hotplug-dir=/usr/lib/firmware
  )

  cd $pkgname-$pkgver
  ./configure "${configure_options[@]}"
  make
}

package() {
  cd $pkgname-$pkgver
  make DESTDIR="$pkgdir" install
  # remove files which conflict with linux-firmware
  rm -rf "$pkgdir"/usr/lib/firmware/{ct{efx,speq}.bin,ess,korg,sb16,yamaha}
  # remove broken symlinks (broken upstream)
  rm -rf "$pkgdir"/usr/lib/firmware/turtlebeach
  install -vDm 644 aica/license.txt -t "$pkgdir/usr/share/licenses/$pkgname/aica/"
  install -vDm 644 ca0132/creative.txt -t "$pkgdir/usr/share/licenses/$pkgname/ca0132/"
}
