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

_realname=godot
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=3.3
pkgrel=1
pkgdesc='An advanced, feature packed, multi-platform 2D and 3D game engine (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url="http://www.godotengine.org/"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-yasm" "${MINGW_PACKAGE_PREFIX}-scons")
options=('!emptydirs' 'staticlibs' 'strip')
source=("https://github.com/godotengine/godot/archive/${pkgver}-stable.tar.gz")
sha256sums=('595ff16eaef3d0b6c030575f4b7fcae8b805e407b90a2f71af3e4142362c1794')

build() {
  msg "Build for ${CARCH}"

  rm -rf build-${CARCH} | true
  cp -r "${_realname}-${pkgver}-stable" "build-${CARCH}"
  cd "${srcdir}/build-${CARCH}"

  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

  # TODO: try to use some system libs:
  # https://github.com/msys2/MINGW-packages/pull/7212#issuecomment-723002506
  ${MINGW_PREFIX}/bin/scons ${MAKEFLAGS} \
    platform=windows \
    target=release_debug \
    use_mingw=yes \
    "${extra_config[@]}" \
    tools=yes
}

package() {
  cd "${srcdir}/build-${CARCH}"
  install -Dm755 bin/godot.windows.opt.tools.*.exe "${pkgdir}${MINGW_PREFIX}/bin/godot.exe"
  install -Dm644 icon.svg "${pkgdir}${MINGW_PREFIX}/share/pixmaps/godot.svg"
  install -D -m644 LICENSE.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/godot/LICENSE.txt"
  install -D -m644 "misc/dist/linux/godot.6" "${pkgdir}${MINGW_PREFIX}/share/man/man6/godot.6"
}
