# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

pkgbase=rhash
pkgname=("lib${pkgbase}" "lib${pkgbase}-devel" "${pkgbase}")
pkgver=1.4.2
pkgrel=1
pkgdesc='Utility for verifying hash sums of files'
url='https://sourceforge.net/projects/rhash/'
license=('custom' 'MIT')
arch=('i686' 'x86_64')
source=(${pkgbase}-${pkgver}.tar.gz::https://github.com/rhash/RHash/archive/v${pkgver}.tar.gz
        ${pkgbase}-${pkgver}.tar.gz.asc::https://github.com/rhash/RHash/releases/download/v${pkgver}/v${pkgver}.tar.gz.asc
        1.4.0_rhash-CYGWIN.patch
        002-no-dynamicbase.patch)
makedepends=('openssl-devel')
sha256sums=('600d00f5f91ef04194d50903d3c79412099328c42f28ff43a0bdb777b00bec62'
            'SKIP'
            '08f647635f5c2519ba2f9b64165690eb31a49bdd43a0986b0a5cf3970d1b9de5'
            '44cda291787236afc04b0578e20ad40363ea0e26b7b5ca971a6aae8c494ece8a')
# https://sourceforge.net/p/rhash/wiki/PublicKey/
validpgpkeys=('2875F6B1C2D27A4F0C8AF60B2A714497E37363AE')

prepare() {
  cd RHash-${pkgver}
  patch -p2 -i ${srcdir}/1.4.0_rhash-CYGWIN.patch
  patch -p1 -i ${srcdir}/002-no-dynamicbase.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=/usr \
      --sysconfdir=/etc \
      --enable-lib-static \
      --enable-lib-shared
  make
  make install DESTDIR="${srcdir}/dest" PREFIX="/usr"
}

check() {
   echo "Skipping make check"
   cd "${srcdir}"/build-${CARCH}
   make test
}

package_librhash() {
  groups=('libraries')
  pkgdesc="LibRHash shared library"
  depends=('libopenssl' 'gcc-libs')

  cd ${srcdir}/dest
  mkdir -p "${pkgdir}/usr/bin"
  cp -f usr/bin/*.dll "${pkgdir}/usr/bin"
  cd "${srcdir}"/build-${CARCH}
  # license
  install -Dm644 COPYING "${pkgdir}"/usr/share/licenses/rhash/LICENSE
}

package_librhash-devel() {
  groups=('development')
  options=('staticlibs')
  depends=("librhash=${pkgver}")
  pkgdesc="Headers and static library for LibRHash"

  cd ${srcdir}/dest
  mkdir -p ${pkgdir}/usr
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
}

package_rhash() {
  depends=("librhash=${pkgver}")
  backup=('etc/rhashrc')

  cd ${srcdir}/dest
  mkdir -p "${pkgdir}/usr/bin"
  cp -rf ${srcdir}/dest/usr/bin/* ${pkgdir}/usr/bin/
  rm  -f ${pkgdir}/usr/bin/*.dll
  cp -rf ${srcdir}/dest/usr/share/* ${pkgdir}/usr
  cp -rf ${srcdir}/dest/etc ${pkgdir}/etc
}

