xcompile: Use local variables and make cosmetic changes

Declaring function variables local improves bash scripts' robustness.

Cosmetic changes among other things include renaming variables from
plural to singular and vice versa as appropriate, and replacing spaces
with tabs.

Tested by confirming that sorted output generated by
util/xcompile/xcompile is the same before and after the change.

Change-Id: I7305b3a4e45478ed3653b7d915dde4f83965f6c1
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-on: http://review.coreboot.org/9996
Tested-by: build bot (Jenkins)
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
This commit is contained in:
Vadim Bendebury 2015-04-25 13:15:58 -07:00
parent e469602461
commit d2cb1f93fb

View File

@ -76,7 +76,7 @@ testcc() {
} }
testas() { testas() {
local gccprefixes="$1" local gccprefix="$1"
local twidth="$2" local twidth="$2"
local arch="$3" local arch="$3"
local use_dash_twidth="$4" local use_dash_twidth="$4"
@ -85,16 +85,16 @@ testas() {
rm -f "$obj_file" rm -f "$obj_file"
[ -n "$use_dash_twidth" ] && use_dash_twidth="--$twidth" [ -n "$use_dash_twidth" ] && use_dash_twidth="--$twidth"
${gccprefixes}as $use_dash_twidth -o "$obj_file" $TMPFILE 2>/dev/null || ${gccprefix}as $use_dash_twidth -o "$obj_file" $TMPFILE 2>/dev/null ||
return 1 return 1
# Check output content type. # Check output content type.
local obj_type="$(${gccprefixes}objdump -p $obj_file)" local obj_type="$(${gccprefix}objdump -p $obj_file)"
local obj_arch="$(expr "$obj_type" : '.*format \(.[a-z0-9-]*\)')" local obj_arch="$(expr "$obj_type" : '.*format \(.[a-z0-9-]*\)')"
[ "$obj_arch" = "$full_arch" ] || return 1 [ "$obj_arch" = "$full_arch" ] || return 1
# Architecture matched. # Architecture matched.
GCCPREFIX="$gccprefixes" GCCPREFIX="$gccprefix"
if [ -z "$use_dash_twidth" ]; then if [ -z "$use_dash_twidth" ]; then
ASFLAGS="" ASFLAGS=""
@ -146,7 +146,7 @@ detect_special_flags() {
;; ;;
mipsel) mipsel)
testcc "$CC" "$CFLAGS -mno-abicalls -fno-pic" && \ testcc "$CC" "$CFLAGS -mno-abicalls -fno-pic" && \
CFLAGS+=" -mno-abicalls -fno-pic" CFLAGS+=" -mno-abicalls -fno-pic"
;; ;;
esac esac
} }
@ -171,8 +171,8 @@ AR_${TARCH}:=${GCCPREFIX}ar
EOF EOF
} }
# Architecture definition # Architecture definitions
SUPPORTED_ARCHITECTURE="x86 arm arm64 riscv mipsel" SUPPORTED_ARCHITECTURES="arm arm64 mipsel riscv x86"
arch_config_arm() { arch_config_arm() {
TARCH="arm" TARCH="arm"
@ -218,7 +218,8 @@ arch_config_mipsel() {
} }
test_architecture() { test_architecture() {
architecture=$1 local architecture=$1
local gccprefix search
GCCPREFIX="invalid" GCCPREFIX="invalid"
unset TARCH TBFDARCH TCLIST TWIDTH TSUPP TABI unset TARCH TBFDARCH TCLIST TWIDTH TSUPP TABI
@ -244,10 +245,10 @@ test_architecture() {
# Search toolchain by checking assembler capability. # Search toolchain by checking assembler capability.
for TBFDARCH in $TBFDARCHS; do for TBFDARCH in $TBFDARCHS; do
for gccprefixes in $search ""; do for gccprefix in $search ""; do
program_exists "${gccprefixes}as" || continue program_exists "${gccprefix}as" || continue
testas "$gccprefixes" "$TWIDTH" "$TBFDARCH" "" && break testas "$gccprefix" "$TWIDTH" "$TBFDARCH" "" && break
testas "$gccprefixes" "$TWIDTH" "$TBFDARCH" "TRUE" && break testas "$gccprefix" "$TWIDTH" "$TBFDARCH" "TRUE" && break
done done
[ "$GCCPREFIX" = "invalid" ] || break [ "$GCCPREFIX" = "invalid" ] || break
done done
@ -263,7 +264,6 @@ test_architecture() {
} }
# This loops over all supported architectures. # This loops over all supported architectures.
for architecture in $SUPPORTED_ARCHITECTURE; do for architecture in $SUPPORTED_ARCHITECTURES; do
test_architecture $architecture test_architecture $architecture
done done