# Template file for 'criu'
pkgname=criu
version=3.18
revision=3
# i686 unsupported upstream: https://criu.org/32bit_tasks_C/R#Compatible_applications
# ppc64 big endian not supported upstream
archs="x86_64* aarch64* ppc64le* armv6l* armv7l*"
build_style=gnu-makefile
make_use_env=compliant
make_build_args="WERROR=0"
make_install_args="LOGROTATEDIR=/etc/logrotate.d LIBDIR=/usr/lib SBINDIR=/usr/bin"
hostmakedepends="asciidoc pkg-config xmlto protobuf which python3-pip protobuf-c protobuf-devel perl"
makedepends="libcap-devel libnet-devel libnftables-devel libnl3-devel protobuf-c-devel
 protobuf-devel libbsd-devel"
short_desc="Utility to checkpoint/restore a process tree"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="GPL-2.0-or-later, LGPL-2.1-only"
homepage="https://criu.org/"
changelog="https://criu.org/Download/criu"
distfiles="https://github.com/checkpoint-restore/criu/archive/refs/tags/v${version}.tar.gz"
checksum=6a9997981c9fe4730c848ce59346b3a22fad69b803607cb67a3f6ec0557fa474

pre_build() {
	if [[ "$CROSS_BUILD" ]]; then
		case "${XBPS_TARGET_MACHINE}" in
		armv6*) export ARCH=arm ARMV=6 ;;
		armv7*) export ARCH=arm ARMV=7 ;;
		aarch64*) export ARCH=aarch64 ;;
		esac
		export HOSTCFLAGS=${CFLAGS_FOR_BUILD}
	fi
}

pre_install() {
	if [[ "$CROSS_BUILD" ]]; then
		case "${XBPS_TARGET_MACHINE}" in
		armv6*) export ARCH=arm ARMV=6 ;;
		armv7*) export ARCH=arm ARMV=7 ;;
		aarch64*) export ARCH=aarch64 ;;
		esac
	fi
}

post_install() {
	vsv criu
}

criu-devel_package() {
	short_desc+=" - development files"
	depends="criu-${version}_${revision}"
	pkg_install() {
		vmove usr/include
		vmove "usr/lib/*.so"
		vmove usr/lib/pkgconfig
	}
}

criu-python_package() {
	# https://github.com/checkpoint-restore/criu/commit/4feb07020dedbf845fc00268d8ca02f4645641cd
	depends="python3-protobuf criu-${version}_${revision}"
	short_desc="Python bindings for criu and crit cli util"
	pkg_install() {
		vmove usr/bin/crit
		vmove usr/share/man/man1/crit.1
		vmove usr/lib/python${py3_ver}
	}
}
