# Template file for 'util-linux'
# Keep this package sync with util-linux-common
pkgname=util-linux
version=2.40.2
revision=1
build_style=gnu-configure
configure_args="--exec-prefix=\${prefix} --enable-libuuid --disable-makeinstall-chown
 --enable-libblkid --enable-fsck --disable-rpath --enable-fs-paths-extra=/usr/sbin:/usr/bin
 --enable-vipw --enable-newgrp --enable-chfn-chsh --with-systemdsystemunitdir=no
 --with-udev --without-python --enable-write"
hostmakedepends="gettext pkg-config"
makedepends="libcap-ng-devel pam-devel readline-devel zlib-devel
 eudev-libudev-devel sqlite-devel"
depends="libfdisk>=${version}_1<=${version}_9999
 libblkid>=${version}_1<=${version}_9999
 libmount>=${version}_1<=${version}_9999
 libsmartcols>=${version}_1<=${version}_9999
 libuuid>=${version}_1<=${version}_9999
 liblastlog2>=${version}_1<=${version}_9999"
checkdepends="xz tar iproute2 socat procps-ng bc"
short_desc="Miscellaneous linux utilities"
maintainer="Enno Boland <gottox@voidlinux.org>"
license="GPL-2.0-or-later"
homepage="https://www.kernel.org/pub/linux/utils/util-linux/"
distfiles="${KERNEL_SITE}/utils/${pkgname}/v${version%.${version#*.*.}}/${pkgname}-${version}.tar.xz"
checksum=d78b37a66f5922d70edf3bdfb01a6b33d34ed3c3cafd6628203b2a2b67c8e8b3

if [ "$XBPS_TARGET_LIBC" = "glibc" ]; then
	makedepends+=" libxcrypt-devel"
fi

if [ "$XBPS_TARGET_LIBC" = "musl" ] && [ "$XBPS_TARGET_WORDSIZE" -eq 32 ]; then
	configure_args+=" --disable-year2038"
fi

# Create uuidd system account for uuidd.
system_accounts="_uuidd"
_uuidd_homedir="/var/empty"
conf_files="/etc/pam.d/*"
provides="eject-${version}_1 rfkill-${version}_1"
replaces="rfkill>=0"

# XXX musl needs this for switch_root(8).
CFLAGS="-D_DIRENT_HAVE_D_TYPE"
# XXX currently packaged musl doesn't provide __NR_landlock_* macros
CFLAGS+=" -D__NR_landlock_create_ruleset=444 -D__NR_landlock_add_rule=445 -D__NR_landlock_restrict_self=446"

alternatives="
 logger:logger:/usr/bin/${pkgname}-logger
 logger:logger.1:/usr/share/man/man1/${pkgname}-logger.1
"

post_extract() {
	# hung inside xbps-src
	rm -f tests/ts/lsns/ioctl_ns
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		# Known broken
		rm -f tests/ts/col/multibyte
	fi
}

do_install() {
	make usrsbin_execdir=/usr/bin DESTDIR=${DESTDIR} install

	# Correct perms for newgrp, chfn, chsh, wall and write.
	chmod u+s $DESTDIR/usr/bin/{newgrp,chsh,chfn}

	mv ${DESTDIR}/usr/bin/{logger,${pkgname}-logger}
	mv ${DESTDIR}/usr/share/man/man1/{logger,${pkgname}-logger}.1
	# pam login utils.
	vinstall $FILESDIR/login.pam 644 etc/pam.d login
	vinstall $FILESDIR/su.pam 644 etc/pam.d su
	vinstall $FILESDIR/su.pam 644 etc/pam.d su-l
	vinstall $FILESDIR/common.pam 644 etc/pam.d chfn
	vinstall $FILESDIR/common.pam 644 etc/pam.d chsh

	vsv uuidd

	rm -rf "$DESTDIR/usr/include"
	rm -rf "$DESTDIR/usr/lib"
	rm -rf "$DESTDIR/usr/share/man/man3"
	# Provided by util-linux-common
	rm -rf "$DESTDIR/usr/share/locale"
}
