# Maintainer: Developer <dev@opalos.org>
# Maintainer: Developer <dev@opalos.org>

pkgbase=libssh
pkgname=(libssh
         libssh-docs)
pkgver=%version%
pkgrel=%release%
pkgdesc='Library for accessing ssh client services through C libraries'
url='https://www.libssh.org/'
license=(LGPL)
arch=(x86_64)
depends=(glibc
         openssl
         zlib)
makedepends=(cmake
             cmocka
             doxygen
             openssh
             python)
provides=(libssh.so)
source=(https://www.libssh.org/files/${pkgver%.*}/$pkgname-$pkgver.tar.xz{,.asc}
        https://gitlab.com/libssh/libssh-mirror/-/commit/1a02364b.patch)
sha256sums=('1861d498f5b6f1741b6abc73e608478491edcf9c9d4b6630eef6e74596de9dc1'
            'SKIP'
            '124612313b78dc89e47e87a17698113b8d2736c213e724c0ae0f84f87136ba48')
validpgpkeys=('8DFF53E18F2ABC8D8F3C92237EE0FC4DCC014E3D') # Andreas Schneider <asn@cryptomilk.org>

prepare() {
# Fix regression in IPv6 addresses in hostname parsing
  patch -d $pkgname-$pkgver -p1 < 1a02364b.patch
}

build() {
  cmake -B build -S $pkgname-$pkgver \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DWITH_GSSAPI=OFF \
    -DUNIT_TESTING=ON
  cmake --build build
  cmake --build build --target docs
}

check() {
  cmake --build build --target test
}

package_libssh() {
  DESTDIR="$pkgdir" cmake --install build
}

package_libssh-docs() {
  pkgdesc='Documentation for libssh'
  depends=()
  provides=()

  mkdir -p "$pkgdir"/usr/share/doc/libssh
  cp -r build/doc/html "$pkgdir"/usr/share/doc/libssh
#  cp -r build/doc/man "$pkgdir"/usr/share
#  rm "$pkgdir"/usr/share/man/man3/{bug,deprecated}.*
}
