summaryrefslogtreecommitdiff
blob: 89f40f3e1a5c92db1ff33b5339b0212915bcc970 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Copyright 1999-2019 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

EAPI=7

PYTHON_COMPAT=( python2_7 )
PYTHON_REQ_USE="sqlite"

inherit multiprocessing python-single-r1 toolchain-funcs

DESCRIPTION="Tianocore UEFI Development kit"
HOMEPAGE="https://github.com/tianocore/tianocore.github.io/wiki/EDK-II"

if [[ ${PV} == *9999* ]]; then
	inherit git-r3
	EGIT_REPO_URI="https://github.com/tianocore/edk2.git"
	KEYWORDS=""
else
	MY_V="${PN^^}${PV}"
	SRC_URI="https://github.com/tianocore/edk2/archive/v${MY_V}.tar.gz -> ${P}.tar.gz
		doc? ( https://github.com/tianocore/edk2/releases/download/v${MY_V}/${MY_V}.Documents.zip -> ${P}-docs.zip )"
	S="${WORKDIR}/edk2-v${MY_V}"
	KEYWORDS="~amd64 ~x86"
fi

LICENSE="BSD-2"
SLOT="0"
IUSE="doc"
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
RESTRICT="strip"

RDEPEND="${PYTHON_DEPS}"
DEPEND="${RDEPEND}
	>=dev-lang/nasm-2.14.02
	>=sys-power/iasl-20160729
	doc? ( app-arch/unzip )"

DOCDIR="${WORKDIR}/Documents"

# EFI pre-build libs
QA_PREBUILT="
	usr/lib/${P}/BeagleBoardPkg/Debugger_scripts/rvi_dummy.axf
	usr/lib/${P}/ArmPkg/Library/GccLto/*.a
"
# GenBiosId is built upstream
# VfrCompile does not use LDFLAGS but next upsteam version should change this
QA_FLAGS_IGNORED="
	usr/lib/udk-2018/BaseTools/Source/C/bin/VfrCompile
	usr/lib/${P}/Vlv2TbltDevicePkg/GenBiosId
"

pkg_setup() {
	if use x86; then
		EFIARCH=IA32
	elif use amd64; then
		EFIARCH=X64
	fi

	# Select toolchain within predefined ones
	if tc-is-gcc; then
		TOOLCHAIN_TAG="GCC5"
	elif tc-is-clang; then
		TOOLCHAIN_TAG="CLANG38"
	else
		TOOLCHAIN_TAG="ELFGCC"
	fi
}

src_unpack() {
	default

	local doc_name
	local f
	if use doc; then
		pushd "${DOCDIR}" >/dev/null || die
		rm -f *.chm || die
		for f in *.zip; do
			unpack "${DOCDIR}/${f}"
			mv html "${f%.zip}" || die
		done
		rm -f *.zip || die
		popd >/dev/null || die
	fi
}

src_configure() {
	sed -e "s:^\(BUILD_CFLAGS\s*=\).*$:\1 ${CFLAGS} -MD -fshort-wchar -fno-strict-aliasing -nostdlib -c -fPIC:" \
		-e "s:^\(BUILD_LFLAGS\s*=\).*$:\1 ${LDFLAGS}:" \
		-e "s:^\(BUILD_CXXFLAGS\s*=\).*$:\1 ${CXXFLAGS} -Wno-unused-result:" \
		-i "BaseTools/Source/C/Makefiles/header.makefile" \
		|| die "Failed to update makefile header"
}

src_compile() {
	local make_flags=(
		BUILD_CC="$(tc-getBUILD_CC)"
		BUILD_CXX="$(tc-getBUILD_CXX)"
		BUILD_AS="$(tc-getBUILD_AS)"
		BUILD_AR="$(tc-getBUILD_AR)"
		BUILD_LD="$(tc-getBUILD_LD)"
	)
	# Base tools does not like parallel make
	emake "${make_flags[@]}" -j1 -C BaseTools

	# Update template parameter files
	sed -e "s:^\(ACTIVE_PLATFORM\s*=\).*$:\1 MdeModulePkg/MdeModulePkg.dsc:" \
		-e "s:^\(TARGET\s*=\).*$:\1 RELEASE:" \
		-e "s:^\(TARGET_ARCH\s*=\).*$:\1 ${EFIARCH}:" \
		-e "s:^\(TOOL_CHAIN_TAG\s*=\).*$:\1 ${TOOLCHAIN_TAG}:" \
		-e "s:^\(MAX_CONCURRENT_THREAD_NUMBER\s*=\).*$:\1 $(makeopts_jobs):" \
		-i "BaseTools/Conf/target.template" || die "Failed to configure target file"

	# Clean unneeded files
	find . -name '*.bat' -o -name '*.exe' -exec rm -f {} \; || die
	find ./BaseTools/Source/C -mindepth 1 -maxdepth 1 \! -name 'bin' -exec rm -rf {} \; || die

	# Upsteam hack (symbolic link) should only be created if needed
	rm "${S}/EmulatorPkg/Unix/Host/X11IncludeHack" || die

	# Create workspace script file
	sed -e "s:{EDK_BASE}:${EPREFIX}/usr/lib/${P}:" \
		"${FILESDIR}"/udk-workspace.template \
		> "${T}/udk-workspace" || die "Failed to build udk-workspace"
}

src_install() {
	dobin "${T}/udk-workspace"

	# Use mkdir && cp here as doins does not preserve execution bits
	mkdir -p "${ED}/usr/lib/${P}" || die
	cp -pR "${S}"/* "${D}/usr/lib/${P}" || die
	dosym "${P}" "/usr/lib/${PN}"

	local HTML_DOCS
	use doc && HTML_DOCS=( "${DOCDIR}"/. )
	einstalldocs
}

pkg_postinst() {
	elog "To create a new workspace, execute:"
	elog "    . udk-workspace [workspace_dir]"
	elog "You can link appropriate packages to your workspace. For example,"
	elog "in order to build MdeModulePkg and examples, you can try:"
	elog "    ln -s \"${EROOT}/usr/lib/${P}/\"Mde{Module,}Pkg ."
	elog "    build -a ${EFIARCH} all"
}