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

_realname=soundtouch
pkgbase="mingw-w64-${_realname}"
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.0
pkgrel=1
pkgdesc="An audio processing library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.surina.net/soundtouch/"
msys2_repository_url="https://codeberg.org/soundtouch/soundtouch"
msys2_changelog_url="https://soundtouch.surina.net/README.html#changehistory"
msys2_references=(
  "cpe: cpe:/a:surina:soundtouch"
)
license=("spdx:LGPL-2.1-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-cc")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs")
source=(https://www.surina.net/${_realname}/${_realname}-${pkgver}.tar.gz
        0001-no-undefined-on.mingw.patch
        0003-fix-docdir.mingw.patch
        0004-missing-municode.patch)
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('3dda3c9ab1e287f15028c010a66ab7145fa855dfa62763538f341e70b4d10abd'
            '76b3041e952675e56138461c5fa8a5abacac31380ce90b27038d0deac46f91be'
            '2cd136046831f3ad9a2e37c0afe3ecd9f25ce27f5dbf4ee8b23b862a96e76cd5'
            '876b8bc6ba99b35b0b13fe963aacf9c7f82a8c7c53b9e8c678aee9af7607c15f')

prepare() {
  bsdtar -xf ${_realname}-${pkgver}.tar.gz || true

  cd "${srcdir}/${_realname}"
  patch -p1 -i "${srcdir}"/0001-no-undefined-on.mingw.patch
  patch -p1 -i "${srcdir}"/0003-fix-docdir.mingw.patch
  patch -p1 -i "${srcdir}"/0004-missing-municode.patch

  ./bootstrap
}

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

  ../${_realname}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

package() {
  cd build-${MSYSTEM}
  make DESTDIR="${pkgdir}" install
  install -Dm644 "${srcdir}/${_realname}/COPYING.TXT" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.TXT"
}
