# Maintainer: Andrew Sun <adsun701@gmail.com>

_realname=4th
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.64.1
pkgrel=1
pkgdesc="A Forth Compiler (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://www.xs4all.nl/~thebeez/4tH/index.html"
msys2_repository_url="https://sourceforge.net/p/forth-4th/code/HEAD/tree/trunk/"
license=('spdx:GPL-3.0-or-later')
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
options=(!strip)
source=("https://downloads.sourceforge.net/sourceforge/forth-4th/${_realname}-${pkgver}-x86_64.tar.gz")
sha256sums=('ba29b5cef482e58060287d67700ef25365372a6dbf2a3f878003654f24a40e04')

build() {
  [[ -d "${srcdir}"/build-${MSYSTEM} ]] && rm -rf "${srcdir}"/build-${MSYSTEM}
  cp -R "${srcdir}"/${_realname}-${pkgver}/sources/. "${srcdir}"/build-${MSYSTEM}
  cd "${srcdir}"/build-${MSYSTEM}

  CROSS="${MINGW_PREFIX}/bin/" \
  make -f Makefile.W32 CC="$CC"
}

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

  install -d "${pkgdir}${MINGW_PREFIX}/"{share/doc/${_realname},lib,bin}

  CROSS="${MINGW_PREFIX}/bin/" \
  make -f Makefile.W32 \
    CC="$CC" \
    BINARIES="${pkgdir}${MINGW_PREFIX}/bin" \
    LIBRARIES="${pkgdir}${MINGW_PREFIX}/lib" \
    DOCDIR="${pkgdir}${MINGW_PREFIX}/share/doc" \
    MANDIR="${pkgdir}${MINGW_PREFIX}/share/man" \
    install

  install -D -m644 "${srcdir}"/${_realname}-${pkgver}/COPYING \
    "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
