# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=sexpect
pkgver=2.3.14
pkgrel=0
pkgdesc="expect designed for shell scripts"
url="https://github.com/clarkwang/sexpect"
arch="all"
license="GPL-3.0-only"
makedepends="
	cmake
	samurai
	"
checkdepends="
	bash
	procps
	"
subpackages="$pkgname-doc"
source="https://github.com/clarkwang/sexpect/archive/v$pkgver/sexpect-$pkgver.tar.gz"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		local crossopts="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=MinSizeRel \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DCMAKE_C_FLAGS="$CFLAGS -D_GNU_SOURCE" \
		$crossopts
	cmake --build build
}

check() {
	local skip='interact-re-helper|spawn-nonblock'
	case "$CARCH" in
		s390x) skip="$skip|spawn-discard"  # FIXME
		;;
		loongarch64) skip="$skip|get-expbuf"  # FIXME
		;;
	esac

	cd build
	ctest --exclude-regex "$skip"
}

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

sha512sums="
dbab06e29c7d31b18283f0bae9e2a8742cfeeae0e16ad145d27f252318546b4277914d79dab0db908f0d13eb78f694645e3de4423fc41c8f057ae39fc334ba55  sexpect-2.3.14.tar.gz
"
