# Maintainer: Jeff Hubbard <musikernel@gmail.com>

_realname=vamp-plugin-sdk
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.10.0
pkgrel=2
pkgdesc="Vamp plugins extract descriptive information from audio data (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="https://www.vamp-plugins.org/"
license=("BSD")
options=('!buildflags')
makedepends=("${MINGW_PACKAGE_PREFIX}-aria2"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libsndfile")
# "https://code.soundsoftware.ac.uk/attachments/download/2691/${_realname}-${pkgver}.tar.gz"
source=(01-mingw-shared.patch)
sha256sums=('aa338dc97b454f800ed63d2e44f178f1d1e8fdaca16c19639e3773a968e5518c')

prepare() {
  # curl fails to download with certificate error
  cd "${srcdir}"
  aria2c --check-certificate=false \
  "https://code.soundsoftware.ac.uk/attachments/download/2691/${_realname}-${pkgver}.tar.gz"
  tar -xf "${_realname}-${pkgver}.tar.gz"

  cd "${srcdir}/${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/01-mingw-shared.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  cp -rf "${_realname}-${pkgver}" "build-${MINGW_CHOST}"
  cd build-${MINGW_CHOST}

  CFLAGS+=" -D_USE_MATH_DEFINES"
  CPPFLAGS+=" -D_USE_MATH_DEFINES"
  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make -j1
}

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