# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=sdl3
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=3.2.24
pkgrel=1
pkgdesc="A library for portable low-level access to a video framebuffer, audio output, mouse, and keyboard (Version 3) (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_references=(
  'anitya: 375746'
  'archlinux: sdl3'
  'aur: sdl3'
  "cpe: cpe:/a:libsdl:libsdl"
  "cpe: cpe:/a:libsdl:simple_directmedia_layer"
  'cygwin: SDL3'
  'gentoo: media-libs/libsdl3'
)
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}/${_realname^^}-${pkgver}.tar.gz"{,.sig})
sha256sums=('81cc0fc17e5bf2c1754eeca9af9c47a76789ac5efdd165b3b91cbbe4b90bfb76'
            'SKIP')
validpgpkeys=('1528635D8053A57F77D1E08630A59377A7763BE6') # Sam Lantinga <slouken@libsdl.org>

build() {
  declare -a _extra_config
  if check_option "debug" "n"; then
    _extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    _extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_extra_config[@]}" \
      -DBUILD_SHARED_LIBS=OFF \
      -DSDL_VULKAN=ON \
      -S "${_realname^^}-${pkgver}" \
      -B "build-${MSYSTEM}-static"

  cmake --build "build-${MSYSTEM}-static"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
    cmake \
      -GNinja \
      -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}" \
      "${_extra_config[@]}" \
      -DBUILD_SHARED_LIBS=ON \
      -DSDL_VULKAN=ON \
      -S "${_realname^^}-${pkgver}" \
      -B "build-${MSYSTEM}-shared"

  cmake --build "build-${MSYSTEM}-shared"
}

package() {
  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}-static"

  DESTDIR="${pkgdir}" cmake --install "build-${MSYSTEM}-shared"
}
