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

pkgbase=libgpg-error
pkgname=('libgpg-error' 'libgpg-error-devel') # 'gpg-error'
pkgver=1.42
pkgrel=1
pkgdesc="Support library for libgcrypt"
arch=('i686' 'x86_64')
url="https://gnupg.org"
license=('LGPL')
depends=('sh' 'libiconv' 'libintl')
makedepends=('libiconv-devel' 'gettext-devel')
source=(https://gnupg.org/ftp/gcrypt/libgpg-error/${pkgname}-${pkgver}.tar.bz2{,.sig}
        libgpg-error-1.16-msys2.patch
        gpg-error-static-linking.patch)
sha256sums=('fc07e70f6c615f8c4f590a8e37a9b8dd2e2ca1e9408f8e60459c67452b925e23'
            'SKIP'
            '9f24d6b26a9da60b14dba9ce8bb55110609ab5496ed969adfb07464c1393d678'
            '9780e3e397b983ef52d5dae22d54c4453a47bddf04eafa2f874c75038e3485eb')
#These might be signed by any of these keys https://gnupg.org/signature_key.html
validpgpkeys=('D8692123C4065DEA5E0F3AB5249B39D24F25E3B6'
              '031EC2536E580D8EA286A9F22071B08A33BD3F06'
              '5B80C5754298F0CB55D8ED6ABCEF7E294B092E28'
              '6DAA6E64A76D2840571B4902528897B826403ADA')
options=(!makeflags)

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

  patch -p1 -i ${srcdir}/libgpg-error-1.16-msys2.patch
  patch -p1 -i ${srcdir}/gpg-error-static-linking.patch
  autoreconf -fi
}

build() {
  cd "${srcdir}"/${pkgname}-${pkgver}
  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --without-libiconv-prefix \
    --without-libintl-prefix \
    --enable-shared \
    --enable-static

  make no_undefined=-no-undefined
  make DESTDIR="${srcdir}/dest" install
}

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

package_libgpg-error() {
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/bin ${pkgdir}/usr/
  rm -f ${pkgdir}/usr/bin/*-config
  cp -rf ${srcdir}/dest/usr/share/locale ${pkgdir}/usr/share/
}

package_libgpg-error-devel() {
  pkgdesc="libgpg-error headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=('libiconv-devel' 'gettext-devel')

  mkdir -p ${pkgdir}/usr/{bin,share}
  cp -f ${srcdir}/dest/usr/bin/*-config ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/include ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/lib ${pkgdir}/usr/
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
  cp -rf ${srcdir}/dest/usr/share/common-lisp ${pkgdir}/usr/share/
}
