pkgname=mingw-w64-clang-aarch64-sdl2
pkgver=2.32.6
pkgrel=1
pkgdesc='A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (Version 2) (mingw-w64-clang-aarch64)'
license=('MIT')
url='http://libsdl.org'

arch=('any')
_archs=('aarch64-w64-mingw32')
depends=('mingw-w64-clang-aarch64-crt' 'sh')
makedepends=('mingw-w64-clang-aarch64-configure')
source=("${url}/release/SDL2-${pkgver}.tar.gz")
sha256sums=('6a7a40d6c2e00016791815e1a9f4042809210bdf10cc78d2c75b45c4f52f93ad')
options=('!debug' '!buildflags' 'staticlibs' '!strip')

build() {
  export USE_COMPILER_WRAPPERS=1
  export MINGW_LDFLAGS="-s"
  cd "${srcdir}/SDL2-${pkgver}"
  for _arch in ${_archs[@]}; do
    mkdir build-${_arch} -p
    pushd build-${_arch}
    ${_arch}-configure
    make
    popd
  done
}

package() {
  export USE_COMPILER_WRAPPERS=1
  cd "${srcdir}/SDL2-${pkgver}"

  install -d "${pkgdir}"/usr/bin

  for _arch in ${_archs[@]}; do
    pushd build-${_arch}
    make DESTDIR="${pkgdir}" install
    find "${pkgdir}/usr/${_arch}/bin" -name "*.dll" -exec $STRIP --strip-unneeded {} \;
    find "${pkgdir}/usr/${_arch}/lib" -name "*.a"   -exec $STRIP -g {} \;
    cp "${pkgdir}/usr/${_arch}/lib/libSDL2.a" "${pkgdir}/usr/${_arch}/lib/libSDL2-static.a"
    ln -s "/usr/${_arch}/bin/sdl2-config" "${pkgdir}/usr/bin/${_arch}-sdl2-config"
    popd
  done

  install -Dm644 LICENSE.txt "${pkgdir}/usr/share/licenses/$pkgname/LICENSE"
}
