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

pkgbase=rhash
pkgname=("lib${pkgbase}" "lib${pkgbase}-devel" "${pkgbase}")
pkgver=1.4.4
pkgrel=1
pkgdesc='Utility for verifying hash sums of files'
url='https://sourceforge.net/projects/rhash/'
msys2_repository_url="https://github.com/rhash/RHash"
msys2_references=(
  "anitya: 13843"
  "cpe: cpe:2.3:a:rhash_project: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
        1.4.4_flags-macros.patch)
makedepends=('gettext-devel' 'openssl-devel' 'autotools' 'gcc')
sha256sums=('8e7d1a8ccac0143c8fe9b68ebac67d485df119ea17a613f4038cda52f84ef52a'
            'SKIP'
            '7314bc0bad48b8ec0f1133a5945507e4de5457f70ec81b48498891edb0aad6ea'
            '44cda291787236afc04b0578e20ad40363ea0e26b7b5ca971a6aae8c494ece8a'
            '62356fe90845872ca2eb00e08ae1e44c06c1dbe07b895d6865647cb70dbcd345')
# 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
  # part fixed when https://github.com/rhash/RHash/commit/c804982d1b24c6533118b3068d2cfdca685076f3 is released
  patch -p0 -i ${srcdir}/1.4.4_flags-macros.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"
  make install-gmo LOCALEDIR="${srcdir}/dest/usr/share/locale"
}

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}" "libiconv" "libintl")
  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
  mkdir -p "${pkgdir}/usr/share"
  cp -rf ${srcdir}/dest/usr/share/* ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/etc ${pkgdir}/etc
}
