# Contributor: Eivind Uggedal <eu@eju.no>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: fossdd <fossdd@pwned.life>
pkgname=hiredict
pkgver=1.3.1
pkgrel=0
pkgdesc="C client library for Redict"
url="https://codeberg.org/redict/hiredict"
arch="all"
license="BSD-3-Clause"
makedepends="openssl-dev>3"
checkdepends="redict"
subpackages="$pkgname-ssl $pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://codeberg.org/redict/hiredict/archive/$pkgver.tar.gz"
builddir="$srcdir/$pkgname"

build() {
	make USE_SSL=1 PREFIX=/usr DEBUG="$CFLAGS" LDFLAGS="$LDFLAGS"
}

check() {
	redict-server \
		--dir "$builddir" \
		--enable-debug-command local \
		--unixsocket "$builddir"/redict.sock&
	local _redictpid=$!

	make hiredict-test

	# make sure socket is available before we start running tests
	local _n=100 # wait up to 10 sec
	while ! [ -e "$builddir"/redict.sock ] && [ $_n -gt 0 ]; do
		sleep 0.1s
		_n="$((_n - 1))"
	done

	./hiredict-test -s "$builddir"/redict.sock || (kill $_redictpid && false)
	kill $_redictpid
}

package() {
	make USE_SSL=1 PREFIX="$pkgdir"/usr install
}

ssl() {
	amove usr/lib/libhiredict_ssl.so*
}

sha512sums="
208672d4dbdcc8bf21cff494ea2191b97b9d67b2c4b5a4f94e2c165613315b28b09e9e03de0495a069320df671e3f9d22a43209f175c2aae71550b0d832c0112  hiredict-1.3.1.tar.gz
"
