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

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

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
	# Those files will be provided by util-linux
	rm -rf "$DESTDIR/usr/bin"
	rm -rf "$DESTDIR/usr/share/man/man1"
	rm -rf "$DESTDIR/usr/share/man/man5"
	rm -rf "$DESTDIR/usr/share/man/man8"
	rm -rf "$DESTDIR/usr/share/bash-completion"
	rm -rf "$DESTDIR/usr/share/doc/"
	# Some libraries have i18n text
	# rm -rf "$DESTDIR/usr/share/locale"
}

util-linux-libs_package() {
	short_desc+=" - meta libraries"
	build_style=meta
	depends="libfdisk>=${version}_${revision} libblkid>=${version}_${revision}
	 libmount>=${version}_${revision} libsmartcols>=${version}_${revision}
	 libuuid>=${version}_${revision}"
}

libfdisk_package() {
	short_desc="Library for fdisk(8)"
	depends="${sourcepkg}>=${version}_1"
	pkg_install() {
		vmove "usr/lib/libfdisk.so.*"
	}
}

libfdisk-devel_package() {
	depends="libblkid-devel>=${version}_1<=${version}_9999
	 libfdisk>=${version}_1<=${version}_9999"
	short_desc="Library for fdisk(8) - development files"
	pkg_install() {
		vmove usr/lib/libfdisk.a
		vmove usr/lib/libfdisk.so
		vmove "usr/lib/pkgconfig/*fdisk*"
		vmove usr/include/libfdisk
	}
}

libmount_package() {
	short_desc="Library for mount(8)"
	depends="${sourcepkg}>=${version}_1"
	pkg_install() {
		vmove "usr/lib/libmount.so.*"
	}
}

libmount-devel_package() {
	depends="libblkid-devel>=${version}_1<=${version}_9999
	 libmount>=${version}_1<=${version}_9999"
	short_desc="Library for mount(8) - development files"
	pkg_install() {
		vmove usr/lib/libmount.a
		vmove usr/lib/libmount.so
		vmove "usr/lib/pkgconfig/*mount*"
		vmove usr/include/libmount
	}
}

libblkid_package() {
	short_desc="Library to handle device identification"
	depends="${sourcepkg}>=${version}_1"
	pkg_install() {
		vmove "usr/lib/libblkid.so.*"
	}
}

libblkid-devel_package() {
	depends="zlib-devel libuuid-devel>=${version}_1<=${version}_9999
	 libblkid>=${version}_1<=${version}_9999"
	short_desc="Library to handle device identification - development files"
	pkg_install() {
		vmove usr/include/blkid
		vmove usr/lib/libblkid.a
		vmove usr/lib/libblkid.so
		vmove usr/lib/pkgconfig/blkid.pc
		vmove usr/share/man/man3/libblkid.3
	}
}

libuuid_package() {
	short_desc="UUID library"
	depends="${sourcepkg}>=${version}_1"
	license="BSD-3-Clause"
	pkg_install() {
		{
			grep Copyright libuuid/src/*.c
			cat Documentation/licenses/COPYING.BSD-3-Clause
		} >uuid.license
		vlicense uuid.license
		vmove "usr/lib/libuuid.so.*"
	}
}

libuuid-devel_package() {
	depends="libuuid>=${version}_${revision}<=${version}_9999"
	short_desc="UUID library development files"
	license="BSD-3-Clause"
	pkg_install() {
		vmove usr/lib/libuuid.a
		vmove usr/lib/libuuid.so
		vmove usr/lib/pkgconfig
		vmove usr/include/uuid
		vmove usr/share/man/man3/uuid*
	}
}

libsmartcols-devel_package() {
	depends="libsmartcols>=${version}_${revision}<=${version}_9999"
	short_desc="Table or Tree library from util-linux - development files"
	pkg_install() {
		vmove usr/lib/libsmartcols.a
		vmove usr/lib/libsmartcols.so
		vmove usr/include/libsmartcols
		vmove usr/lib/pkgconfig/smartcols*
	}
}

libsmartcols_package() {
	short_desc="Table or Tree library from util-linux"
	depends="${sourcepkg}>=${version}_1"
	pkg_install() {
		vmove usr/lib/libsmartcols.so.*
	}
}

liblastlog2-devel_package() {
	depends="libsmartcols>=${version}_${revision}<=${version}_9999"
	short_desc+="Lastlog replacement library from util-linux - development files"
	pkg_install() {
		vmove usr/share/man/man3/lastlog2*
		vmove usr/share/man/man3/ll2*
		vmove usr/include/liblastlog2
		vmove usr/lib/pkgconfig/lastlog2*
		vmove usr/lib/liblastlog2.a
		vmove usr/lib/liblastlog2.so
	}
}

liblastlog2_package() {
	short_desc="Lastlog replacement library from util-linux"
	depends="${sourcepkg}>=${version}_1"
	pkg_install() {
		vmove usr/lib/liblastlog2.so.*
	}
}
