# Contributor: Alexander Georgievskiy <galeksandrp@gmail.com>
# Contributor: Andrew Sun <adsun701@gmail.com>

_realname=fdk-aac
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.0.3
pkgrel=1
pkgdesc="A standalone library of the Fraunhofer FDK AAC code from Android (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://github.com/mstorsjo/fdk-aac"
msys2_references=(
  'archlinux: libfdk-aac'
)
license=('custom')
makedepends=("${MINGW_PACKAGE_PREFIX}-autotools" "${MINGW_PACKAGE_PREFIX}-cc")
source=("${url}/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('e25671cd96b10bad896aa42ab91a695a9e573395262baed4e4a2ff178d6a3a78')

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

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

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

  make
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  make DESTDIR="${pkgdir}" install
  
  # Install license
  install -dm 755 "${pkgdir}${MINGW_PREFIX}"/share/licenses/libfdk-aac
  install -m 644 "${srcdir}"/${_realname}-${pkgver}/NOTICE \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/libfdk-aac/
}
