# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=extremetuxracer
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.8.4
pkgrel=2
pkgdesc="Downhill racing game starring Tux (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://sourceforge.net/projects/extremetuxracer/"
msys2_repository_url="https://github.com/jcowgill/extremetuxracer"
license=('spdx:GPL-2.0-or-later')
depends=(
  "${MINGW_PACKAGE_PREFIX}-sfml"
  "${MINGW_PACKAGE_PREFIX}-cc-libs"
)
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-autotools"
  "${MINGW_PACKAGE_PREFIX}-cc"
)
source=("https://downloads.sourceforge.net/${_realname}/etr-${pkgver}.tar.xz"
        "0001-relocate.patch"
        "pathtools.c"
        "pathtools.h"
        "sfml3.patch")
sha256sums=('fa3285cc0c755a5aff529f3f2cea3516481114c6b4b8e1ec0769feeff04773e5'
            'dfe6fa9c5ac538545dca8c734fb10f79e9d1a44440c44c1f22227c7289cbc67b'
            'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0'
            '1585ef1b61cf53a2ca27049c11d49e0834683dfda798f03547761375df482a90'
            'aec54a09ae6dfc641243864f545eb7a16c5a1e22cbeeafda2b1bdc36105a8f1c')

prepare() {
  test ! -d "${startdir}/../mingw-w64-pathtools" || {
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.c" "${srcdir}/pathtools.c" &&
    cmp "${startdir}/../mingw-w64-pathtools/pathtools.h" "${srcdir}/pathtools.h"
  } || exit 1

  cd etr-${pkgver}
  cp -fHv ../pathtools.[ch] src/
  patch -p1 -i "../0001-relocate.patch"
  # https://github.com/jcowgill/extremetuxracer/commit/5823ba6c18432e083ec103ce74921270d7e071d6
  patch -p1 -i ../sfml3.patch
  sed -i 's/c++14/c++17/' configure.ac
  ./autogen.sh
}

build() {
  mkdir -p "build-${MSYSTEM}" && cd "build-${MSYSTEM}"

  CXXFLAGS+=" -Wno-c++11-narrowing" \
  ../"etr-${pkgver}"/configure \
    --prefix="${MINGW_PREFIX}" \
    --build="${MINGW_CHOST}" \
    --host="${MINGW_CHOST}" \
    --target="${MINGW_CHOST}"

  make
}

package() {
  cd "build-${MSYSTEM}"

  make DESTDIR="${pkgdir}" install
}
