Line 0
Link Here
|
0 |
- |
1 |
# Copyright 1999-2016 Gentoo Foundation |
|
|
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
# $Id$ |
4 |
|
5 |
EAPI=6 |
6 |
|
7 |
PYTHON_COMPAT=( python2_7 ) |
8 |
PYTHON_REQ_USE="sqlite" |
9 |
|
10 |
inherit flag-o-matic multiprocessing python-single-r1 toolchain-funcs versionator |
11 |
|
12 |
DESCRIPTION="Tianocore UEFI Development kit" |
13 |
HOMEPAGE="http://www.tianocore.org/edk2/" |
14 |
MY_V="${PN^^}$(get_version_component_range 1)" |
15 |
SRC_URI="https://github.com/tianocore/${PN}/releases/download/${MY_V}/${MY_V}.Complete.MyWorkSpace.zip" |
16 |
|
17 |
LICENSE="BSD" |
18 |
SLOT="0" |
19 |
KEYWORDS="~amd64 ~x86" |
20 |
IUSE="doc examples" |
21 |
|
22 |
DEPEND="app-arch/unzip |
23 |
dev-lang/nasm |
24 |
${PYTHON_DEPS}" |
25 |
REQUIRED_USE="${PYTHON_REQUIRED_USE}" |
26 |
|
27 |
S="${WORKDIR}/MyWorkSpace" |
28 |
|
29 |
pkg_setup() { |
30 |
UNAME_ARCH=$(uname -m | sed -e 's:i[3456789]86:IA32:') |
31 |
if [[ ${UNAME_ARCH} == "x86_64" ]] || [[ ${UNAME_ARCH} == "amd64" ]] ; then |
32 |
export ARCH=X64 |
33 |
else |
34 |
export ARCH=${UNAME_ARCH} |
35 |
fi |
36 |
|
37 |
# We will create a custom toolchain with user defined settings |
38 |
export TOOLCHAIN_TAG="CUSTOM" |
39 |
} |
40 |
|
41 |
src_unpack() { |
42 |
unpack ${A} |
43 |
unpack "${WORKDIR}/${MY_V}.MyWorkSpace.zip" |
44 |
|
45 |
pushd "${S}" || die |
46 |
unpack "${WORKDIR}/BaseTools(Unix).tar" |
47 |
|
48 |
local doc_name |
49 |
if use doc; then |
50 |
mkdir -p "${S}/doc" || die |
51 |
pushd "${S}/doc" >/dev/null || die |
52 |
for f in "${WORKDIR}/Documents/"*" Document.zip"; do |
53 |
doc_name=$(echo ${f} | sed -e 's:^.*/([^/]*) Document.zip$:\1:') |
54 |
if [[ -f "${WORKDIR}/Documents/${doc_name} Document.zip" ]]; then |
55 |
unpack "${WORKDIR}/Documents/${doc_name} Document.zip" |
56 |
mv "${S}/doc/html" "${S}/doc/${doc_name}" || die |
57 |
fi |
58 |
done |
59 |
popd >/dev/null || die |
60 |
fi |
61 |
|
62 |
popd >/dev/null || die |
63 |
} |
64 |
|
65 |
src_configure() { |
66 |
python_setup 'python2.7' |
67 |
|
68 |
# Compile of Base Tools is required for further setting up the environment |
69 |
# Base tools does not like parallel make |
70 |
local cflags_save=${CFLAGS} |
71 |
append-cflags $(test-flags-CC -MD) $(test-flags-CC -fshort-wchar) |
72 |
append-cflags $(test-flags-CC -fno-strict-aliasing) |
73 |
append-cflags $(test-flags-CC -nostdlib) $(test-flags-CC -c) |
74 |
sed -e "s:^\(CFLAGS\s*=\).*$:\1 ${CFLAGS}:" \ |
75 |
-i "${S}/BaseTools/Source/C/Makefiles/header.makefile" \ |
76 |
|| die "Failed to update makefile header" |
77 |
local make_flags=( |
78 |
CC="$(tc-getCC)" |
79 |
CXX="$(tc-getCXX)" |
80 |
AS="$(tc-getAS)" |
81 |
AR="$(tc-getAR)" |
82 |
LD="$(tc-getLD)" |
83 |
) |
84 |
emake "${make_flags[@]}" -j1 -C BaseTools |
85 |
. edksetup.sh BaseTools |
86 |
|
87 |
# Update flags in UDK parameter files |
88 |
CFLAGS=${cflags_save} |
89 |
append-cflags $(test-flags-CC -fshort-wchar) |
90 |
append-cflags $(test-flags-CC -fno-strict-aliasing) $(test-flags-CC -c) |
91 |
append-cflags $(test-flags-CC -ffunction-sections) |
92 |
append-cflags $(test-flags-CC -fdata-sections) |
93 |
append-cflags $(test-flags-CC -fno-stack-protector) |
94 |
append-cflags $(test-flags-CC -fno-asynchronous-unwind-tables) |
95 |
if [[ "${ARCH}" == "X64" ]]; then |
96 |
append-cflags $(test-flags-CC -m64) $(test-flags-CC -mno-red-zone) |
97 |
append-cflags $(test-flags-CC -mcmodel=large) |
98 |
else |
99 |
append-cflags $(test-flags-CC -m32) $(test-flags-CC -malign-double) |
100 |
fi |
101 |
append-ldflags -nostdlib -n -q --gc-sections |
102 |
sed -e "s:^\(ACTIVE_PLATFORM\s*=\).*$:\1 MdeModulePkg/MdeModulePkg.dsc:" \ |
103 |
-e "s:^\(TARGET\s*=\).*$:\1 RELEASE:" \ |
104 |
-e "s:^\(TARGET_ARCH\s*=\).*$:\1 ${ARCH}:" \ |
105 |
-e "s:^\(TOOL_CHAIN_TAG\s*=\).*$:\1 ${TOOLCHAIN_TAG}:" \ |
106 |
-e "s:^\(MAX_CONCURRENT_THREAD_NUMBER\s*=\).*$:\1 $(makeopts_jobs):" \ |
107 |
-i "${S}/Conf/target.txt" || die "Failed to configure target file" |
108 |
cat >>${S}/Conf/tools_def.txt <<EOF |
109 |
|
110 |
*_CUSTOM_*_*_FAMILY = GCC |
111 |
*_CUSTOM_*_MAKE_PATH = make |
112 |
*_CUSTOM_*_ASL_PATH = DEF(UNIX_IASL_BIN) |
113 |
*_CUSTOM_*_OBJCOPY_PATH = $(tc-getOBJCOPY) |
114 |
*_CUSTOM_*_CC_PATH = $(tc-getCC) |
115 |
*_CUSTOM_*_SLINK_PATH = $(tc-getAR) |
116 |
*_CUSTOM_*_DLINK_PATH = $(tc-getLD) |
117 |
*_CUSTOM_*_ASLDLINK_PATH = $(tc-getLD) |
118 |
*_CUSTOM_*_ASM_PATH = $(tc-getCC) |
119 |
*_CUSTOM_*_PP_PATH = $(tc-getCC) |
120 |
*_CUSTOM_*_VFRPP_PATH = $(tc-getCC) |
121 |
*_CUSTOM_*_ASLCC_PATH = $(tc-getCC) |
122 |
*_CUSTOM_*_ASLPP_PATH = $(tc-getCC) |
123 |
*_CUSTOM_*_RC_PATH = $(tc-getOBJCOPY) |
124 |
*_CUSTOM_*_PP_FLAGS = DEF(GCC_PP_FLAGS) |
125 |
*_CUSTOM_*_ASLPP_FLAGS = DEF(GCC_ASLPP_FLAGS) |
126 |
*_CUSTOM_*_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS) |
127 |
*_CUSTOM_*_VFRPP_FLAGS = DEF(GCC_VFRPP_FLAGS) |
128 |
*_CUSTOM_*_APP_FLAGS = |
129 |
*_CUSTOM_*_ASL_FLAGS = DEF(IASL_FLAGS) |
130 |
*_CUSTOM_*_ASL_OUTFLAGS = DEF(IASL_OUTFLAGS) |
131 |
*_CUSTOM_*_OBJCOPY_FLAGS = |
132 |
*_CUSTOM_IA32_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS) -m32 |
133 |
*_CUSTOM_IA32_ASM_FLAGS = DEF(GCC_ASM_FLAGS) -m32 -march=i386 |
134 |
*_CUSTOM_IA32_CC_FLAGS = ${CFLAGS} -include AutoGen.h -DSTRING_ARRAY_NAME=\$(BASE_NAME)Strings -D EFI32 |
135 |
*_CUSTOM_IA32_ASLDLINK_FLAGS = ${LDFLAGS} -z common-page-size=0x40 --entry ReferenceAcpiTable -u ReferenceAcpiTable -m elf_i386 |
136 |
*_CUSTOM_IA32_DLINK_FLAGS = ${LDFLAGS} -z common-page-size=0x40 --entry \$(IMAGE_ENTRY_POINT) -u \$(IMAGE_ENTRY_POINT) -Map \$(DEST_DIR_DEBUG)/\$(BASE_NAME).map -m elf_i386 --oformat=elf32-i386 |
137 |
*_CUSTOM_IA32_DLINK2_FLAGS = DEF(GCC_DLINK2_FLAGS_COMMON) --defsym=PECOFF_HEADER_SIZE=0x220 |
138 |
*_CUSTOM_IA32_RC_FLAGS = DEF(GCC_IA32_RC_FLAGS) |
139 |
*_CUSTOM_IA32_NASM_FLAGS = -f elf32 |
140 |
*_CUSTOM_X64_ASLCC_FLAGS = DEF(GCC_ASLCC_FLAGS) -m64 |
141 |
*_CUSTOM_X64_ASM_FLAGS = DEF(GCC_ASM_FLAGS) -m64 |
142 |
*_CUSTOM_X64_CC_FLAGS = ${CFLAGS} -include AutoGen.h -DSTRING_ARRAY_NAME=\$(BASE_NAME)Strings "-DEFIAPI=__attribute__((ms_abi))" -DNO_BUILTIN_VA_FUNCS |
143 |
*_CUSTOM_X64_ASLDLINK_FLAGS = ${LDFLAGS} -z common-page-size=0x40 --entry ReferenceAcpiTable -u ReferenceAcpiTable -m elf_x86_64 |
144 |
*_CUSTOM_X64_DLINK_FLAGS = ${LDFLAGS} -z common-page-size=0x40 --entry \$(IMAGE_ENTRY_POINT) -u \$(IMAGE_ENTRY_POINT) -Map \$(DEST_DIR_DEBUG)/\$(BASE_NAME).map -m elf_x86_64 --oformat=elf64-x86-64 |
145 |
*_CUSTOM_X64_DLINK2_FLAGS = DEF(GCC_DLINK2_FLAGS_COMMON) --defsym=PECOFF_HEADER_SIZE=0x228 |
146 |
*_CUSTOM_X64_RC_FLAGS = DEF(GCC_X64_RC_FLAGS) |
147 |
*_CUSTOM_X64_NASM_FLAGS = -f elf64 |
148 |
EOF |
149 |
} |
150 |
|
151 |
src_compile() { |
152 |
local build_target |
153 |
if use examples; then |
154 |
build_target=all |
155 |
else |
156 |
build_target=libraries |
157 |
fi |
158 |
|
159 |
build ${build_target} || die "Failed to compile environment" |
160 |
} |
161 |
|
162 |
src_install() { |
163 |
local build_dir="${S}/Build/MdeModule/RELEASE_${TOOLCHAIN_TAG}/${ARCH}" |
164 |
|
165 |
for f in "${build_dir}"/*/Library/*/*/OUTPUT/*.lib; do |
166 |
newlib.a "${f}" lib$(basename "${f}" .lib).a |
167 |
done |
168 |
dolib "${S}/BaseTools/Scripts/GccBase.lds" |
169 |
|
170 |
local include_dest="/usr/include/${PN}" |
171 |
for f in "" /Guid /IndustryStandard /Library /Pi /Ppi /Protocol /Uefi; do |
172 |
insinto "${include_dest}${f}" |
173 |
doins "${S}/MdePkg/Include${f}"/*.h |
174 |
done |
175 |
insinto "${include_dest}" |
176 |
doins "${S}/MdePkg/Include/${ARCH}"/*.h |
177 |
find "${S}" -name 'BaseTools' -prune -o -name 'MdePkg' -prune -o \ |
178 |
-name 'CryptoPkg' -prune -o -type d -name Include \ |
179 |
-exec find {} -maxdepth 0 \; \ |
180 |
| while read hfile; do |
181 |
doins -r "${hfile}"/* |
182 |
done |
183 |
|
184 |
dobin "${S}/BaseTools/Source/C/bin/GenFw" |
185 |
|
186 |
if use doc; then |
187 |
docinto "html" |
188 |
# Document installation may be very long, so split it and display message |
189 |
for f in "${S}"/doc/*; do |
190 |
ebegin "Installing documentation for $(basename ${f}), please wait" |
191 |
dodoc -r "${f}" |
192 |
eend $? |
193 |
done |
194 |
fi |
195 |
|
196 |
local ex_rebuild_dir |
197 |
local ex_name |
198 |
local ex_build_dir |
199 |
if use examples; then |
200 |
ex_rebuild_dir="${S}/${P}-exemples" |
201 |
for f in "${S}/MdeModulePkg/Application"/*; do |
202 |
ex_name=$(basename "${f}") |
203 |
ebegin "Preparing ${ex_name} example" |
204 |
mkdir -p "${ex_rebuild_dir}/${ex_name}" || die |
205 |
ex_build_dir="${build_dir}/MdeModulePkg/Application" |
206 |
ex_build_dir="${ex_build_dir}/${ex_name}/${ex_name}" |
207 |
|
208 |
copySourceFiles "${f}" "${ex_rebuild_dir}/${ex_name}" |
209 |
copySourceFiles "${ex_build_dir}/DEBUG" "${ex_rebuild_dir}/${ex_name}" |
210 |
createMakefile "${ex_rebuild_dir}/${ex_name}/Makefile" \ |
211 |
"${ex_name}" "${ex_build_dir}/GNUmakefile" || die |
212 |
|
213 |
tar -C "${ex_rebuild_dir}" -cf "${ex_rebuild_dir}/${ex_name}.tar" \ |
214 |
"${ex_name}" || die |
215 |
|
216 |
eend $? "Failed to create example file" |
217 |
done |
218 |
docinto "examples" |
219 |
dodoc "${ex_rebuild_dir}"/*.tar |
220 |
fi |
221 |
|
222 |
# TODO * QA Notice: The following files contain writable and executable sections |
223 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:Thunk16.obj |
224 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:SwitchStack.obj |
225 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:SetJump.obj |
226 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:LongJump.obj |
227 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:EnableDisableInterrupts.obj |
228 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:DisablePaging64.obj |
229 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:CpuId.obj |
230 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:CpuIdEx.obj |
231 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:EnableCache.obj |
232 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:DisableCache.obj |
233 |
# TODO * QA Notice: Package triggers severe warnings which indicate that it |
234 |
# TODO * may exhibit random runtime failures. |
235 |
# TODO * /usr/include/bits/string3.h:90:70: warning: call to void* __builtin___memset_chk(void*, int, long unsigned int, long unsigned int) will always overflow destination buffer |
236 |
} |
237 |
|
238 |
## |
239 |
# Parameters : |
240 |
# 1 - Path where to search for source files. |
241 |
# 2 - Path where source files must be copied. |
242 |
copySourceFiles() { |
243 |
while read -d '' -r filename; do |
244 |
DEST_FILE="${2}${filename#${1}}" |
245 |
mkdir -p $(dirname "${DEST_FILE}") || die |
246 |
mv "${filename}" "${DEST_FILE}" || die |
247 |
done < <(find "${1}" -name '*.h' -print0 -o -name '*.c' -print0) |
248 |
} |
249 |
|
250 |
# This looks like it should instead have a template Makefile shipped with the |
251 |
# ebuild which is then copied and sed'd to meet requirements. |
252 |
|
253 |
## |
254 |
# Parameters : |
255 |
# 1 - Path of the file to create. |
256 |
# 2 - Name of the module. |
257 |
# 3 - Path of the generated Makefile. |
258 |
createMakefile() { |
259 |
cat >${1} <<EOF |
260 |
TOP := \$(abspath \$(dir \$(lastword \$(MAKEFILE_LIST)))) |
261 |
EXEC = ${2}.efi |
262 |
SRC = \$(shell find \$(TOP) -type f -name '*.c') |
263 |
OBJ = \$(SRC:.c=.o) |
264 |
INC_DIR = /usr/include/${PN} |
265 |
LIB_DIR = /usr/lib |
266 |
STATIC_LIBRARY_FILES = \\ |
267 |
EOF |
268 |
|
269 |
perl -ne \ |
270 |
'if( m/^STATIC_LIBRARY_FILES\s*=/ ) { |
271 |
$static=1; |
272 |
} elsif( $static ) { |
273 |
if( m!^\s*\$\(BIN_DIR\).*/([^/]*)\.lib! ) { |
274 |
print "\t\"-l${1}\" \\\n" |
275 |
} else { |
276 |
$static=0; |
277 |
} |
278 |
}' >>${1} <${3} |
279 |
|
280 |
cat >>${1} <<EOF |
281 |
|
282 |
EFI_LDS = \$(LIB_DIR)/GccBase.lds |
283 |
|
284 |
EOF |
285 |
grep -e '^MODULE_TYPE\s*=' ${3} >>${1} |
286 |
grep -e '^IMAGE_ENTRY_POINT\s*=' ${3} >>${1} |
287 |
echo >>${1} |
288 |
grep -e '^CP\s*=' ${3} >>${1} |
289 |
grep -e '^RM\s*=' ${3} >>${1} |
290 |
grep -e '^CC\s*=' ${3} >>${1} |
291 |
grep -e '^DLINK\s*=' ${3} >>${1} |
292 |
grep -e '^OBJCOPY\s*=' ${3} >>${1} |
293 |
grep -e '^GENFW\s*=' ${3} >>${1} |
294 |
[[ $ARCH == X64 ]] && PECOFF_HEADER_SIZE='0x228' || PECOFF_HEADER_SIZE='0x220' |
295 |
cat >>${1} <<EOF |
296 |
|
297 |
CC_FLAGS = -g -fshort-wchar -fno-strict-aliasing -Wall -Werror \ |
298 |
-Wno-array-bounds -ffunction-sections -fdata-sections -c -iquote\$(TOP) \ |
299 |
-include AutoGen.h -I\$(INC_DIR) -DSTRING_ARRAY_NAME=${2}Strings -m64 \ |
300 |
-fno-stack-protector "-DEFIAPI=__attribute__((ms_abi))" -DNO_BUILTIN_VA_FUNCS \ |
301 |
-mno-red-zone -Wno-address -mcmodel=large -Wno-address \ |
302 |
-Wno-unused-but-set-variable |
303 |
DLINK_FLAGS=-nostdlib -n -q --gc-sections --entry \$(IMAGE_ENTRY_POINT) \ |
304 |
-u \$(IMAGE_ENTRY_POINT) -melf_x86_64 --oformat=elf64-x86-64 -L \$(LIB_DIR) \ |
305 |
--script=\$(EFI_LDS) --defsym=PECOFF_HEADER_SIZE=${PECOFF_HEADER_SIZE} |
306 |
EOF |
307 |
grep -e '^OBJCOPY_FLAGS\s*=' ${3} >>${1} |
308 |
grep -e '^GENFW_FLAGS\s*=' ${3} >>${1} |
309 |
cat >>${1} <<EOF |
310 |
|
311 |
all: \$(EXEC) |
312 |
|
313 |
%.efi: \$(OBJ) |
314 |
\$(DLINK) -o \$(@:.efi=.dll) \$(DLINK_FLAGS) \\ |
315 |
--start-group \$(STATIC_LIBRARY_FILES) \$^ --end-group |
316 |
\$(OBJCOPY) \$(OBJCOPY_FLAGS) \$(@:.efi=.dll) |
317 |
\$(CP) \$(@:.efi=.dll) \$(@:.efi=.debug) |
318 |
\$(OBJCOPY) --strip-unneeded -R .eh_frame \$(@:.efi=.dll) |
319 |
\$(OBJCOPY) --add-gnu-debuglink=\$(@:.efi=.debug) \$(@:.efi=.dll) |
320 |
\$(GENFW) -e \$(MODULE_TYPE) -o \$@ \$(@:.efi=.dll) \$(GENFW_FLAGS) |
321 |
\$(RM) \$(@:.efi=.dll) |
322 |
|
323 |
%.o: %.c |
324 |
\$(CC) \$(CC_FLAGS) -o \$@ \$^ |
325 |
|
326 |
clean: |
327 |
\$(RM) *.o |
328 |
|
329 |
mrproper: clean |
330 |
\$(RM) \$(EXEC) \$(EXEC:.efi=.debug) |
331 |
|
332 |
.PHONY: all clean mrproper |
333 |
EOF |
334 |
} |