# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=liblouis
pkgver=3.31.0
pkgrel=0
pkgdesc="Braille translator and back-translator"
url="https://liblouis.io/"
arch="all"
license="GPL-3.0-or-later"
makedepends="
	help2man
	m4
	python3
	py3-gpep517
	py3-setuptools
	py3-wheel
	"
checkdepends="bash"
subpackages="
	$pkgname-static
	$pkgname-dev
	$pkgname-bin:_bin
	$pkgname-doc
	py3-$pkgname-pyc
	py3-$pkgname:_py3:noarch
	"
source="https://github.com/liblouis/liblouis/releases/download/v$pkgver/liblouis-$pkgver.tar.gz"

# secfixes:
#   3.22.0-r0:
#     - CVE-2022-26981

build() {
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var \
		--enable-ucs4
	make

	cd python
	gpep517 build-wheel \
		--wheel-dir "$builddir"/.dist \
		--output-fd 3 3>&1 >&2
}

check() {
	make check

	# Tests fail on s390x, very likely due to endianness
	if [ "$CARCH" != "s390x" ]; then
		python3 -m venv --clear --without-pip --system-site-packages .testenv
		.testenv/bin/python3 -m installer .dist/*.whl

		cd python
		LD_LIBRARY_PATH="$builddir/liblouis/.libs" \
		LOUIS_TABLEPATH="$builddir/tables" \
			../.testenv/bin/python3 -m unittest tests/test_louis.py
	fi
}

package() {
	make DESTDIR="$pkgdir" install

	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

_bin() {
	pkgdesc="$pkgdesc (tools)"
	depends="bash cmd:patgen make perl py3-$pkgname"

	amove usr/bin
}

_py3() {
	pkgdesc="$pkgdesc (python ctypes bindings)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove 'usr/lib/python*'
}

sha512sums="
d5414131ec2820f8deefb271d4e5e1e01c75ae94dc52b34dc0b132dee8004c7960c79cfa0cdaf59040e51fc9ffaff45e59c33bfdd651db73c56c62253047feb4  liblouis-3.31.0.tar.gz
"
