# Template file for 'dracut'
pkgname=dracut
version=109
revision=1
build_style=configure
configure_args="--prefix=/usr --sysconfdir=/etc"
conf_files="/etc/dracut.conf"
hostmakedepends="pkg-config ruby-asciidoctor"
makedepends="libkmod-devel"
depends="bash coreutils cpio eudev gzip kmod>=3.7 kpartx util-linux"
short_desc="Low-level tool for generating an initramfs/initrd image"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2.0-or-later, LGPL-2.0-or-later"
homepage="https://github.com/dracut-ng/dracut-ng/wiki"
changelog="https://raw.githubusercontent.com/dracut-ng/dracut-ng/master/NEWS.md"
distfiles="https://github.com/dracut-ng/dracut-ng/archive/refs/tags/${version}.tar.gz"
checksum=6f5b84c6db4381c5bca59c38b18613037c6aafd1aff8cadea22bb83fb8850bcf
alternatives="
 initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/dracut/kernel-hook-postinst
 initramfs:/etc/kernel.d/post-remove/20-initramfs:/usr/libexec/dracut/kernel-hook-postrm
"
subpackages="dracut-network"
# Checks require distfiles come from a git repository
make_check=no

make_dirs="
 /etc/dracut.conf.d 0755 root root
 /usr/lib/dracut/dracut.conf.d 0755 root root"

if [ "$XBPS_TARGET_LIBC" = "musl" ]; then
	makedepends+=" musl-fts-devel"
fi

case "$XBPS_TARGET_MACHINE" in
	i686*|x86_64*|aarch64*) # archs supported by dracut for EFI bundle
		subpackages+=" dracut-uefi"
	;;
esac

post_install() {
	# kernel hooks.
	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/dracut
	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/dracut

	rm ${DESTDIR}/usr/share/man/man8/*.service.*
	rm -r ${DESTDIR}/usr/lib/kernel

}

dracut-network_package() {
	depends="dhclient ${sourcepkg}-${version}_${revision}"
	short_desc+=" - network modules"
	pkg_install() {
		for f in 35network-legacy 40network 45url-lib \
			70kernel-network-modules 70qemu-net 70livenet \
			74cifs 74fcoe 74fcoe-uefi 74iscsi 74nbd 74nfs 74nvmf 74ssh-client; do
			vmove usr/lib/dracut/modules.d/${f}
		done
	}
}

dracut-uefi_package() {
	depends="binutils systemd-boot-efistub ${sourcepkg}>=${version}_${revision}"
	short_desc+=" - UEFI bundle hook"
	conf_files="/etc/default/dracut-uefi-hook"
	alternatives="
	 initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/dracut/uefi-hook-postinst
	 initramfs:/etc/kernel.d/post-remove/20-initramfs:/usr/libexec/dracut/uefi-hook-postrm
	"

	pkg_install() {
		vinstall ${FILESDIR}/dracut-uefi-hook.confd 644 etc/default dracut-uefi-hook
		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/dracut uefi-hook-postinst
		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/dracut uefi-hook-postrm
	}
}
