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

pkgbase=gnutls
pkgname=('gnutls' 'libgnutls' 'libgnutls-devel')
_base_ver=3.7.2
pkgver=${_base_ver}
pkgrel=1
pkgdesc="A library which provides a secure layer over a reliable transport layer"
arch=('x86_64' 'i686')
license=('GPL3' 'LGPL2.1')
url="https://www.gnutls.org/"
makedepends=('gtk-doc'
             'gettext-devel'
             'libidn2-devel'
             'libiconv-devel'
             'gmp-devel'
             'libnettle-devel'
             'libp11-kit-devel'
             'libtasn1-devel'
             'libunistring-devel'
             'zlib-devel')
#optdepends=('guile: for use with Guile bindings')
source=(https://gnupg.org/ftp/gcrypt/gnutls/v${_base_ver%.*}/${pkgname}-${pkgver}.tar.xz{,.sig}
        gnutls-3.6.3-msysize.patch)
sha256sums=('646e6c5a9a185faa4cea796d378a1ba8e1148dbb197ca6605f95986a25af2752'
            'SKIP'
            'ede10b896e2cf8da72127fa7813fca15ba46f418167ecea6faef016744cf1ed2')
validpgpkeys=('0424D4EE81A0E3D119C6F835EDA21E94B565716F' # "Simon Josefsson <simon@josefsson.org>"
              '1F42418905D8206AA754CCDC29EE58B996865171' # "Nikos Mavrogiannopoulos <nmav@gnutls.org>
              '462225C3B46F34879FC8496CD605848ED7E69871') # "Daiki Ueno <ueno@unixuser.org>"

prepare() {
  cd "${srcdir}"/${pkgname}-${_base_ver}
  patch -p1 -i ${srcdir}/gnutls-3.6.3-msysize.patch

  autoreconf -vfi
}

build() {
  cd "${srcdir}/${pkgname}-${_base_ver}"
  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    --enable-shared \
    --enable-static \
    --disable-guile \
    --enable-cxx \
    --disable-hardware-acceleration \
    --enable-heartbeat-support \
    --with-default-trust-store-file=/usr/ssl/certs/ca-bundle.crt

  make
  make DESTDIR="${srcdir}/dest" install
  rm ${srcdir}/dest/usr/share/info/dir
}

check() {
  cd "${srcdir}"/${pkgname}-${_base_ver}
  #make check
}

package_gnutls() {
  depends=("libgnutls=${pkgver}")

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*.exe ${pkgdir}/usr/bin/
  #cp -rf ${srcdir}/dest/usr/share/doc ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/man ${pkgdir}/usr/share/
}

package_libgnutls() {
  depends=('gcc-libs' 'libidn2' 'libiconv' 'libintl' 'gmp' 'libnettle' 'libp11-kit' 'libtasn1' 'zlib')
  groups=('libraries')
  install=libgnutls.install

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/
}

package_libgnutls-devel() {
  pkgdesc="Libgnutls headers and libraries"
  groups=('development')
  depends=("libgnutls=${pkgver}"
           'libidn2-devel'
           'libnettle-devel'
           'libp11-kit-devel'
           'libtasn1-devel')

  mkdir -p ${pkgdir}/usr/lib
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib/pkgconfig ${pkgdir}/usr/lib/
  cp -f ${srcdir}/dest/usr/lib/*.a ${pkgdir}/usr/lib/
}
