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

_realname=4th
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.62.5
pkgrel=1
pkgdesc="A Forth Compiler (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url="https://www.xs4all.nl/~thebeez/4tH/index.html"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-binutils")
options=(!strip staticlibs)
source=("${_realname}-${pkgver}.tar.gz"::"https://downloads.sourceforge.net/sourceforge/forth-4th/${_realname}-${pkgver}-x86_64.tar.gz")
sha256sums=('e51ced7e71c942a27104baeae6cff68f44ae37a1c5813b6c12f9a3a1cfde309a')

build() {
  cd "${srcdir}/${_realname}-${pkgver}/sources/"
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  cp -R ${srcdir}/${_realname}-${pkgver}/sources/. "${srcdir}"/build-${CARCH}
  CROSS="${MINGW_PREFIX}/bin/" \
  make -f Makefile.W32
}

package() {
  cd "${srcdir}/${_realname}-${pkgver}/sources/"
  install -D -m644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -d "${pkgdir}${MINGW_PREFIX}/"{share/doc/${_realname},lib,bin}
  CROSS="${MINGW_PREFIX}/bin/" \
  make -f Makefile.W32 BINARIES="${pkgdir}${MINGW_PREFIX}/bin" \
       LIBRARIES="${pkgdir}${MINGW_PREFIX}/lib" \
       DOCDIR="${pkgdir}${MINGW_PREFIX}/share/doc" \
       MANDIR="${pkgdir}${MINGW_PREFIX}/share/man" install
}
