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

pkgbase=libassuan
pkgname=('libassuan' 'libassuan-devel')
pkgver=3.0.2
pkgrel=1
pkgdesc="A IPC library used by some GnuPG related software"
arch=('i686' 'x86_64')
url="https://gnupg.org/related_software/libassuan"
msys2_repository_url='https://git.gnupg.org/cgi-bin/gitweb.cgi?p=libassuan.git'
msys2_pgp_keys_url='https://gnupg.org/signature_key.html'
license=('GPL')
makedepends=('libgpg-error-devel' 'autotools' 'gcc')
options=('strip' 'libtool')
_oldver=2.5.7
source=(https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${_oldver}.tar.bz2{,.sig}
        https://gnupg.org/ftp/gcrypt/${pkgname}/${pkgname}-${pkgver}.tar.bz2{,.sig})
sha256sums=('0103081ffc27838a2e50479153ca105e873d3d65d8a9593282e9c94c7e6afb76'
            'SKIP'
            'd2931cdad266e633510f9970e1a2f346055e351bb19f9b78912475b8074c36f6'
            'SKIP')
validpgpkeys=('AC8E115BF73E2D8D47FA9908E98E9B2D19C6C8BD'  # Niibe Yutaka (GnuPG Release Key)
              '6DAA6E64A76D2840571B4902528897B826403ADA') # Werner Koch (dist signing 2020)

prepare() {
  cd "${pkgname}-${_oldver}"

  autoreconf -fi
  cd ..

  cd "${pkgname}-${pkgver}"

  autoreconf -fi
}

build() {
  cd "${pkgname}-${_oldver}"

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared

  make no_undefined="-no-undefined"
  make DESTDIR="${srcdir}/dest_old" install
  cd ..

  cd "${pkgname}-${pkgver}"

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static

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

check() {
  cd "${pkgname}-${pkgver}"
  #make check
}

package_libassuan() {
  groups=('libraries')
  depends=('gcc-libs' 'libgpg-error')

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

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share/info ${pkgdir}/usr/share/

  install -D -m644 ${srcdir}/${pkgname}-${pkgver}/COPYING ${pkgdir}/usr/share/licenses/${pkgname}/COPYING
}

package_libassuan-devel() {
  pkgdesc="Libassuan headers and libraries"
  groups=('development')
  options=('staticlibs')
  depends=("libassuan=${pkgver}" 'libgpg-error-devel')

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

  mkdir -p ${pkgdir}/usr/share
  cp -rf ${srcdir}/dest/usr/share/aclocal ${pkgdir}/usr/share/
}
