# Template file for 'qemu-user-static'
# This package should be updated together with qemu
pkgname=qemu-user-static
version=9.0.2
revision=2
build_style=configure
configure_args="--prefix=/usr --sysconfdir=/etc --libexecdir=/usr/libexec
 --disable-kvm --disable-png --disable-virtfs --disable-fdt --disable-seccomp
 --enable-linux-user --disable-system --static --disable-pie"
hostmakedepends="flex glib-devel pkg-config perl python3 ninja"
makedepends="dtc-devel glib-devel pixman-devel libuuid-devel"
short_desc="QEMU User-mode emulators (statically compiled)"
maintainer="classabbyamp <void@placeviolette.net>"
license="GPL-2.0-only, LGPL-2.1-only"
homepage="https://www.qemu.org"
distfiles="https://wiki.qemu.org/download/qemu-${version}.tar.bz2"
checksum=6fef38a497ff65f8d45c611b12ed5f5bb3e19ea6d76bfaea6857bf6fd76701e6

if [ "$CROSS_BUILD" ]; then
	configure_args+=" --cross-prefix=${XBPS_CROSS_TRIPLET}-"
fi

post_install() {
	# Remove unneeded stuff.
	rm -rf ${DESTDIR}/etc ${DESTDIR}/usr/share ${DESTDIR}/usr/libexec
	for f in nbd io img; do
		rm -f ${DESTDIR}/usr/bin/qemu-${f}
	done
	for f in ${DESTDIR}/usr/bin/*; do
		mv ${f} ${f}-static
	done

	vmkdir usr/share/binfmts
	HOST_ARCH="${XBPS_TARGET_MACHINE%-musl}" scripts/qemu-binfmt-conf.sh --debian \
		--exportdir "${DESTDIR}"/usr/share/binfmts --qemu-path /usr/bin \
		--preserve-argv0 yes --persistent yes --credential yes
	for bf in "${DESTDIR}"/usr/share/binfmts/*; do
		vsed -i -e "s/${bf##*/}/&-static/g" "$bf"
		mv "$bf" "${bf}-static"
	done
}
