Diff udk-2015-r1 with a udk-2018-r1

/usr/portage/sys-boot/udk/udk-2018-r1.ebuild 2020-04-30 15:09:00.000000000 +0300
6 6
PYTHON_COMPAT=( python2_7 )
7 7
PYTHON_REQ_USE="sqlite"
8 8

  
9
inherit flag-o-matic multiprocessing python-single-r1 toolchain-funcs
10

  
11
MY_V="${PN^^}${PV}"
9
inherit multiprocessing python-single-r1 toolchain-funcs
12 10

  
13 11
DESCRIPTION="Tianocore UEFI Development kit"
14
HOMEPAGE=" https://github.com/tianocore/tianocore.github.io/wiki/EDK-II"
15
SRC_URI="https://github.com/tianocore/${PN}/releases/download/${MY_V}/${MY_V}.Complete.MyWorkSpace.zip"
12
HOMEPAGE="https://github.com/tianocore/tianocore.github.io/wiki/EDK-II"
13

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

  
17
LICENSE="BSD"
26
LICENSE="BSD-2"
18 27
SLOT="0"
19
KEYWORDS="~amd64 ~x86"
20
IUSE="doc examples"
28
IUSE="doc"
21 29
REQUIRED_USE="${PYTHON_REQUIRED_USE}"
22 30
RESTRICT="strip"
23 31

  
24 32
RDEPEND="${PYTHON_DEPS}"
25 33
DEPEND="${RDEPEND}
26
	app-arch/unzip
27
	dev-lang/nasm"
28

  
29
S="${WORKDIR}/MyWorkSpace"
30

  
31
# Generated libs for EFI can contain WX sections
32
QA_EXECSTACK="usr/lib*/libBaseLib.a:*"
34
	>=dev-lang/nasm-2.14.02
35
	>=sys-power/iasl-20160729
36
	doc? ( app-arch/unzip )"
37

  
38
DOCDIR="${WORKDIR}/Documents"
39

  
40
# EFI pre-build libs
41
QA_PREBUILT="
42
	usr/lib/${P}/BeagleBoardPkg/Debugger_scripts/rvi_dummy.axf
43
	usr/lib/${P}/ArmPkg/Library/GccLto/*.a
44
"
45
# GenBiosId is built upstream
46
# VfrCompile does not use LDFLAGS but next upsteam version should change this
47
QA_FLAGS_IGNORED="
48
	usr/lib/udk-2018/BaseTools/Source/C/bin/VfrCompile
49
	usr/lib/${P}/Vlv2TbltDevicePkg/GenBiosId
50
"
33 51

  
34 52
pkg_setup() {
35
	python_setup 'python2.7'
36

  
37
	if [[ ${ARCH} == "amd64" ]]; then
38
		ARCH=X64
39
	elif [[ ${ARCH} == "x86" ]]; then
40
		ARCH=IA32
53
	if use x86; then
54
		EFIARCH=IA32
55
	elif use amd64; then
56
		EFIARCH=X64
41 57
	fi
42 58

  
43
	# We will create a custom toolchain with user defined settings
44
	TOOLCHAIN_TAG="CUSTOM"
59
	# Select toolchain within predefined ones
60
	if tc-is-gcc; then
61
		TOOLCHAIN_TAG="GCC5"
62
	elif tc-is-clang; then
63
		TOOLCHAIN_TAG="CLANG38"
64
	else
65
		TOOLCHAIN_TAG="ELFGCC"
66
	fi
45 67
}
46 68

  
47 69
src_unpack() {
48
	unpack ${A}
49
	unpack "${WORKDIR}/${MY_V}.MyWorkSpace.zip"
50

  
51
	pushd "${S}" || die
52
	unpack "${WORKDIR}/BaseTools(Unix).tar"
70
	default
53 71

  
54 72
	local doc_name
55 73
	local f
56 74
	if use doc; then
57
		mkdir -p "${S}/doc" || die
58
		pushd "${S}/doc" >/dev/null || die
59
		for f in "${WORKDIR}/Documents/"*" Document.zip"; do
60
			doc_name=${f##*/}
61
			doc_name=${doc_name% Document.zip}
62
			if [[ -f "${WORKDIR}/Documents/${doc_name} Document.zip" ]]; then
63
				unpack "${WORKDIR}/Documents/${doc_name} Document.zip"
64
				mv "html" "${doc_name}" || die
65
			fi
75
		pushd "${DOCDIR}" >/dev/null || die
76
		rm -f *.chm || die
77
		for f in *.zip; do
78
			unpack "${DOCDIR}/${f}"
79
			mv html "${f%.zip}" || die
66 80
		done
81
		rm -f *.zip || die
67 82
		popd >/dev/null || die
68 83
	fi
69

  
70
	popd >/dev/null || die
71 84
}
72 85

  
73 86
src_configure() {
74
	# Patch source file for permissive error (issue #639080)
75
	sed -e "s/\(mStringFileName == \)'\\\\0'/\1NULL/" \
76
		-i "${S}/BaseTools/Source/C/VfrCompile/VfrUtilityLib.cpp" \
77
		|| die "Failed to patch source file"
78
	sed -e "s/\((StringPtr != \)L'\\\\0'/\1NULL/" \
79
		-i "${S}/MdeModulePkg/Library/UefiHiiLib/HiiLib.c" \
80
		|| die "Failed to patch source file"
81
	# Compile of Base Tools is required for further setting up the environment
82
	# Base tools does not like parallel make
83
	sed -e "s|^\(CFLAGS\s*=\).*$|\1 ${CFLAGS} -MD -fshort-wchar -fno-strict-aliasing -nostdlib -c -fPIC|" \
84
		-i "${S}/BaseTools/Source/C/Makefiles/header.makefile" \
87
	sed -e "s|^\(BUILD_CFLAGS\s*=\).*$|\1 ${CFLAGS} -MD -fshort-wchar -fno-strict-aliasing -nostdlib -c -fPIC|" \
88
		-e "s|^\(BUILD_LFLAGS\s*=\).*$|\1 ${LDFLAGS}|" \
89
		-e "s|^\(BUILD_CXXFLAGS\s*=\).*$|\1 ${CXXFLAGS} -Wno-unused-result|" \
90
		-i "BaseTools/Source/C/Makefiles/header.makefile" \
85 91
		|| die "Failed to update makefile header"
92
}
93

  
94
src_compile() {
86 95
	local make_flags=(
87
		CC="$(tc-getCC)"
88
		CXX="$(tc-getCXX)"
89
		AS="$(tc-getAS)"
90
		AR="$(tc-getAR)"
91
		LD="$(tc-getLD)"
96
		BUILD_CC="$(tc-getBUILD_CC)"
97
		BUILD_CXX="$(tc-getBUILD_CXX)"
98
		BUILD_AS="$(tc-getBUILD_AS)"
99
		BUILD_AR="$(tc-getBUILD_AR)"
100
		BUILD_LD="$(tc-getBUILD_LD)"
92 101
	)
102
	# Base tools does not like parallel make
93 103
	emake "${make_flags[@]}" -j1 -C BaseTools
94
	. edksetup.sh BaseTools
95 104

  
96
	# Update flags in UDK parameter files
97
	append-cflags -fshort-wchar -fno-strict-aliasing -c
98
	append-cflags $(test-flags-CC -ffunction-sections)
99
	append-cflags $(test-flags-CC -fdata-sections)
100
	append-cflags $(test-flags-CC -fno-stack-protector)
101
	append-cflags $(test-flags-CC -fno-asynchronous-unwind-tables)
102
	if [[ "${ARCH}" == "X64" ]]; then
103
		append-cflags $(test-flags-CC -m64) $(test-flags-CC -mno-red-zone)
104
		append-cflags $(test-flags-CC -mcmodel=large)
105
	else
106
		append-cflags $(test-flags-CC -m32) $(test-flags-CC -malign-double)
107
	fi
105
	# Update template parameter files
108 106
	sed -e "s|^\(ACTIVE_PLATFORM\s*=\).*$|\1 MdeModulePkg/MdeModulePkg.dsc|" \
109 107
		-e "s|^\(TARGET\s*=\).*$|\1 RELEASE|" \
110
		-e "s|^\(TARGET_ARCH\s*=\).*$|\1 ${ARCH}|" \
108
		-e "s|^\(TARGET_ARCH\s*=\).*$|\1 ${EFIARCH}|" \
111 109
		-e "s|^\(TOOL_CHAIN_TAG\s*=\).*$|\1 ${TOOLCHAIN_TAG}|" \
112 110
		-e "s|^\(MAX_CONCURRENT_THREAD_NUMBER\s*=\).*$|\1 $(makeopts_jobs)|" \
113
		-i "${S}/Conf/target.txt" || die "Failed to configure target file"
114
	sed -e "s|«CC»|$(tc-getCC)|" \
115
		-e "s|«AR»|$(tc-getAR)|" \
116
		-e "s|«LD»|$(tc-getLD)|" \
117
		-e "s|«OBJCOPY»|$(tc-getOBJCOPY)|" \
118
		-e "s|«CFLAGS»|${CFLAGS}|" \
119
		"${FILESDIR}/${PV}-tools_def.template" >>"${S}/Conf/tools_def.txt" \
120
		|| die "Failed to prepare tools definition file"
121
}
111
		-i "BaseTools/Conf/target.template" || die "Failed to configure target file"
122 112

  
123
src_compile() {
124
	if use examples; then
125
		ewarn "Examples installation does not work anymore"
126
		ewarn "Try with a most recent version of the package"
127
	fi
128

  
129
	build libraries || die "Failed to compile environment"
113
	# Clean unneeded files
114
	find . -name '*.bat' -o -name '*.exe' -exec rm -f {} \; || die
115
	find ./BaseTools/Source/C -mindepth 1 -maxdepth 1 \! -name 'bin' -exec rm -rf {} \; || die
116

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

  
120
	# Create workspace script file
121
	sed -e "s|{EDK_BASE}|${EPREFIX}/usr/lib/${P}|" \
122
		"${FILESDIR}"/udk-workspace.template \
123
		> "${T}/udk-workspace" || die "Failed to build udk-workspace"
130 124
}
131 125

  
132 126
src_install() {
133
	local f
134
	local build_dir="${S}/Build/MdeModule/RELEASE_${TOOLCHAIN_TAG}/${ARCH}"
135

  
136
	for f in "${build_dir}"/*/Library/*/*/OUTPUT/*.lib; do
137
		local fn="lib${f##*/}"
138
		newlib.a "${f}" "${fn%.lib}.a"
139
	done
140
	dolib.a "${S}/BaseTools/Scripts/GccBase.lds"
141

  
142
	insinto "/usr/include/${PN}"
143
	doins "${S}/MdePkg/Include/"*.h
144
	doins -r "${S}/MdePkg/Include/"{${ARCH}/.,Guid,IndustryStandard,Library,Pi,Ppi,Protocol,Uefi}
145
	local hfile
146
	while read -d '' -r hfile; do
147
		doins -r "${hfile}/."
148
	done < <(find "${S}" -name 'BaseTools' -prune -o -name 'MdePkg' -prune -o \
149
		-name 'CryptoPkg' -prune -o -type d -name Include -print0)
150

  
151
	dobin "${S}/BaseTools/Source/C/bin/GenFw"
152

  
153
	if use doc; then
154
		docinto "html"
155
		# Document installation may be very long, so split it and display message
156
		for f in "${S}"/doc/*; do
157
			ebegin "Install documentation for ${f##*/}"
158
			dodoc -r "${f}"
159
			eend $?
160
		done
161
	fi
162
}
127
	dobin "${T}/udk-workspace"
163 128

  
164
##
165
# Parameters:
166
# 1 - Path where to search for source files.
167
# 2 - Path where source files must be copied.
168
copySourceFiles() {
169
	local dest_file
170
	while read -d '' -r filename; do
171
		dest_file="${2}${filename#${1}}"
172
		mkdir -p "${dest_file%/*}" || die
173
		mv "${filename}" "${dest_file}" || die
174
	done < <(find "${1}" -name '*.h' -print0 -o -name '*.c' -print0)
175
}
176

  
177
##
178
# Parameters:
179
# 1 - Path of the file to create.
180
# 2 - Name of the module.
181
# 3 - Path of the generated Makefile.
182
createMakefile() {
183
	local static_libs=$(sed -n '/^STATIC_LIBRARY_FILES\s*=/,/^\s*\$(OUTPUT_DIR)/{/^\s*\$(OUTPUT_DIR)/b;p}' ${3} \
184
		| sed -e 's|^\s*\$(BIN_DIR).*/\([^/]*\)\.lib|\t-l\1|' -e 's|\\$|\\\\\\n|' | tr --delete '\n')
185
	local pecoff_header_size;
186
	[[ $ARCH == X64 ]] && pecoff_header_size='0x228' || pecoff_header_size='0x220'
187
	sed -e "s|«MODULE»|${2}|" \
188
		-e "s|«PACKAGE_NAME»|${PN}|" \
189
		-e "s|«STATIC_LIBS»|${static_libs}|" \
190
		-e "s|«MODULE_TYPE»|$(grep -e '^MODULE_TYPE\s*=' ${3} | tail -1)|" \
191
		-e "s|«IMAGE_ENTRY_POINT»|$(grep -e '^IMAGE_ENTRY_POINT\s*=' ${3})|" \
192
		-e "s|«CP»|$(grep -e '^CP\s*=' ${3})|" \
193
		-e "s|«RM»|$(grep -e '^RM\s*=' ${3})|" \
194
		-e "s|«CC»|$(grep -e '^CC\s*=' ${3})|" \
195
		-e "s|«DLINK»|$(grep -e '^DLINK\s*=' ${3})|" \
196
		-e "s|«OBJCOPY»|$(grep -e '^OBJCOPY\s*=' ${3})|" \
197
		-e "s|«GENFW»|$(grep -e '^GENFW\s*=' ${3})|" \
198
		-e "s|«PECOFF_HEADER_SIZE»|${pecoff_header_size}|" \
199
		-e "s|«OBJCOPY_FLAGS»|$(grep -e '^OBJCOPY_FLAGS\s*=' ${3})|" \
200
		-e "s|«GENFW_FLAGS»|$(grep -e '^GENFW_FLAGS\s*=' ${3})|" \
201
		"${FILESDIR}/${PV}-makefile.template" >${1} \
202
		|| die "Failed to create Makefile"
129
	# Use mkdir && cp here as doins does not preserve execution bits
130
	mkdir -p "${ED}/usr/lib/${P}" || die
131
	cp -pR "${S}"/* "${D}/usr/lib/${P}" || die
132
	dosym "${P}" "/usr/lib/${PN}"
133

  
134
	local HTML_DOCS
135
	use doc && HTML_DOCS=( "${DOCDIR}"/. )
136
	einstalldocs
137
}
138

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