# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=dosbox
_forkname=dosbox-staging
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.76.0
pkgrel=1
pkgdesc="Emulator with builtin DOS for running DOS Games (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://github.com/dosbox-staging/dosbox-staging'
license=('GPL2')
depends=(
    "${MINGW_PACKAGE_PREFIX}-fluidsynth"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-opusfile"
    "${MINGW_PACKAGE_PREFIX}-SDL2"
    "${MINGW_PACKAGE_PREFIX}-SDL2_net"
    "${MINGW_PACKAGE_PREFIX}-zlib"
    "${MINGW_PACKAGE_PREFIX}-munt-mt32emu"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
_commit="b8efb8c842b7bbf9ec6ac94cf8c68000767e9660"
# only master has meson support atm
source=("https://github.com/dosbox-staging/dosbox-staging/archive/${_commit}.tar.gz")
sha256sums=('5b721c0ccbd0183fec0f7d0a09539f9a50d242d8c1ef7b83135edf6e81ca2fa6')

prepare() {
  mv "${srcdir}/${_forkname}-${_commit}" "${srcdir}/${_forkname}-${pkgver}"
  cd "${srcdir}/${_forkname}-${pkgver}"
}

build() {
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("--buildtype=release")
  else
    extra_config+=("--buildtype=debug")
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  meson \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    "${extra_config[@]}" \
    -Dunit_tests=disabled \
    ../${_forkname}-${pkgver}

  meson compile
}

check() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  meson test
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  DESTDIR="${pkgdir}" meson install

  install -Dm644 "${srcdir}/${_forkname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
