# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=rhash
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.4.5
pkgrel=1
pkgdesc="Great utility for computing hash sums (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://sourceforge.net/projects/rhash/'
msys2_repository_url="https://github.com/rhash/RHash"
msys2_references=(
  "cpe: cpe:2.3:a:rhash_project:rhash"
)
license=('spdx:0BSD')
depends=("${MINGW_PACKAGE_PREFIX}-gettext-runtime")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-gettext-tools")
source=("https://github.com/rhash/RHash/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        rhash-mingw-install.patch
        rhash-all-mingw.patch)
sha256sums=('6db837e7bbaa7c72c5fd43ca5af04b1d370c5ce32367b9f6a1f7b49b2338c09a'
            '83cf845d426a5bee7ea21c9d9473328668a7e3d5bdd6e2583f208522f2ee231c'
            '8358373d8ffb490c27a0c45580c1d3c34468bbd74e3621b02b2de28191d2d56a')
validpgpkeys=('2875F6B1C2D27A4F0C8AF60B2A714497E37363AE')

prepare() {
  cd "${srcdir}"/RHash-${pkgver}
  patch -Np1 -i ../rhash-mingw-install.patch
  patch -Np1 -i ../rhash-all-mingw.patch
}

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

  ./configure \
     --prefix=${MINGW_PREFIX} \
     --enable-lib-static \
     --enable-lib-shared

  make
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}
  make test test-shared test-static || true
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}
  make -j1 install DESTDIR="${pkgdir}"
  make -j1 install install-gmo DESTDIR="${pkgdir}"

  # license
  # fully qualify path for this because there might be switch in
  # build systems.
  install -Dm644 "${srcdir}"/RHash-${pkgver}/COPYING \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/rhash/LICENSE
}
