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

_realname=fluidsynth
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.2.0
pkgrel=1
pkgdesc="A real-time software synthesizer based on the SoundFont 2 specifications (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://www.fluidsynth.org/"
license=('LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-libsndfile"
         "${MINGW_PACKAGE_PREFIX}-portaudio"
         "${MINGW_PACKAGE_PREFIX}-readline")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-libtool"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cmake")
options=('strip' 'staticlibs')
source=("${_realname}-${pkgver}.tar.gz::https://github.com/FluidSynth/${_realname}/archive/v${pkgver}.tar.gz"
        "010-no-undefined.patch")
sha256sums=('928fb16f307507485bd1d9b010dafba8c747bce5de2ba47ab1705944c87013b6'
            'c848fcb41ab812c640fd5f591dd61772b5cf1c6b5ef325894f7f0905fa8b7c76')
noextract=("${_realname}-${pkgver}.tar.gz")

prepare() {
    cd ${srcdir}
    tar -xf "${_realname}-${pkgver}.tar.gz" || true

    cd "${_realname}-${pkgver}"
    patch -p1 -i ${srcdir}/010-no-undefined.patch
}

build() {
  [[ -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 \
      -G'Ninja' \
      -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
      "${extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -Denable-portaudio=ON \
      -Denable-dbus=OFF \
      ../${_realname}-${pkgver}

  ninja
}

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