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

_realname=godot-cpp
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=3.3
pkgrel=1
pkgdesc='C++ bindings for the Godot script API (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="http://www.godotengine.org/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-godot_headers")
makedepends=("${MINGW_PACKAGE_PREFIX}-scons")
_commit='d68e629a7cb93a6be73391d87be060eeb72d9d7a'
source=("https://github.com/godotengine/godot-cpp/archive/${_commit}.tar.gz")
sha256sums=('444d7511cbd10359a3d52d7ef326837fabe7d175f937733ba1ffcfcedd2cdb15')

prepare() {
  rm -rf "${_realname}-${pkgver}"
  mv "godot-cpp-${_commit}" "${_realname}-${pkgver}"
}

build() {
  cd "${_realname}-${pkgver}"
  declare -a extra_config
  if [ "$CARCH" = "x86_64" ]; then
    extra_config+=("use_lto=yes")
    extra_config+=("bits=64")
  else
    # lto is broken on 32bit
    extra_config+=("use_lto=no")
    extra_config+=("bits=32")
  fi

  ${MINGW_PREFIX}/bin/scons ${MAKEFLAGS} \
    platform=windows \
    target=release \
    use_mingw=yes \
	headers_dir=${MINGW_PREFIX}/include/godot \
	custom_api_file=${MINGW_PREFIX}/share/godot/api.json \
    "${extra_config[@]}" \
    generate_bindings=yes
}

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

  mkdir -p "${pkgdir}${MINGW_PREFIX}/include"
  cd include
  find . -type f -exec install -Dm644 {} "${pkgdir}${MINGW_PREFIX}/include/godot/"{} \;
  cd ..
  install -D -m644 bin/libgodot-cpp.windows.release.*.a "${pkgdir}${MINGW_PREFIX}/lib/libgodot-cpp.a"
  install -D -m644 LICENSE.md "${pkgdir}${MINGW_PREFIX}/share/licenses/godot-cpp/LICENSE.md"
}
