# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Contributor: Dan Williams <dan@ma.ssive.co>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libseccomp
pkgver=2.6.1
pkgrel=0
pkgdesc="interface to the Linux Kernel's syscall filtering mechanism"
url="https://github.com/seccomp/libseccomp"
arch="all"
license="LGPL-2.1-or-later"
depends_dev="linux-headers"
makedepends="$depends_dev gperf cython python3 python3-dev py3-gpep517 py3-setuptools autoconf automake libtool"
checkdepends="bash"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc py3-$pkgname:py3"
source="https://github.com/seccomp/libseccomp/releases/download/v$pkgver/libseccomp-$pkgver.tar.gz
	remove-redefinition-prctl.patch
	py-shared.patch
	busybox.patch
	"

# armhf & loongarch64: valgrind not available
# armv7, ppc64le & riscv64: several bpf-valgrind tests fail
case "$CARCH" in
aarch64|s390x|x86*) checkdepends="$checkdepends valgrind" ;;
esac

# secfixes:
#   2.4.0-r0:
#     - CVE-2019-9893

prepare() {
	default_prepare
	autoreconf -vif
}

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

	cd src/python
	CFLAGS="$CFLAGS -I../../include" \
	VERSION_RELEASE="$pkgver" \
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	LIBSECCOMP_TSTCFG_MODE_LIST="c python" \
	LD_LIBRARY_PATH="$PWD/src/.libs" \
	make check
}

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

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

py3() {
	pkgdesc="Python 3 bindings for $pkgname"

	amove usr/lib/python3*
}

sha512sums="
468404874ee013177f048611a4fefef87f4ee01b83d991f8bf9026c8fdb8506badd613e0355ad8222c5a7f51162b6829de6d72fc53222a56e0e123d5e85f73c4  libseccomp-2.6.1.tar.gz
f2c31dcafdc9a1ad78e32e76b75e1c1603071eaa3f979e1f2483b879a34ad07e0a4ef3642196a695415cdf81e1ed2bf325175872fb4e203ef9d0e668c287493f  remove-redefinition-prctl.patch
1bc34d3df7be39e8eafd9d853fb2c58425892632f404c01286a75dba30d466912165dfa420b538402784a72734763269849bce9625f8b1b6641f4592e6a20359  py-shared.patch
90b1e4a38e058150cd6e483a490d49ca7c4066bbb61c8066ec809453abd8f2c3bf0a32346cb664b0faa5ea8d3311f7bff8e485b75248f25ff7252249afd6b15b  busybox.patch
"
