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

_realname=SDL
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.2.15
pkgrel=9
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://libsdl.org"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-libiconv")
options=('staticlibs' 'strip')
source=("${url}/release/SDL-${pkgver}.tar.gz"
        "0001-sdl-config-win-paths.patch")
sha256sums=('d6d316a793e5e348155f0dd93b979798933fb98aa1edebcc108829d6474aad00'
            '3b88cde73a06f204b607093d864224b094b189a98d1c1c5a7e9ceb69e7ef7bd7')

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

  patch -Np1 -i "${srcdir}"/0001-sdl-config-win-paths.patch
}

build() {
  [[ -d "build-${MINGW_CHOST}" ]] && rm -rf "build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../SDL-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-assembly \
    --enable-shared \
    --enable-static

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  sed -e "s|-mwindows||g" -i ${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/sdl.pc
}
