|
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 |
sed -e "s:^\(ACTIVE_PLATFORM\s*=\).*$:\1 MdeModulePkg/MdeModulePkg.dsc:" \ |
| 102 |
-e "s:^\(TARGET\s*=\).*$:\1 RELEASE:" \ |
| 103 |
-e "s:^\(TARGET_ARCH\s*=\).*$:\1 ${ARCH}:" \ |
| 104 |
-e "s:^\(TOOL_CHAIN_TAG\s*=\).*$:\1 ${TOOLCHAIN_TAG}:" \ |
| 105 |
-e "s:^\(MAX_CONCURRENT_THREAD_NUMBER\s*=\).*$:\1 $(makeopts_jobs):" \ |
| 106 |
-i "${S}/Conf/target.txt" || die "Failed to configure target file" |
| 107 |
sed -e "s:«CC»:$(tc-getCC):" \ |
| 108 |
-e "s:«AR»:$(tc-getAR):" \ |
| 109 |
-e "s:«LD»:$(tc-getLD):" \ |
| 110 |
-e "s:«OBJCOPY»:$(tc-getOBJCOPY):" \ |
| 111 |
-e "s:«CFLAGS»:${CFLAGS}:" \ |
| 112 |
"${FILESDIR}/${PV}-tools_def.template" >>${S}/Conf/tools_def.txt \ |
| 113 |
|| die "Failed to prepare tools definition file" |
| 114 |
} |
| 115 |
|
| 116 |
src_compile() { |
| 117 |
local build_target |
| 118 |
if use examples; then |
| 119 |
build_target=all |
| 120 |
else |
| 121 |
build_target=libraries |
| 122 |
fi |
| 123 |
|
| 124 |
build ${build_target} || die "Failed to compile environment" |
| 125 |
} |
| 126 |
|
| 127 |
src_install() { |
| 128 |
local build_dir="${S}/Build/MdeModule/RELEASE_${TOOLCHAIN_TAG}/${ARCH}" |
| 129 |
|
| 130 |
for f in "${build_dir}"/*/Library/*/*/OUTPUT/*.lib; do |
| 131 |
newlib.a "${f}" lib$(basename "${f}" .lib).a |
| 132 |
done |
| 133 |
dolib "${S}/BaseTools/Scripts/GccBase.lds" |
| 134 |
|
| 135 |
local include_dest="/usr/include/${PN}" |
| 136 |
for f in "" /Guid /IndustryStandard /Library /Pi /Ppi /Protocol /Uefi; do |
| 137 |
insinto "${include_dest}${f}" |
| 138 |
doins "${S}/MdePkg/Include${f}"/*.h |
| 139 |
done |
| 140 |
insinto "${include_dest}" |
| 141 |
doins "${S}/MdePkg/Include/${ARCH}"/*.h |
| 142 |
find "${S}" -name 'BaseTools' -prune -o -name 'MdePkg' -prune -o \ |
| 143 |
-name 'CryptoPkg' -prune -o -type d -name Include \ |
| 144 |
-exec find {} -maxdepth 0 \; \ |
| 145 |
| while read hfile; do |
| 146 |
doins -r "${hfile}"/* |
| 147 |
done |
| 148 |
|
| 149 |
dobin "${S}/BaseTools/Source/C/bin/GenFw" |
| 150 |
|
| 151 |
if use doc; then |
| 152 |
docinto "html" |
| 153 |
# Document installation may be very long, so split it and display message |
| 154 |
for f in "${S}"/doc/*; do |
| 155 |
ebegin "Installing documentation for $(basename ${f}), please wait" |
| 156 |
dodoc -r "${f}" |
| 157 |
eend $? |
| 158 |
done |
| 159 |
fi |
| 160 |
|
| 161 |
local ex_rebuild_dir |
| 162 |
local ex_name |
| 163 |
local ex_build_dir |
| 164 |
if use examples; then |
| 165 |
ex_rebuild_dir="${S}/${P}-exemples" |
| 166 |
for f in "${S}/MdeModulePkg/Application"/*; do |
| 167 |
ex_name=$(basename "${f}") |
| 168 |
ebegin "Preparing ${ex_name} example" |
| 169 |
mkdir -p "${ex_rebuild_dir}/${ex_name}" || die |
| 170 |
ex_build_dir="${build_dir}/MdeModulePkg/Application" |
| 171 |
ex_build_dir="${ex_build_dir}/${ex_name}/${ex_name}" |
| 172 |
|
| 173 |
copySourceFiles "${f}" "${ex_rebuild_dir}/${ex_name}" |
| 174 |
copySourceFiles "${ex_build_dir}/DEBUG" "${ex_rebuild_dir}/${ex_name}" |
| 175 |
createMakefile "${ex_rebuild_dir}/${ex_name}/Makefile" \ |
| 176 |
"${ex_name}" "${ex_build_dir}/GNUmakefile" || die |
| 177 |
|
| 178 |
tar -C "${ex_rebuild_dir}" -cf "${ex_rebuild_dir}/${ex_name}.tar" \ |
| 179 |
"${ex_name}" || die |
| 180 |
|
| 181 |
eend $? "Failed to create example file" |
| 182 |
done |
| 183 |
docinto "examples" |
| 184 |
dodoc "${ex_rebuild_dir}"/*.tar |
| 185 |
fi |
| 186 |
|
| 187 |
# TODO * QA Notice: The following files contain writable and executable sections |
| 188 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:Thunk16.obj |
| 189 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:SwitchStack.obj |
| 190 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:SetJump.obj |
| 191 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:LongJump.obj |
| 192 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:EnableDisableInterrupts.obj |
| 193 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:DisablePaging64.obj |
| 194 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:CpuId.obj |
| 195 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:CpuIdEx.obj |
| 196 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:EnableCache.obj |
| 197 |
# TODO * !WX --- --- usr/lib64/libBaseLib.a:DisableCache.obj |
| 198 |
# TODO * QA Notice: Package triggers severe warnings which indicate that it |
| 199 |
# TODO * may exhibit random runtime failures. |
| 200 |
# 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 |
| 201 |
} |
| 202 |
|
| 203 |
## |
| 204 |
# Parameters : |
| 205 |
# 1 - Path where to search for source files. |
| 206 |
# 2 - Path where source files must be copied. |
| 207 |
copySourceFiles() { |
| 208 |
while read -d '' -r filename; do |
| 209 |
DEST_FILE="${2}${filename#${1}}" |
| 210 |
mkdir -p $(dirname "${DEST_FILE}") || die |
| 211 |
mv "${filename}" "${DEST_FILE}" || die |
| 212 |
done < <(find "${1}" -name '*.h' -print0 -o -name '*.c' -print0) |
| 213 |
} |
| 214 |
|
| 215 |
## |
| 216 |
# Parameters : |
| 217 |
# 1 - Path of the file to create. |
| 218 |
# 2 - Name of the module. |
| 219 |
# 3 - Path of the generated Makefile. |
| 220 |
createMakefile() { |
| 221 |
local static_libs=$(sed -n '/^STATIC_LIBRARY_FILES\s*=/,/^\s*\$(OUTPUT_DIR)/{/^\s*\$(OUTPUT_DIR)/b;p}' ${3} \ |
| 222 |
| sed -e 's:^\s*\$(BIN_DIR).*/\([^/]*\)\.lib:\t-l\1:' -e 's:\\$:\\\\\\n:' | tr --delete '\n') |
| 223 |
local pecoff_header_size; |
| 224 |
[[ $ARCH == X64 ]] && pecoff_header_size='0x228' || pecoff_header_size='0x220' |
| 225 |
sed -e "s:«MODULE»:${2}:" \ |
| 226 |
-e "s:«PACKAGE_NAME»:${PN}:" \ |
| 227 |
-e "s:«STATIC_LIBS»:${static_libs}:" \ |
| 228 |
-e "s:«MODULE_TYPE»:$(grep -e '^MODULE_TYPE\s*=' ${3} | tail -1):" \ |
| 229 |
-e "s:«IMAGE_ENTRY_POINT»:$(grep -e '^IMAGE_ENTRY_POINT\s*=' ${3}):" \ |
| 230 |
-e "s:«CP»:$(grep -e '^CP\s*=' ${3}):" \ |
| 231 |
-e "s:«RM»:$(grep -e '^RM\s*=' ${3}):" \ |
| 232 |
-e "s:«CC»:$(grep -e '^CC\s*=' ${3}):" \ |
| 233 |
-e "s:«DLINK»:$(grep -e '^DLINK\s*=' ${3}):" \ |
| 234 |
-e "s:«OBJCOPY»:$(grep -e '^OBJCOPY\s*=' ${3}):" \ |
| 235 |
-e "s:«GENFW»:$(grep -e '^GENFW\s*=' ${3}):" \ |
| 236 |
-e "s:«PECOFF_HEADER_SIZE»:${pecoff_header_size}:" \ |
| 237 |
-e "s:«OBJCOPY_FLAGS»:$(grep -e '^OBJCOPY_FLAGS\s*=' ${3}):" \ |
| 238 |
-e "s:«GENFW_FLAGS»:$(grep -e '^GENFW_FLAGS\s*=' ${3}):" \ |
| 239 |
"${FILESDIR}/${PV}-makefile.template" >${1} \ |
| 240 |
|| die "Failed to create Makefile" |
| 241 |
} |