# Maintainer: Lothar Serra Mari <serra@scummvm.org>

_realname=scummvm
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2.0
pkgrel=3
pkgdesc="A program which allows you to run certain classic graphical point-and-click adventure games (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://www.scummvm.org/'
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-binutils"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-gcc-libs"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-faad2"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-flac"
         "${MINGW_PACKAGE_PREFIX}-fluidsynth"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libogg"
         "${MINGW_PACKAGE_PREFIX}-libvorbis"
         "${MINGW_PACKAGE_PREFIX}-libmad"
         "${MINGW_PACKAGE_PREFIX}-libmpeg2-git"
         "${MINGW_PACKAGE_PREFIX}-libtheora"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-nasm"
         "${MINGW_PACKAGE_PREFIX}-readline"
         "${MINGW_PACKAGE_PREFIX}-SDL2"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://downloads.scummvm.org/frs/scummvm/${pkgver}/scummvm-${pkgver}.tar.xz"
        "0001-fluidsynth-2-fixes.patch")
sha256sums=('1469657e593bd8acbcfac0b839b086f640ebf120633e93f116cab652b5b27387'
            '73dcf95911f41ca6c2702cae71056118129db014fb6e2cc37a51133f71cc8f36')

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

  # https://github.com/scummvm/scummvm/pull/2915
  # + some previous commits to make it apply
  patch -p1 -i "${srcdir}/0001-fluidsynth-2-fixes.patch"
}

build() {
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --enable-release \
    --enable-optimizations \
    --disable-cloud \
    --disable-debug

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
