# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=SDL2_mixer
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.4
pkgrel=4
pkgdesc="A simple multi-channel audio mixer (Version 2) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://libsdl.org/projects/SDL_mixer"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-flac"
         "${MINGW_PACKAGE_PREFIX}-fluidsynth"
         "${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-libmodplug"
         "${MINGW_PACKAGE_PREFIX}-mpg123"
         "${MINGW_PACKAGE_PREFIX}-opusfile")
options=('staticlibs' 'strip')
source=("$url/release/${_realname}-${pkgver}.zip"
        SDL2_mixer-2.0.1-find_lib.mingw.patch
        SDL2_mixer-2.0.1-libtool_windres.mingw.patch)
sha256sums=('9affb8c7bf6fbffda0f6906bfb99c0ea50dca9b188ba9e15be90042dc03c5ded'
            '8c906b09cb9318b54dac6b63eff49e63fb83bf1fc97219581b720709723ce5c1'
            '86fa38c76b834ea28d40c95d4639cf7896f449fe92a4348d21da641106a53132')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -Np1 -i ${srcdir}/SDL2_mixer-2.0.1-find_lib.mingw.patch
  patch -Np1 -i ${srcdir}/SDL2_mixer-2.0.1-libtool_windres.mingw.patch
  autoconf
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}/"
  export lt_cv_deplibs_check_method='pass_all'
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-shared \
    --enable-static \
    --disable-music-ogg-shared \
    --disable-music-flac-shared \
    --enable-music-mp3 \
    --disable-music-mp3-mad-gpl \
    --enable-music-mp3-mpg123 \
    --disable-music-mp3-mpg123-shared \
    --enable-music-opus \
    --disable-music-opus-shared

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/COPYING.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
