# Maintainer: Some One <some.one@some.email.com>

_realname=munt-mt32emu
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.5.1
pkgrel=1
pkgdesc="mt32emu is a C/C++ library which allows to emulate (approximately) the Roland MT-32, CM-32L and LAPC-I synthesiser modules."
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://munt.sourceforge.net"
license=("LGPL2.1")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
)
options=('staticlibs')
source=("https://github.com/munt/munt/archive/refs/tags/libmt32emu_${pkgver//./_}.tar.gz")
sha256sums=('684988ab4d2b103554d9a38ad556cebc3ebc28d1d8fbb49fb4808ec9c80a2bf4')

build() {
  cd "${srcdir}/munt-libmt32emu_${pkgver//./_}/mt32emu"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    ${MINGW_PREFIX}/bin/cmake.exe \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      ../munt-libmt32emu_${pkgver//./_}/mt32emu

  ${MINGW_PREFIX}/bin/cmake --build .
}

package() {
  cd "${srcdir}"/build-${CARCH}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install
  install -Dm644 ${srcdir}/munt-libmt32emu_${pkgver//./_}/mt32emu/COPYING.LESSER.txt ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
