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

_realname=raylib
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=5.5
pkgrel=2
pkgdesc='Simple and easy-to-use game programming library (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.raylib.com/'
msys2_repository_url='https://github.com/raysan5/raylib/'
msys2_references=(
  'archlinux: raylib'
  "cpe: cpe:/a:raylib:raylib"
)
license=('spdx:Zlib')
depends=("${MINGW_PACKAGE_PREFIX}-cc-libs"
         "${MINGW_PACKAGE_PREFIX}-glfw")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-ninja")
source=("https://github.com/raysan5/raylib/archive/${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('aea98ecf5bc5c5e0b789a76de0083a21a70457050ea4cc2aec7566935f5e258e')

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=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${extra_config[@]}" \
    -DBUILD_EXAMPLES=OFF \
    -DUSE_EXTERNAL_GLFW=ON \
    -DBUILD_SHARED_LIBS=OFF \
    -B "build-${MSYSTEM}-static" \
    -S "${_realname}-${pkgver}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}-static"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"Ninja" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "${extra_config[@]}" \
    -DBUILD_EXAMPLES=OFF \
    -DBUILD_SHARED_LIBS=ON \
    -DUSE_EXTERNAL_GLFW=ON \
    -B "build-${MSYSTEM}-shared" \
    -S "${_realname}-${pkgver}"

  "${MINGW_PREFIX}"/bin/cmake.exe --build "build-${MSYSTEM}-shared"
}

package() {
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}-static"
  DESTDIR="${pkgdir}" "${MINGW_PREFIX}"/bin/cmake.exe --install "build-${MSYSTEM}-shared"

  install -Dm644 "${srcdir}"/${_realname}-${pkgver}/LICENSE \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
