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

_realname=munt
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.7.2
pkgrel=1
pkgdesc="Software synthesizer emulating pre-GM MIDI devices such as the Roland MT-32, CM-32L, CM-64 and LAPC-I"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://munt.sourceforge.net/"
msys2_repository_url="https://github.com/munt/munt"
license=("spdx:GPL-3.0-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
depends=("${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-portaudio"
         "${MINGW_PACKAGE_PREFIX}-qt6-base"
         "${MINGW_PACKAGE_PREFIX}-qt6-multimedia")
source=("https://github.com/munt/munt/archive/libmt32emu_${pkgver//./_}.tar.gz")
sha256sums=('3b0beff64e83d2b4879baba2326eed1300edc9663b3dc52621fc74d196ca9a80')

build() {
  mkdir -p "${srcdir}"/build-${MSYSTEM} && cd "${srcdir}"/build-${MSYSTEM}

  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[@]}" \
      -Dmt32emu-qt_WITH_QT_VERSION=6 \
      ../munt-libmt32emu_${pkgver//./_}

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

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

  cd "${srcdir}"/build-${MSYSTEM}/mt32emu_smf2wav
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
  install -Dm644 "${srcdir}"/munt-libmt32emu_${pkgver//./_}/mt32emu_smf2wav/COPYING.txt "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/mt32emu-smf2wav_LICENSE
}
