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

_realname=libmysofa
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.3.1
pkgrel=1
pkgdesc="Reader for AES SOFA files to get better HRTFs (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/hoene/libmysofa/"
msys2_references=(
  "cpe: cpe:/a:symonics:libmysofa"
)
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-cunit")
source=("https://github.com/hoene/libmysofa/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        001-mingw-dont-use-nuget.patch
        002-fix-exports.patch
        004-fix-dllexport-attribute.patch
        005-add-cflag-private-for-staticlib.patch)
sha256sums=('a8a8cbf7b0b2508a6932278799b9bf5c63d833d9e7d651aea4622f3bc6b992aa'
            'f7c1f72dac366fd11502cf7176aa5133075f39b0e375522d00fc1cb827189378'
            'b233686c910d184bfaf7423e0d01fec301eff17f3fdfa595b45742a098d93a92'
            '808fa75c68f31ac4eb631a0c9ea1a2b83d99c4f9158eb2dd478218ce800615c8'
            '665bd53bfe3cdface288553ebd1b8d07e78762475add4971413a5703790ea045')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/001-mingw-dont-use-nuget.patch
  patch -p1 -i "${srcdir}"/002-fix-exports.patch
  patch -p1 -i "${srcdir}"/004-fix-dllexport-attribute.patch
  patch -p1 -i "${srcdir}"/005-add-cflag-private-for-staticlib.patch
}

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DBUILD_SHARED_LIBS=ON \
    "../${_realname}-${pkgver}"

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

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake.exe --install ./

  mkdir -p "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}
  cp "${srcdir}"/${_realname}-${pkgver}/LICENSE "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/
}
