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

_realname=audaspace
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.5.0
pkgrel=2
pkgdesc="A high level audio library written in C++ with language bindings for Python (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://audaspace.github.io/"
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-ffmpeg"
         "${MINGW_PACKAGE_PREFIX}-fftw"
         "${MINGW_PACKAGE_PREFIX}-libsndfile"
         "${MINGW_PACKAGE_PREFIX}-openal"
         "${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-numpy"
         "${MINGW_PACKAGE_PREFIX}-SDL2")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-python-sphinx"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=("https://github.com/neXyon/audaspace/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        0100-mingw-relocate.patch
        0101-mingw-exports.patch
        0102-mingw-python.patch)
sha256sums=('7375d09578aff83e6842a302b40bc4adc859c4edcad479ff90b28d91ba0f608d'
            'ba491094d6249f842c0f27741155f6f3966e4bff1ac79eba36e601d189446950'
            '8cf2aefb1973177ec3d75443e47ba95c66ca113076e615af0a8f6c8de1398da0'
            '3ad2a5c3495694048c8bafb893b299bdbc33231ef0d32192809dc9d1ab49f285')

# Helper macros to help make tasks easier #
apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -Nbp1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd ${_realname}-${pkgver}
  
  apply_patch_with_msg \
    0100-mingw-relocate.patch \
    0101-mingw-exports.patch \
    0102-mingw-python.patch
}

build() {
  declare -a _btype
  if check_option "debug" "y"; then
    _btype=Debug
  else
    _btype=Release
  fi

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=${_btype} \
    -DPYTHON_EXECUTABLE=${MINGW_PREFIX}/bin/python.exe \
    -DPython3_EXECUTABLE=${MINGW_PREFIX}/bin/python.exe \
    -DPython3_ROOT_DIR=${MINGW_PREFIX} \
    -DPython3_FIND_REGISTRY=NEVER \
    ../${_realname}-${pkgver}

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

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

  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install .
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
