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

pkgname=('libssh2' 'libssh2-devel')
pkgver=1.9.0
pkgrel=1
pkgdesc="A library implementing the SSH2 protocol as defined by Internet Drafts"
url="https://libssh2.org/"
groups=('libraries')
arch=('i686' 'x86_64')
license=('BSD')
makedepends=('openssl-devel' 'zlib-devel')
options=('!libtool')
source=("https://libssh2.org/download/${pkgname}-${pkgver}.tar.gz"{,.asc}
        1.2.7-cygwin.patch
        libssh2-1.4.3-msys2.patch)
sha256sums=('d5fb8bd563305fd1074dda90bd053fb2d29fc4bce048d182f96eaa466dfadafd'
            'SKIP'
            '894937383ec281301cc15464e07cd518e5f1093fd46c41e1bb7d1f2b0ed1a4df'
            'bbfe1e132e824ac50aaf9364a82625bb75f7672ec52f041314cc539b4587bc6c')
validpgpkeys=('914C533DF9B2ADA2204F586D78E11C6B279D5C91' '27EDEAF22F3ABCEB50DB9A125CC908FDB71E12C2')

prepare() {
  cd "${pkgname}-${pkgver}"
  patch -p2 -i ${srcdir}/1.2.7-cygwin.patch
  patch -p1 -i ${srcdir}/libssh2-1.4.3-msys2.patch

  autoreconf -ivf
}

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

  ./configure \
    --prefix=/usr \
    --build=${CHOST} \
    --enable-shared \
    --enable-static \
    --with-openssl \
    --with-libz \
    --without-libz-prefix \
    --without-libssl-prefix \
    --without-libgcrypt-prefix
  make
  make DESTDIR="${srcdir}/dest" install
}

package_libssh2() {
  pkgdesc="Multi-protocol file transfer library (runtime)"
  depends=('ca-certificates' 'openssl' 'zlib')
  groups=('libraries')

  mkdir -p ${pkgdir}/usr/bin
  cp -f ${srcdir}/dest/usr/bin/*.dll ${pkgdir}/usr/bin/
  cp -rf ${srcdir}/dest/usr/share ${pkgdir}/usr/
  install -Dm644 ${srcdir}/${pkgname}-${pkgver}/COPYING "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
}

package_libssh2-devel() {
  pkgdesc="Libssh2 headers and libraries"
  options=('staticlibs')
  depends=("libssh2=${pkgver}" 'openssl-devel' 'zlib-devel')
  groups=('development')

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