# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

pkgname=('nettle' 'libnettle' 'libhogweed' 'libnettle-devel')
pkgver=3.7.3
pkgrel=1
pkgdesc="A low-level cryptographic library"
arch=('i686' 'x86_64')
url="https://www.lysator.liu.se/~nisse/nettle/"
license=('GPL2')
groups=('net-utils')
depends=('gmp')
makedepends=('gmp-devel')
source=(https://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.gz{,.sig}
        nettle-2.6-msys2.patch
        3.2-dlopen-test-msys-test.patch)
validpgpkeys=('343C2FF0FBEE5EC2EDBEF399F3599FF828C67298') # Niels M├╢ller <nisse@lysator.liu.se>
sha256sums=('661f5eb03f048a3b924c3a8ad2515d4068e40f67e774e8a26827658007e3bcf0'
            'SKIP'
            '3c83eeb093ae056ba0a583d38ed171891509ab70e39057594ee8f30885db0d99'
            'a922cc88086f0f1af1aea5a40ead773c5cc97d6c55bd6870b574f62dde812a51')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  patch -p1 -i ${srcdir}/nettle-2.6-msys2.patch
  patch -p1 -i ${srcdir}/3.2-dlopen-test-msys-test.patch
  autoreconf -fi
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  ./configure \
    --prefix=/usr \
    --libdir=/usr/lib \
    --build=${CHOST} \
    --enable-shared \
    --enable-static \
    --disable-assembler

  make
  make DESTDIR="${srcdir}/dest" install
}

check() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  make -k check
}

package_nettle() {
  depends=('libnettle')
  install=$pkgname.install

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
}

package_libnettle() {
  groups=('libraries')
  depends=('libhogweed')

  mkdir -p ${pkgdir}/usr/bin
  cp -rf ${srcdir}/dest/usr/bin/*nettle*.dll ${pkgdir}/usr/bin/
}

package_libhogweed() {
  groups=('libraries')
  depends=('gmp')

  mkdir -p ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/bin/*hogweed*.dll ${pkgdir}/usr/bin/
}

package_libnettle-devel() {
  pkgdesc="Libnettle headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libnettle=${pkgver}" "libhogweed=${pkgver}" 'gmp-devel')

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