# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=spandsp
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.6
pkgrel=2
pkgdesc="A DSP library for telephony (mingw-w64)."
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('GPL' 'LGPL')
url="https://www.soft-switch.org/"
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libtiff")
options=('strip' '!debug' 'staticlibs')
# https://www.soft-switch.org/downloads/${_realname}/${_realname}-${pkgver}.tar.gz
source=(https://web.archive.org/web/20210211020515/https://www.soft-switch.org/downloads/${_realname}/${_realname}-${pkgver}.tar.gz
        "0001-include-winsock.patch"
        "0002-fix-export-define.patch")
sha512sums=('16bb215ca89a39282e832403f69bc4c98ad3fe35ab3a6eb4731ee5029a6acd9b2df243c3701de845441cbdc16c88b3cd398ef15dc3502e45d5aeca8a161917d4'
            'c6afb60015f504e1b53e648e7e0db39f7d60b19b224fdea4101f5a452d361f5271456c0ab390f9cfba84e75641774d6b071b1ae9b64772a22c6fdb03832f45b9'
            '840e2e77a25a5d0bc3f27552b1c67bfcc0fcea1582dd8e0a1a16e9537c7facc936c2ce28a9fb99e0c19d8ab3883cb6d616489b38c9b2cf524a6a3aff4b10eac3')

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

  patch -Np1 -i "${srcdir}/0001-include-winsock.patch"
  patch -Np1 -i "${srcdir}/0002-fix-export-define.patch"
}

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

  CPPFLAGS+=" -DLIBSPANDSP_EXPORTS" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST}

  make
}

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

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

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
