# Maintainer: Christoph Gysin <christoph.gysin@gmail.com>

_realname=libsoundio
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.0.1
_pkgver=$pkgver-7
pkgrel=1
pkgdesc='A C99 library providing cross-platform audio input and output (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.github.com/andrewrk/libsoundio'
license=('spdx:MIT')
source=("https://github.com/andrewrk/${_realname}/archive/${_pkgver}.tar.gz"
        "0001-build-fix.patch")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc")
md5sums=('7a8d22fc28a5331e26ed318283f40d96'
         'b03623fbd1451bb6de84dec008e4713b')

prepare() {
  cd "${_realname}-${_pkgver}"

  patch -p1 < ../0001-build-fix.patch
}

build() {
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake \
    -G"Ninja" \
    -Bbuild \
    -S"${_realname}-${_pkgver}" \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
    -DCMAKE_DLL_NAME_WITH_SOVERSION=ON \
    -DBUILD_EXAMPLE_PROGRAMS=OFF \
    -DBUILD_TESTS=OFF \
    -DENABLE_JACK=OFF \
    -DENABLE_PULSEAUDIO=OFF \
    -DENABLE_ALSA=OFF \
    -DENABLE_COREAUDIO=OFF \
    -DENABLE_WASAPI=ON \
    -DBUILD_STATIC_LIBS=OFF \
    -DCMAKE_POLICY_VERSION_MINIMUM=3.5

  cmake --build build
}

package() {
  DESTDIR="${pkgdir}" cmake --install build

  install -Dm644 "${_realname}-${_pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
