1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
6 PYTHON_COMPAT=( python2_7 )
7 PYTHON_REQ_USE="sqlite"
9 inherit flag-o-matic multiprocessing python-single-r1 toolchain-funcs
13 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"
19 KEYWORDS="~amd64 ~x86"
21 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
24 RDEPEND="${PYTHON_DEPS}"
29 S="${WORKDIR}/MyWorkSpace"
31 # Generated libs for EFI can contain WX sections
32 QA_EXECSTACK="usr/lib*/libBaseLib.a:*"
35 python_setup 'python2.7'
37 if [[ ${ARCH} == "amd64" ]]; then
39 elif [[ ${ARCH} == "x86" ]]; then
43 # We will create a custom toolchain with user defined settings
44 TOOLCHAIN_TAG="CUSTOM"
49 unpack "${WORKDIR}/${MY_V}.MyWorkSpace.zip"
52 unpack "${WORKDIR}/BaseTools(Unix).tar"
57 mkdir -p "${S}/doc" || die
58 pushd "${S}/doc" >/dev/null || die
59 for f in "${WORKDIR}/Documents/"*" Document.zip"; do
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
67 popd >/dev/null || die
70 popd >/dev/null || die
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" \
85 || die "Failed to update makefile header"
93 emake "${make_flags[@]}" -j1 -C BaseTools
94 . edksetup.sh BaseTools
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)
106 append-cflags $(test-flags-CC -m32) $(test-flags-CC -malign-double)
108 sed -e "s|^\(ACTIVE_PLATFORM\s*=\).*$|\1 MdeModulePkg/MdeModulePkg.dsc|" \
109 -e "s|^\(TARGET\s*=\).*$|\1 RELEASE|" \
110 -e "s|^\(TARGET_ARCH\s*=\).*$|\1 ${ARCH}|" \
111 -e "s|^\(TOOL_CHAIN_TAG\s*=\).*$|\1 ${TOOLCHAIN_TAG}|" \
112 -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"
124 if use examples; then
125 ewarn "Examples installation does not work anymore"
126 ewarn "Try with a most recent version of the package"
129 build libraries || die "Failed to compile environment"
134 local build_dir="${S}/Build/MdeModule/RELEASE_${TOOLCHAIN_TAG}/${ARCH}"
136 for f in "${build_dir}"/*/Library/*/*/OUTPUT/*.lib; do
137 local fn="lib${f##*/}"
138 newlib.a "${f}" "${fn%.lib}.a"
140 dolib.a "${S}/BaseTools/Scripts/GccBase.lds"
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}
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)
151 dobin "${S}/BaseTools/Source/C/bin/GenFw"
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##*/}"
166 # 1 - Path where to search for source files.
167 # 2 - Path where source files must be copied.
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)
179 # 1 - Path of the file to create.
180 # 2 - Name of the module.
181 # 3 - Path of the generated Makefile.
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"