# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# contributers: Zach Bacon <zachbacon@budgiemedia.rocks>

_realname=SDL2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.32.10
pkgrel=1
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (Version 2) (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'archlinux: sdl2'
  "cpe: cpe:/a:libsdl:libsdl"
  "cpe: cpe:/a:libsdl:simple_directmedia_layer"
  'gentoo: media-libs/libsdl2'
)
msys2_repository_url="https://github.com/libsdl-org/SDL/"
url="https://libsdl.org/"
license=("spdx:Zlib")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf")
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-libiconv"
         "${MINGW_PACKAGE_PREFIX}-vulkan")
source=("https://github.com/libsdl-org/SDL/releases/download/release-${pkgver}/SDL2-${pkgver}.tar.gz"{,.sig}
        005-sdl-config-win-paths.patch)
sha256sums=('5f5993c530f084535c65a6879e9b26ad441169b3e25d789d83287040a9ca5165'
            'SKIP'
            'c47283d104039965d5cf99eeb58aebbac059648c46b931e9efcb864abab9bfd9')
validpgpkeys=('1528635D8053A57F77D1E08630A59377A7763BE6') # Sam Lantinga <slouken@libsdl.org>

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

  # Fixes sdl-config https://github.com/msys2/MINGW-packages/issues/9881
  patch -p1 -i "${srcdir}"/005-sdl-config-win-paths.patch
}

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

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DCMAKE_BUILD_TYPE=Release \
    -DSDL_VULKAN=ON \
    -DSDL_TEST=ON \
    ../${_realname}-${pkgver}

  ${MINGW_PREFIX}/bin/cmake --build .
}

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

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .
}
