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

_realname=faad2
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.10.0
pkgrel=1
pkgdesc="ISO AAC audio decoder (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://github.com/knik0/faad2"
license=('GPL')
options=('staticlibs' 'strip')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-yasm" "${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/knik0/${_realname}/archive/${pkgver//\./_}.tar.gz")
sha256sums=('0c6d9636c96f95c7d736f097d418829ced8ec6dbd899cc6cc82b728480a84bfb')

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

  WANT_AUTOMAKE=latest autoreconf --force --install
}

build() {
  [[ -d "${srcdir}"/build-${MINGW_CHOST} ]] && rm -rf "${srcdir}"/build-${MINGW_CHOST}
  mkdir -p "${srcdir}"/build-${MINGW_CHOST} && cd "${srcdir}"/build-${MINGW_CHOST}
  cp -rf ../${_realname}-${pkgver//\./_}/* .

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

  make
}

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

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