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

_realname=alure2
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2
pkgrel=1
pkgdesc='Utility library to help manage common tasks with OpenAL applications (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://kcat.tomasu.net/alure.html'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-openal")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" 
             "${MINGW_PACKAGE_PREFIX}-libsndfile" 
             "${MINGW_PACKAGE_PREFIX}-libvorbis" 
             "${MINGW_PACKAGE_PREFIX}-flac" 
             "${MINGW_PACKAGE_PREFIX}-mpg123" 
             "${MINGW_PACKAGE_PREFIX}-dumb" 
             "${MINGW_PACKAGE_PREFIX}-fluidsynth"
             "${MINGW_PACKAGE_PREFIX}-ninja")
optdepends=("${MINGW_PACKAGE_PREFIX}-libsndfile: for uncompressed audio support"
            "${MINGW_PACKAGE_PREFIX}-libvorbis: for OGG Vorbis support"
            "${MINGW_PACKAGE_PREFIX}-flac: for FLAC support"
            "${MINGW_PACKAGE_PREFIX}-mpg123: for MPEG support"
            "${MINGW_PACKAGE_PREFIX}-dumb: for IT, XM, S3M and MOD support"
            "${MINGW_PACKAGE_PREFIX}-fluidsynth: for SoundFont 2 support")
_commit="2b54c0d8b074ff1b84821c791556b3634c11764f"
source=("https://repo.or.cz/alure.git/snapshot/${_commit}.tar.gz")
sha256sums=('b74cfbcd948691a5cf503e24ae701ca91f0fecff0507d47b2e83dd2521b62080')

prepare() {
  mv "${srcdir}/alure-"* "${srcdir}/${_realname}-${pkgver}"
  cd "${srcdir}/${_realname}-${pkgver}"
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G "Ninja" \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DALURE_BUILD_EXAMPLES=OFF \
    ../${_realname}-${pkgver}

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

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

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --build . --target install

  # conflicts with openal
  rm "${pkgdir}${MINGW_PREFIX}/include/AL/efx"*.h

  install -Dm0644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
