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

_realname=rhash
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.4.1
pkgrel=3
pkgdesc="Great utility for computing hash sums (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://sourceforge.net/projects/rhash/'
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
license=('custom' 'BSD')
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/rhash/RHash/archive/v${pkgver}.tar.gz"
        "${_realname}-${pkgver}.tar.gz.asc"::"https://github.com/rhash/RHash/releases/download/v${pkgver}/v${pkgver}.tar.gz.asc"
        rhash-link-implib.patch
        rhash-all-mingw.patch)
sha256sums=('430c812733e69b78f07ce30a05db69563450e41e217ae618507a4ce2e144a297'
            'SKIP'
            'a9d2491942fd4dc34eafea677d734902761c4e366b997a8e7f7ff6f7b435c9b0'
            'c999da390c4c19ff6c39dd7a1a85b8f07300b9bb72b1507a6255c341b8c2fc4a')
validpgpkeys=('2875F6B1C2D27A4F0C8AF60B2A714497E37363AE')

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

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  cp -R "${srcdir}"/RHash-${pkgver} "${srcdir}"/build-${CARCH}
  cd "${srcdir}"/build-${CARCH}
  ./configure \
     --prefix=${MINGW_PREFIX} \
     --enable-lib-static \
     --enable-lib-shared
  make
}

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

package() {
  cd "${srcdir}"/build-${CARCH}
  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
}
