# Maintainer: David Runge <dvzrv@archlinux.org>
# Contributor: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Sergej Pupykin <pupykin.s+arch@gmail.com>
# Contributor: Daniel Ehlers <danielehlers@mindeye.net>

pkgbase=alsa-plugins
pkgname=(alsa-plugins pulseaudio-alsa)
pkgver=1.2.12
pkgrel=5.1
epoch=1
pkgdesc="Additional ALSA plugins"
arch=(x86_64 aarch64)
url="https://www.alsa-project.org"
license=(
  GPL-2.0-or-later
  LGPL-2.1-or-later
)
makedepends=(
  alsa-lib
  dbus
  ffmpeg
  jack
  libavtp
  libpulse
  libsamplerate
  speexdsp
)
source=(
  https://www.alsa-project.org/files/pub/plugins/$pkgbase-$pkgver.tar.bz2{,.sig}
  pulse-sysdefault.diff
)
sha512sums=('b2064eb32662662f422f6e7c71f503d82c68d7a7059c8197bdd61ee08735b3ee104c6a5f9e3451e81124634514b91fc89d05d33041d9c2bb0f55b3c2ac3271b1'
            'SKIP'
            'b8c8e55f4da0ae87cc44d75a906d00b4f1e2304e6bc10419c6e0913c8f7d29599a3f3d41733decbe412a4669ea0d5af2a57f85b1655fba3625fbbd33c956f3f9')
b2sums=('ee9514d7cd73881840b17d86d52d3557936ce666ae5027b423903f2dedc74b112a8592d66dd2514744057e4bcebaf5c689f39fcc9027e05106cc0a0090470f34'
        'SKIP'
        '83c16b77c1737b2b59b60302be22b63e53026a366799fd97fe3c03b86756063d1b9689d5ffc7c793b40db55bdb79a5b6d72a17e0c8aa32364d6e639cf7ad3ce0')
validpgpkeys=('F04DF50737AC1A884C4B3D718380596DA6E59C91') # ALSA Release Team (Package Signing Key v1) <release@alsa-project.org>

prepare() {
  cd $pkgbase-$pkgver

  # Make use of the pulse plugin's "fallback" feature
  # Keeps parity with our old config from pulseaudio-alsa
  patch -Np1 -i ../pulse-sysdefault.diff

  autoreconf -fiv
}

build() {
  local configure_options=(
    --prefix=/usr
    --sysconfdir=/etc
    --enable-maemo-plugin
    --enable-maemo-resource-manager
  )

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

package_alsa-plugins() {
  depends=(
    alsa-lib libasound.so
    glibc
  )
  optdepends=(
    'dbus: for maemo plugin'
    'ffmpeg: for pcm_a52 plugin'
    'jack: for pcm_jack plugin'
    'libavtp: for pcm_aaf plugin'
    'libsamplerate: for rate_samplerate plugin'
    'libpulse: for conf_pulse, ctl_pulse and pcm_pulse plugins'
    'speexdsp: for pcm_speex and rate_speexrate plugins'
  )

  cd $pkgbase-$pkgver
  make DESTDIR="$pkgdir" install
  install -vDm 644 doc/README* doc/*.txt -t "$pkgdir/usr/share/doc/$pkgbase"

  # remove maemo plugin configuration (it overrides defaults for pcm and ctl),
  # until a better way is found to package default overrides:
  # https://bugs.archlinux.org/task/65440
  rm -v "$pkgdir/etc/alsa/conf.d/98-maemo.conf"

  # make a proper off-by-default config template out of the example file
  mv -v "$pkgdir/etc/alsa/conf.d/99-pulseaudio-default.conf.example" "$pkgdir/usr/share/alsa/alsa.conf.d/99-pulseaudio-default.conf"
}

package_pulseaudio-alsa() {
  pkgdesc="ALSA Configuration for PulseAudio"
  depends=(
    'alsa-plugins>=1.2.2-2'
    libpulse
  )

  install -vdm 755 "$pkgdir/etc/alsa/conf.d"
  ln -st "$pkgdir/etc/alsa/conf.d" /usr/share/alsa/alsa.conf.d/99-pulseaudio-default.conf
}

# vim:set sw=2 et:
