# Template file for 'tinyramfs'
pkgname=tinyramfs
version=0.3.0
revision=2
build_style=gnu-makefile
depends="util-linux cpio kmod"
short_desc="Tiny initramfs written in POSIX shell"
maintainer="dkwo <npiazza@disroot.org>"
license="GPL-3.0-only"
homepage="https://github.com/illiliti/tinyramfs"
distfiles="https://github.com/illiliti/tinyramfs/archive/refs/tags/${version}.tar.gz"
checksum=e4d4780d48c97e5b86235327c9867685d1f63d1babe6ee30e3e05d9f94b31786
alternatives="
 initramfs:/etc/kernel.d/post-install/20-initramfs:/usr/libexec/tinyramfs/kernel-hook-postinst
 initramfs:/etc/kernel.d/post-remove/20-initramfs:/usr/libexec/tinyramfs/kernel-hook-postrm
"
make_check=no # checking requires qemu, locally this still fails
conf_files="/etc/tinyramfs/config"

case "${XBPS_TARGET_MACHINE}" in
	i686*|x86_64*|aarch64*)
		subpackages+=" tinyramfs-uefi"
	;;
esac

post_install() {
	vinstall ${FILESDIR}/kernel-hook-postinst 755 usr/libexec/tinyramfs
	vinstall ${FILESDIR}/kernel-hook-postrm 755 usr/libexec/tinyramfs
	vinstall ${FILESDIR}/config 644 etc/tinyramfs
}

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

	pkg_install() {
		vinstall ${FILESDIR}/kernel-uefi-hook-postinst 755 usr/libexec/tinyramfs uefi-hook-postinst
		vinstall ${FILESDIR}/kernel-uefi-hook-postrm 755 usr/libexec/tinyramfs uefi-hook-postrm
	}
}
