1 # Shell script that defines functions for determining some environmental
2 # characteristics for the edk2 "build" utility.
4 # This script is meant to be sourced, in a bash environment.
6 # Copyright (C) 2019 Red Hat, Inc.
8 # This program and the accompanying materials are licensed and made available
9 # under the terms and conditions of the BSD License that accompanies this
10 # distribution. The full text of the license may be found at
11 # <http://opensource.org/licenses/bsd-license.php>.
13 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
14 # WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 # Verify whether the QEMU system emulation target is supported by the UEFI spec
18 # and edk2. Print a message to the standard error, and return with nonzero
19 # status, if verification fails.
22 # $1: QEMU system emulation target
23 qemu_edk2_verify_arch
()
25 local emulation_target
="$1"
26 local program_name
=$
(basename -- "$0")
28 case "$emulation_target" in
29 (arm|aarch64|i386|x86_64
)
32 printf '%s: unknown/unsupported QEMU system emulation target "%s"\n' \
33 "$program_name" "$emulation_target" >&2
40 # Translate the QEMU system emulation target to the edk2 architecture
41 # identifier. Print the result to the standard output.
44 # $1: QEMU system emulation target
47 local emulation_target
="$1"
49 if ! qemu_edk2_verify_arch
"$emulation_target"; then
53 case "$emulation_target" in
70 # Translate the QEMU system emulation target to the gcc cross-compilation
71 # architecture identifier. Print the result to the standard output.
74 # $1: QEMU system emulation target
75 qemu_edk2_get_gcc_arch
()
77 local emulation_target
="$1"
79 if ! qemu_edk2_verify_arch
"$emulation_target"; then
83 case "$emulation_target" in
85 printf '%s\n' "$emulation_target"
94 # Determine the gcc cross-compiler prefix (if any) for use with the edk2
95 # toolchain. Print the result to the standard output.
98 # $1: QEMU system emulation target
99 qemu_edk2_get_cross_prefix
()
101 local emulation_target
="$1"
105 if ! gcc_arch
=$
(qemu_edk2_get_gcc_arch
"$emulation_target"); then
109 host_arch
=$
(uname
-m)
111 if [ "$gcc_arch" == "$host_arch" ] ||
112 ( [ "$gcc_arch" == i686
] && [ "$host_arch" == x86_64
] ); then
113 # no cross-compiler needed
116 printf '%s-linux-gnu-\n' "$gcc_arch"
121 # Determine the edk2 toolchain tag for the QEMU system emulation target. Print
122 # the result to the standard output. Print a message to the standard error, and
123 # return with nonzero status, if the (conditional) gcc version check fails.
126 # $1: QEMU system emulation target
127 qemu_edk2_get_toolchain
()
129 local emulation_target
="$1"
130 local program_name
=$
(basename -- "$0")
134 if ! qemu_edk2_verify_arch
"$emulation_target"; then
138 case "$emulation_target" in
144 if ! cross_prefix
=$
(qemu_edk2_get_cross_prefix
"$emulation_target"); then
148 gcc_version
=$
("${cross_prefix}gcc" -v 2>&1 |
tail -1 |
awk '{print $3}')
149 # Run "git-blame" on "OvmfPkg/build.sh" in edk2 for more information on
151 case "$gcc_version" in
153 printf '%s: unsupported gcc version "%s"\n' \
154 "$program_name" "$gcc_version" >&2
172 # Determine the name of the environment variable that exposes the
173 # cross-compiler prefix to the edk2 "build" utility. Print the result to the
177 # $1: QEMU system emulation target
178 qemu_edk2_get_cross_prefix_var
()
180 local emulation_target
="$1"
184 if ! edk2_toolchain
=$
(qemu_edk2_get_toolchain
"$emulation_target"); then
188 case "$emulation_target" in
190 if ! edk2_arch
=$
(qemu_edk2_get_arch
"$emulation_target"); then
193 printf '%s_%s_PREFIX\n' "$edk2_toolchain" "$edk2_arch"
196 printf '%s_BIN\n' "$edk2_toolchain"
202 # Set and export the environment variable(s) necessary for cross-compilation,
203 # whenever needed by the edk2 "build" utility.
206 # $1: QEMU system emulation target
207 qemu_edk2_set_cross_env
()
209 local emulation_target
="$1"
211 local cross_prefix_var
213 if ! cross_prefix
=$
(qemu_edk2_get_cross_prefix
"$emulation_target"); then
217 if [ -z "$cross_prefix" ]; then
222 if ! cross_prefix_var
=$
(qemu_edk2_get_cross_prefix_var \
223 "$emulation_target"); then
227 eval "export $cross_prefix_var=\$cross_prefix"