# Maintainer: Zach Bacon <11doctorwhocanada@gmail.com>

_realname=faac
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.31.1
pkgrel=1
pkgdesc="FAAC is an AAC audio encoder (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://github.com/knik0/faac'
license=('GPL2')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("https://github.com/knik0/${_realname}/archive/faac-${pkgver}.tar.gz")
sha256sums=('3191bf1b131f1213221ed86f65c2dfabf22d41f6b3771e7e65b6d29478433527')

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

  if [[ ${MINGW_PACKAGE_PREFIX} == *-clang-* ]]; then
    sed -i "s/-Wl,--add-stdcall-alias//g" libfaac/Makefile.am
  fi

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -R "faac-faac-${pkgver}" "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}

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

  make
}

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