# Template file for 'systemd-boot'
pkgname=systemd-boot
version=256.6
revision=2
build_style=meson
conf_files="/etc/default/systemd-boot"
configure_args="-Defi=true -Dman=enabled -Dbootloader=enabled
 -Dsbat-distro=void -Dsbat-distro-summary=Void -Dsbat-distro-pkgname=${pkgname}
 -Dsbat-distro-version="${version}_${revision}"
 -Dsbat-distro-url=https://github.com/void-linux/void-packages/issues

 -Dacl=disabled -Dkmod=disabled -Dselinux=disabled -Dsysusers=false -Dtmpfiles=false
 -Dadm-group=false -Danalyze=false -Dapparmor=disabled -Daudit=disabled
 -Dbacklight=false -Dbinfmt=false -Dbpf-framework=disabled -Dbzip2=disabled
 -Dcoredump=false -Ddbus=disabled -Delfutils=disabled -Denvironment-d=false
 -Dfdisk=disabled -Dgcrypt=disabled -Dglib=disabled -Dgshadow=false -Dgnutls=disabled
 -Dhibernate=false -Dhostnamed=false -Didn=false -Dima=false -Dinitrd=false
 -Dfirstboot=false -Dldconfig=false -Dlibcryptsetup=disabled -Dlibcurl=disabled
 -Dlibfido2=disabled -Dlibidn=disabled -Dlibidn2=disabled -Dlibiptc=disabled -Dlocaled=false
 -Dlogind=false -Dlz4=disabled -Dmachined=false -Dmicrohttpd=disabled -Dnetworkd=false
 -Dnscd=false -Dnss-myhostname=false -Dnss-resolve=disabled -Dnss-systemd=false
 -Doomd=false -Dopenssl=disabled -Dp11kit=disabled -Dpam=disabled -Dpcre2=disabled
 -Dpolkit=disabled -Dportabled=false -Dpstore=false -Dpwquality=disabled
 -Drandomseed=false -Dresolve=false -Drfkill=false -Dseccomp=disabled -Dsmack=false
 -Dsysext=false -Dtimedated=false -Dtimesyncd=false -Dtpm=false -Dqrencode=disabled
 -Dquotacheck=false -Duserdb=false -Dutmp=false -Dvconsole=false -Dwheel-group=false
 -Dxdg-autostart=false -Dxkbcommon=disabled -Dxz=disabled -Dzlib=disabled -Dzstd=disabled
 -Dtests=false -Dkernel-install=false -Dlink-boot-shared=false -Dstandalone-binaries=true"
# most of these aren't needed for what we're building but it's easier than patching
hostmakedepends="pkg-config gperf python3-Jinja2 python3-pyelftools libxslt docbook-xsl"
makedepends="libcap-devel libmount-devel"
depends="systemd-boot-efistub>=${version}_${revision} ukify>=${version}_${revision}"
short_desc="Simple UEFI boot manager from systemd"
maintainer="Daniel Martinez <danielmartinez@cock.li>"
license="LGPL-2.1-or-later"
homepage="https://www.freedesktop.org/wiki/Software/systemd/systemd-boot/"
distfiles="https://github.com/systemd/systemd/archive/refs/tags/v${version}.tar.gz"
checksum=c085f162dec001407dd32f00abbf20b7e6ed7043dcfaf8ed954787d86707f409
make_check=no  # tests a bunch of stuff we aren't using

if [ "${XBPS_TARGET_LIBC}" = glibc ]; then
	makedepends+=" libxcrypt-devel"
else
	# see src/basic/linux/if_ether.h
	export CFLAGS="-D__UAPI_DEF_ETHHDR=0 -Wno-error=incompatible-pointer-types"
fi

case "${XBPS_TARGET_MACHINE}" in
	x86_64*)  _efi_arch="x64"     ;;
	i686*)    _efi_arch="ia32"    ;;
	aarch64*) _efi_arch="aa64"    ;;
	arm*)     _efi_arch="arm"     ;;
	riscv64*) _efi_arch="riscv64" ;;
	*) broken="unknown efi architecture" ;;
esac

_bins=(ukify bootctl)
_mans=(man/ukify.1 man/systemd-stub.7
 man/sd-boot.7 man/systemd-boot.7 man/bootctl.1)
_efis=("src/boot/efi/linux${_efi_arch}.efi.stub"
 "src/boot/efi/systemd-boot${_efi_arch}.efi")
_libexecs=(systemd-bless-boot)
make_build_target="${_bins[*]} ${_mans[*]} ${_efis[*]} ${_libexecs[*]}"

post_patch() {
	if [ "${XBPS_TARGET_LIBC}" = musl ]; then
		for x in ${FILESDIR}/patches/musl/*.patch; do
			msg_normal "Applying patch $x\n"
			patch -sNp1 -i ${x}
		done
	fi
}

do_install() {
	for b in "${_bins[@]}"; do
		vbin "build/$b"
	done

	for m in build/man/*.[0-9]; do
		vman "$m"
	done

	for e in "${_efis[@]}"; do
		vinstall "build/$e" 644 usr/lib/systemd/boot/efi
	done

	for l in "${_libexecs[@]}"; do
		vinstall "build/$l" 644 usr/lib/systemd
	done

	vinstall ${FILESDIR}/kernel.d/systemd-boot.post-install 744 \
		etc/kernel.d/post-install 50-systemd-boot
	vinstall ${FILESDIR}/kernel.d/systemd-boot.post-remove 744 \
		etc/kernel.d/post-remove 50-systemd-boot
	vinstall ${FILESDIR}/kernel.d/systemd-boot.conf 644 \
		etc/default systemd-boot
}

ukify_package() {
	short_desc="Unified Kernel Image creation tool from systemd-boot"
	depends="python3-pefile"
	pkg_install() {
		vmove usr/bin/ukify
		vmove usr/share/man/man1/ukify.1
	}
}

systemd-boot-efistub_package() {
	short_desc="UEFI stub loader from systemd-boot"
	pkg_install() {
		vmove "usr/lib/systemd/boot/efi/linux*.efi.stub"
		vmove "usr/share/man/man7/linux*.efi.*"
		vmove usr/share/man/man7/sd-stub.7
		vmove usr/share/man/man7/systemd-stub.7
	}
}

gummiboot_package() {
	short_desc="Simple UEFI Boot Manager (transitional dummy package)"
	depends="systemd-boot"
	build_style=meta
}

gummiboot-efistub_package() {
	short_desc="Linux UEFI stub from the gummiboot project (transitional dummy package)"
	depends="systemd-boot-efistub"
	build_style=meta
}
