# Template file for 'cryptsetup'
pkgname=cryptsetup
version=2.5.0
revision=1
build_style=gnu-configure
configure_args="--with-crypto_backend=openssl --enable-cryptsetup-reencrypt
 --disable-asciidoc --enable-libargon2 $(vopt_enable pwquality)"
make_check_args="-C tests"
hostmakedepends="pkg-config"
makedepends="device-mapper-devel json-c-devel openssl-devel popt-devel
 libargon2-devel libssh-devel $(vopt_if pwquality libpwquality-devel)"
checkdepends="procps-ng which jq tar xz xxd"
short_desc="Setup virtual encryption devices under Linux dm-crypt"
maintainer="Daniel Eyßer <daniel.eysser@gmail.com>"
license="GPL-2.0-or-later"
homepage="https://gitlab.com/cryptsetup/cryptsetup"
changelog="https://gitlab.com/cryptsetup/cryptsetup/raw/master/docs/v${version}-ReleaseNotes"
distfiles="${KERNEL_SITE}/utils/cryptsetup/v${version%.*}/${pkgname}-${version}.tar.xz"
checksum=9184a6ebbd9ce7eb211152e7f741a6c82f2d1cc0e24a84ec9c52939eee0f0542
subpackages="libcryptsetup cryptsetup-devel"
build_options="pwquality"
desc_option_pwquality="Enable support for checking password quality via libpwquality"

if [ "$XBPS_LIBC" = "musl" ]
then
	make_check=no # Test fail on musl see upstream:
	# https://gitlab.com/cryptsetup/cryptsetup/-/issues/781
else
	make_check=ci-skip # tests depend on acessing /dev/mapper/control fails on CI
fi

post_patch() {
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		# Require losetup from util-linux, also failing when present
		# TODO: 2 tests require lsblk
		rm -f tests/compat-test
		ln -f /bin/true tests/compat-test
	fi
}

if [ "$XBPS_TARGET_LIBC" = musl ]; then
	configure_args+=" --enable-static-cryptsetup"
	subpackages+=" cryptsetup-static"

	makedepends+=" argp-standalone"
	LDFLAGS+=" -largp"
fi

cryptsetup-static_package() {
	short_desc+=" - static cryptsetup"
	pkg_install() {
		vmove "usr/bin/*.static"
	}
}

libcryptsetup_package() {
	short_desc+=" - runtime libraries"
	pkg_install() {
		vmove "usr/lib/*.so.*"
	}
}

cryptsetup-devel_package() {
	depends="libcryptsetup>=${version}_${revision}"
	short_desc+=" - development files"
	pkg_install() {
		vmove usr/include
		vmove usr/lib/pkgconfig
		vmove "usr/lib/*.so"
		case $XBPS_TARGET_MACHINE in
			*-musl)
				vmove "usr/lib/*.a"
			;;
		esac
	}
}
