# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Contributor: Dan Williams <dan@ma.ssive.co>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=libseccomp
pkgver=2.6.0
pkgrel=1
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
	seccomp_export_bpf_mem-bounds.patch
	62-sim-arch_transactions-fuzz-remove.patch
	"

# 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() {
	# commit be65b26b67099be2b2b4890d736dbd1ad15adf36 adapted to new kernel 5.x syscalls
	# as long as we are at 4.19 kernel, we need this change
	case "$CARCH" in
		ppc64le|s390x) rm -f tests/36-sim-ipc_syscalls.tests \
			             tests/37-sim-ipc_syscalls_be.tests;;
	esac

	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="
9039478656d9b670af2ff4cb67b6b1fa315821e59d2f82ba6247e988859ddc7e3d15fea159eccca161bf2890828bb62aa6ab4d6b7ff55f27a9d6bd9532eeee1b  libseccomp-2.6.0.tar.gz
f2c31dcafdc9a1ad78e32e76b75e1c1603071eaa3f979e1f2483b879a34ad07e0a4ef3642196a695415cdf81e1ed2bf325175872fb4e203ef9d0e668c287493f  remove-redefinition-prctl.patch
1bc34d3df7be39e8eafd9d853fb2c58425892632f404c01286a75dba30d466912165dfa420b538402784a72734763269849bce9625f8b1b6641f4592e6a20359  py-shared.patch
90b1e4a38e058150cd6e483a490d49ca7c4066bbb61c8066ec809453abd8f2c3bf0a32346cb664b0faa5ea8d3311f7bff8e485b75248f25ff7252249afd6b15b  busybox.patch
d4fccd5cca7c05cb34213e28a64f32c17530e73947bf17c5e34de2f3a53e3fc5dad8d585acea8568c1b5f026de8046c49a743754c27d37c7703f2c96a8f51583  seccomp_export_bpf_mem-bounds.patch
50b7c03db88c6fcdaefefe1d4bd2f02cb16dac845d408a46d4882053238d63449114dde944b1b287103246d65879501e739741be85c2f1b2aeb7faa1a181a468  62-sim-arch_transactions-fuzz-remove.patch
"
