# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libssh
pkgver=0.11.1
pkgrel=0
pkgdesc="Library for accessing ssh client services through C libraries"
options="!check" # Tests require CLIENT_TESTING enabled which needs socket_wrapper
url="https://www.libssh.org/"
arch="all"
license="LGPL-2.1-or-later BSD-2-Clause"
depends_dev="openssl-dev>3 zlib-dev"
makedepends="$depends_dev cmake samurai"
checkdepends="cmocka-dev"
subpackages="$pkgname-dev"
source="https://www.libssh.org/files/${pkgver%.*}/libssh-$pkgver.tar.xz"

# secfixes:
#   0.10.6-r0:
#     - CVE-2023-6004
#     - CVE-2023-6918
#     - CVE-2023-48795
#   0.9.6-r0:
#     - CVE-2021-3634
#   0.9.5-r0:
#     - CVE-2020-16135
#   0.9.4-r0:
#     - CVE-2020-1730
#   0.9.3-r0:
#     - CVE-2019-14889
#   0.7.6-r0:
#     - CVE-2018-10933

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=None \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DWITH_GSSAPI=OFF \
		-DUNIT_TESTING=OFF
	cmake --build build
}

check() {
	case "$CARCH" in
		s390x) _disabled_tests="-E torture_threads_buffer"
	esac
	cd build
	CTEST_OUTPUT_ON_FAILURE=TRUE ctest $_disabled_tests
}

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

sha512sums="
284d376ad9ea30b0274b4ac754b27d168286dca862ece43ef15ca6d89e66865ad7a6703cc12dd4a8564a60b8449ae9b36e6496fd51d34cc27ac4030f6cf216d6  libssh-0.11.1.tar.xz
"
