# POWER Maintainer: Alexander Baldeck <alex.bldck@gmail.com>
# Maintainer: Jan Alexander Steffens (heftig) <jan.steffens@gmail.com>
# Contributor: Allan McRae <allan@archlinux.org>
# Contributor: Tom Newsom <Jeepster@gmx.co.uk>
# Contributor: Lukas Sabota <punkrockguy318@cocmast.net> (Timidity Patch)

pkgname=sdl_mixer
pkgver=1.2.12
pkgrel=12
pkgdesc="A simple multi-channel audio mixer"
url="https://www.libsdl.org/projects/SDL_mixer/"
arch=(x86_64 powerpc64le powerpc64 powerpc riscv64)
license=(custom)
depends=(libmikmod libvorbis sdl)
makedepends=(fluidsynth)
optdepends=('fluidsynth: MIDI software synth, replaces built-in timidity')
source=(https://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-$pkgver.tar.gz
        mikmod1.patch mikmod2.patch fluidsynth-volume.patch double-free-crash.patch
        fluidsynth-use-after-free.patch)
sha256sums=('1644308279a975799049e4826af2cfc787cad2abb11aa14562e402521f86992a'
            'e0d36cd81083a0b033436b8f300cc4f4513a6043e57fea139afbade02dbe0de8'
            'a0c5326b4363464159a38dc51badad984b65ce0fa4c3b1dd1ad5f73bc7b6c55e'
            '4b6c567debf18c88398d4045a6e4ed0954f0e04cc61162ca907a83ddec17cd70'
            'b707f5c8d1229d1612cc8a9f4e976f0a3b19ea40d7bd1d5bc1cbd5c9f8bca56d'
            '97a9ec5ce455114e3fde862670da468a81ba3a868f9385048ddc45a5a3102d03')

prepare() {
  cd SDL_mixer-$pkgver

  patch -Np1 -i ../mikmod1.patch
  patch -Np1 -i ../mikmod2.patch
  patch -Np1 -i ../fluidsynth-volume.patch
  patch -Np1 -i ../double-free-crash.patch
  patch -Np1 -i ../fluidsynth-use-after-free.patch

  sed -e "/CONFIG_FILE_ETC/s|/etc/timidity.cfg|/etc/timidity/timidity.cfg|" \
      -e "/DEFAULT_PATH2/s|/usr/local/lib/timidity|/usr/lib/timidity|" \
      -i timidity/config.h
}

build() {
  cd SDL_mixer-$pkgver
  ./configure --prefix=/usr --disable-static --build=${CHOST}
  make
}

package() {
  cd SDL_mixer-$pkgver
  make DESTDIR="$pkgdir" install
  install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
