summaryrefslogtreecommitdiff
blob: 75bd9bda8186b017e840f11f61f2ae6586ed6983 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Copyright 1999-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit readme.gentoo-r1 secureboot

BINPKG="${P/-bin/}-1"
ARCHES="amd64 arm64"

DESCRIPTION="TianoCore EDK II UEFI firmware for virtual machines"
HOMEPAGE="https://github.com/tianocore/edk2"
SRC_URI=$(printf "https://dev.gentoo.org/~chewi/distfiles/${BINPKG}-%s.xpak\n" ${ARCHES})
S="${WORKDIR}"
LICENSE="BSD-2 MIT"
SLOT="0"
KEYWORDS="~amd64 ~arm64 ~loong ~ppc ~ppc64 ~riscv ~x86"

RDEPEND="!sys-firmware/edk2"

DOC_CONTENTS="This package includes the TianoCore EDK II UEFI firmware for virtual \
machines of these architectures: ${ARCHES}. See each architecture's README for \
usage details."

src_unpack() {
	local a
	for a in ${ARCHES}; do
		mkdir "${a}" || die
		tar -C "${a}" -xf - < <(xz -c -d --single-stream "${DISTDIR}/${BINPKG}-${a}.xpak") ||
			die "unpacking ${a} binpkg failed"
	done
}

src_prepare() {
	bunzip2 */usr/share/doc/*/README.gentoo.bz2 || die
	default
}

src_install() {
	insinto /usr/share
	doins -r */usr/share/{edk2,qemu}/

	# Compatibility with older package versions.
	dosym edk2/OvmfX64 /usr/share/edk2-ovmf

	secureboot_auto_sign --in-place
	readme.gentoo_create_doc

	local a
	for a in ${ARCHES}; do
		newdoc "${a}"/usr/share/doc/*/README.gentoo README-"${a}".gentoo
	done
}

pkg_preinst() {
	local OLD=${EROOT}/usr/share/edk2-ovmf NEW=${EROOT}/usr/share/edk2/OvmfX64
	if [[ -d ${OLD} && ! -L ${OLD} ]]; then
		{
			rm -vf "${OLD}"/{OVMF_{CODE,CODE.secboot,VARS}.fd,EnrollDefaultKeys.efi,Shell.efi,UefiShell.img} &&
			mkdir -p "${NEW}" &&
			find "${OLD}" -mindepth 1 -maxdepth 1 -execdir mv --update=none-fail -vt "${NEW}"/ {} + &&
			rmdir "${OLD}"
		} || die "unable to replace old directory with compatibility symlink"
	fi
}

pkg_postinst() {
	readme.gentoo_print_elog
}