# Maintainer: Sarah Ottinger <schalaalexiazeal@gmail.com>

_realname=godot-cpp
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=4.5
pkgrel=1
pkgdesc='C++ bindings for the Godot script API (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.godotengine.org/"
msys2_repository_url="https://github.com/godotengine/godot-cpp"
license=('spdx:MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-godot=$pkgver"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://github.com/godotengine/godot-cpp/archive/godot-${pkgver}-stable.tar.gz")
sha256sums=('ac78539c0042554c494ea419549d2de88758d448721aeb0e5d41129aa87e339c')

prepare() {
  cd "${_realname}-godot-${pkgver}-stable"
}

build() {
  cd "${_realname}-godot-${pkgver}-stable"

  cd gdextension
  godot --display-driver headless --dump-extension-api --dump-gdextension-interface
  cd ..

  # build debug library
  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  cmake -B build \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DCMAKE_INSTALL_PREFIX="${MINGW_PREFIX}"
  cmake --build build

}

package() {
  cd "${_realname}-godot-${pkgver}-stable"

  install -dm755 "${pkgdir}${MINGW_PREFIX}"/{lib,include}
  install -Dm644 build/bin/libgodot-cpp.*.*.*.a "${pkgdir}${MINGW_PREFIX}"/lib/libgodot-cpp.a
  cp -rup {,build/gen/}include/godot_cpp "${pkgdir}${MINGW_PREFIX}"/include
  install -Dm644 gdextension/gdextension_interface.h "${pkgdir}${MINGW_PREFIX}"/include/godot_cpp
  install -Dm644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE.md"
}
