dev-python/numpydoc: arm64 keyworded (bug #721130)
[gentoo.git] / sys-boot / udk / udk-2015-r1.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5
6 PYTHON_COMPAT=( python2_7 )
7 PYTHON_REQ_USE="sqlite"
8
9 inherit flag-o-matic multiprocessing python-single-r1 toolchain-funcs
10
11 MY_V="${PN^^}${PV}"
12
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"
16
17 LICENSE="BSD"
18 SLOT="0"
19 KEYWORDS="~amd64 ~x86"
20 IUSE="doc examples"
21 REQUIRED_USE="${PYTHON_REQUIRED_USE}"
22 RESTRICT="strip"
23
24 RDEPEND="${PYTHON_DEPS}"
25 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:*"
33
34 pkg_setup() {
35         python_setup 'python2.7'
36
37         if [[ ${ARCH} == "amd64" ]]; then
38                 ARCH=X64
39         elif [[ ${ARCH} == "x86" ]]; then
40                 ARCH=IA32
41         fi
42
43         # We will create a custom toolchain with user defined settings
44         TOOLCHAIN_TAG="CUSTOM"
45 }
46
47 src_unpack() {
48         unpack ${A}
49         unpack "${WORKDIR}/${MY_V}.MyWorkSpace.zip"
50
51         pushd "${S}" || die
52         unpack "${WORKDIR}/BaseTools(Unix).tar"
53
54         local doc_name
55         local f
56         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
66                 done
67                 popd >/dev/null || die
68         fi
69
70         popd >/dev/null || die
71 }
72
73 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" \
85                 || die "Failed to update makefile header"
86         local make_flags=(
87                 CC="$(tc-getCC)"
88                 CXX="$(tc-getCXX)"
89                 AS="$(tc-getAS)"
90                 AR="$(tc-getAR)"
91                 LD="$(tc-getLD)"
92         )
93         emake "${make_flags[@]}" -j1 -C BaseTools
94         . edksetup.sh BaseTools
95
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
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"
121 }
122
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"
130 }
131
132 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 }
163
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"
203 }