2010-02-10 21:31:38 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This file is part of the coreboot project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007-2010 coresystems GmbH
|
2012-11-26 23:33:09 +01:00
|
|
|
# Copyright (C) 2012 Google Inc
|
2010-02-10 21:31:38 +01:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
2010-03-16 02:17:19 +01:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; version 2 of the License.
|
2010-02-10 21:31:38 +01:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2013-02-23 18:37:27 +01:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2010-02-10 21:31:38 +01:00
|
|
|
#
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
TMPFILE=""
|
|
|
|
|
|
|
|
die() {
|
|
|
|
echo "ERROR: $*" >&2
|
|
|
|
exit 1
|
2010-02-10 21:31:38 +01:00
|
|
|
}
|
2009-08-12 17:00:51 +02:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
clean_up() {
|
|
|
|
if [ -n "$TMPFILE" ]; then
|
|
|
|
rm -f "$TMPFILE" "$TMPFILE.c" "$TMPFILE.o"
|
2009-08-12 17:00:51 +02:00
|
|
|
fi
|
2012-11-26 23:33:09 +01:00
|
|
|
}
|
2009-08-12 17:00:51 +02:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
program_exists() {
|
|
|
|
type "$1" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
testcc() {
|
|
|
|
local tmp_c="$TMPFILE.c"
|
|
|
|
local tmp_o="$TMPFILE.o"
|
|
|
|
rm -f "$tmp_c" "$tmp_o"
|
2012-12-20 23:24:08 +01:00
|
|
|
echo "void _start(void) {}" >"$tmp_c"
|
2012-11-26 23:33:09 +01:00
|
|
|
"$1" -nostdlib -Werror $2 "$tmp_c" -o "$tmp_o" >/dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
|
|
|
testas() {
|
|
|
|
local gccprefixes="$1"
|
|
|
|
local twidth="$2"
|
|
|
|
local arch="$3"
|
|
|
|
local use_dash_twidth="$4"
|
|
|
|
local obj_file="$TMPFILE.o"
|
|
|
|
local full_arch="elf$twidth-$arch"
|
|
|
|
|
|
|
|
rm -f "$obj_file"
|
|
|
|
[ -n "$use_dash_twidth" ] && use_dash_twidth="--$twidth"
|
|
|
|
${gccprefixes}as $use_dash_twidth -o "$obj_file" $TMPFILE 2>/dev/null ||
|
|
|
|
return 1
|
|
|
|
|
|
|
|
# Check output content type.
|
|
|
|
local obj_type="$(${gccprefixes}objdump -p $obj_file)"
|
|
|
|
local obj_arch="$(expr "$obj_type" : '.*format \(.[a-z0-9-]*\)')"
|
|
|
|
[ "$obj_arch" = "$full_arch" ] || return 1
|
|
|
|
|
|
|
|
# Architecture matched.
|
|
|
|
GCCPREFIX="$gccprefixes"
|
|
|
|
|
|
|
|
if [ -z "$use_dash_twidth" ]; then
|
|
|
|
ASFLAGS=""
|
|
|
|
CFLAGS=""
|
|
|
|
LDFLAGS=""
|
|
|
|
else
|
|
|
|
ASFLAGS="--$twidth"
|
|
|
|
CFLAGS="-m$twidth"
|
|
|
|
LDFLAGS="-b $full_arch"
|
2012-02-22 19:46:17 +01:00
|
|
|
|
2009-08-12 17:00:51 +02:00
|
|
|
fi
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
# Special parameters only available in dash_twidth mode.
|
|
|
|
[ -n "$use_dash_twidth" ] && case "$full_arch" in
|
|
|
|
"elf32-i386" )
|
|
|
|
LDFLAGS="$LDFLAGS -melf_i386"
|
|
|
|
CFLAGS="$CFLAGS -Wl,-b,elf32-i386 -Wl,-melf_i386"
|
|
|
|
;;
|
|
|
|
esac
|
2009-08-12 17:00:51 +02:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
return 0
|
|
|
|
}
|
2010-02-10 21:31:38 +01:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
detect_special_flags() {
|
|
|
|
local architecture="$1"
|
|
|
|
# GCC 4.6 is much more picky about unused variables.
|
|
|
|
# Turn off it's warnings for now:
|
|
|
|
testcc "$CC" "$CFLAGS -Wno-unused-but-set-variable " &&
|
|
|
|
CFLAGS="$CFLAGS -Wno-unused-but-set-variable "
|
|
|
|
|
|
|
|
# Use bfd linker instead of gold if available:
|
|
|
|
testcc "$CC" "$CFLAGS -fuse-ld=bfd" &&
|
|
|
|
CFLAGS="$CFLAGS -fuse-ld=bfd" && LINKER_SUFFIX='.bfd'
|
2010-02-10 21:31:38 +01:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
testcc "$CC" "$CFLAGS -Wa,--divide" &&
|
|
|
|
CFLAGS="$CFLAGS -Wa,--divide"
|
|
|
|
testcc "$CC" "$CFLAGS -fno-stack-protector"&&
|
|
|
|
CFLAGS="$CFLAGS -fno-stack-protector"
|
|
|
|
testcc "$CC" "$CFLAGS -Wl,--build-id=none" &&
|
|
|
|
CFLAGS="$CFLAGS -Wl,--build-id=none"
|
|
|
|
|
|
|
|
case "$architecture" in
|
2012-12-27 22:30:55 +01:00
|
|
|
armv7 )
|
|
|
|
ARMFLAGS=""
|
|
|
|
testcc "$CC" "$CFLAGS $ARMFLAGS"&&CFLAGS="$CFLAGS $ARMFLAGS"
|
2012-11-26 23:33:09 +01:00
|
|
|
;;
|
2013-11-08 19:13:50 +01:00
|
|
|
aarch64 )
|
|
|
|
ARMFLAGS=""
|
|
|
|
testcc "$CC" "$CFLAGS $ARMFLAGS"&&CFLAGS="$CFLAGS $ARMFLAGS"
|
|
|
|
;;
|
2012-11-26 23:33:09 +01:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
report_arch_toolchain() {
|
|
|
|
cat <<EOF
|
2012-12-06 02:12:10 +01:00
|
|
|
# elf${TWIDTH}-${TBFDARCH} toolchain (${GCCPREFIX}gcc)
|
2012-11-26 23:33:09 +01:00
|
|
|
CC_${TARCH}:=${GCCPREFIX}gcc ${CFLAGS}
|
2013-09-03 14:39:48 +02:00
|
|
|
CPP_${TARCH}:=${GCCPREFIX}cpp
|
2012-11-26 23:33:09 +01:00
|
|
|
AS_${TARCH}:=${GCCPREFIX}as ${ASFLAGS}
|
2013-03-23 01:35:56 +01:00
|
|
|
LD_${TARCH}:=${GCCPREFIX}ld${LINKER_SUFFIX} ${LDFLAGS}
|
2012-11-26 23:33:09 +01:00
|
|
|
NM_${TARCH}:=${GCCPREFIX}nm
|
|
|
|
OBJCOPY_${TARCH}:=${GCCPREFIX}objcopy
|
|
|
|
OBJDUMP_${TARCH}:=${GCCPREFIX}objdump
|
|
|
|
READELF_${TARCH}:=${GCCPREFIX}readelf
|
|
|
|
STRIP_${TARCH}:=${GCCPREFIX}strip
|
|
|
|
AR_${TARCH}:=${GCCPREFIX}ar
|
|
|
|
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
# Create temporary file(s).
|
|
|
|
TMPFILE="$(mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz)"
|
|
|
|
touch "$TMPFILE"
|
|
|
|
trap clean_up EXIT
|
|
|
|
|
|
|
|
# Architecture definition
|
2013-11-08 19:13:50 +01:00
|
|
|
SUPPORTED_ARCHITECTURE="x86 armv7 aarch64"
|
2012-11-26 23:33:09 +01:00
|
|
|
|
|
|
|
# ARM Architecture
|
2012-12-06 02:42:43 +01:00
|
|
|
TARCH_armv7="armv7"
|
2012-12-06 02:12:10 +01:00
|
|
|
TBFDARCH_armv7="littlearm"
|
2013-09-19 10:57:58 +02:00
|
|
|
TCLIST_armv7="armv7a armv7-a"
|
2012-12-06 02:12:10 +01:00
|
|
|
TWIDTH_armv7="32"
|
2012-11-26 23:33:09 +01:00
|
|
|
|
2013-11-08 19:13:50 +01:00
|
|
|
# AARCH64 -- armv8
|
|
|
|
TARCH_aarch64="aarch64"
|
|
|
|
TBFDARCH_aarch64="littleaarch64"
|
|
|
|
TCLIST_aarch64="aarch64"
|
|
|
|
TWIDTH_aarch64="64"
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
# X86 Architecture
|
|
|
|
TARCH_x86="i386"
|
2012-12-06 02:12:10 +01:00
|
|
|
TBFDARCH_x86="i386"
|
2012-11-26 23:33:09 +01:00
|
|
|
TCLIST_x86="i386 x86_64"
|
|
|
|
TWIDTH_x86="32"
|
2012-11-27 10:07:22 +01:00
|
|
|
XGCCPATH=${1:-"`pwd`/util/crossgcc/xgcc/bin/"}
|
2012-11-26 23:33:09 +01:00
|
|
|
|
|
|
|
# This loops over all supported architectures.
|
|
|
|
for architecture in $SUPPORTED_ARCHITECTURE; do
|
|
|
|
GCCPREFIX="invalid"
|
|
|
|
TARCH="$(eval echo \$TARCH_$architecture)"
|
2012-12-06 02:12:10 +01:00
|
|
|
TBFDARCH="$(eval echo \$TBFDARCH_$architecture)"
|
2012-11-26 23:33:09 +01:00
|
|
|
TCLIST="$(eval echo \$TCLIST_$architecture)"
|
|
|
|
TWIDTH="$(eval echo \$TWIDTH_$architecture)"
|
|
|
|
[ -z "$TARCH" -o -z "$TCLIST" -o -z "$TWIDTH" ] &&
|
|
|
|
die "Missing architecture definition for $architecture."
|
|
|
|
|
|
|
|
# To override toolchain, define CROSS_COMPILE_$arch or CROSS_COMPILE as
|
|
|
|
# environment variable.
|
|
|
|
# Ex: CROSS_COMPILE_arm="armv7a-cros-linux-gnueabi-"
|
|
|
|
# CROSS_COMPILE_x86="i686-pc-linux-gnu-"
|
|
|
|
search="$(eval echo \$CROSS_COMPILE_$architecture 2>/dev/null)"
|
|
|
|
search="$search $CROSS_COMPILE"
|
|
|
|
for toolchain in $TCLIST; do
|
|
|
|
search="$search $XGCCPATH$toolchain-elf-"
|
|
|
|
search="$search $toolchain-elf-"
|
2013-11-08 19:13:50 +01:00
|
|
|
search="$search $toolchain-linux-gnu-"
|
2012-12-06 02:12:10 +01:00
|
|
|
search="$search $XGCCPATH$toolchain-eabi-"
|
|
|
|
search="$search $toolchain-eabi-"
|
2012-11-26 23:33:09 +01:00
|
|
|
done
|
|
|
|
echo "# $architecture TARCH_SEARCH=$search"
|
|
|
|
|
|
|
|
# Search toolchain by checking assembler capability.
|
|
|
|
for gccprefixes in $search ""; do
|
|
|
|
program_exists "${gccprefixes}as" || continue
|
2012-12-06 02:12:10 +01:00
|
|
|
testas "$gccprefixes" "$TWIDTH" "$TBFDARCH" "" && break
|
|
|
|
testas "$gccprefixes" "$TWIDTH" "$TBFDARCH" "TRUE" && break
|
2012-11-26 23:33:09 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$GCCPREFIX" = "invalid" ]; then
|
|
|
|
echo "Warning: no suitable GCC for $architecture." >&2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
CC="${GCCPREFIX}"gcc
|
|
|
|
|
|
|
|
detect_special_flags "$architecture"
|
|
|
|
report_arch_toolchain
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ "$(${XGCCPATH}/iasl 2>/dev/null | grep -c ACPI)" -gt 0 ]; then
|
2011-08-09 00:07:50 +02:00
|
|
|
IASL=${XGCCPATH}iasl
|
|
|
|
else
|
|
|
|
IASL=iasl
|
|
|
|
fi
|
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
if program_exists gcc; then
|
|
|
|
HOSTCC=gcc
|
|
|
|
else
|
|
|
|
HOSTCC=cc
|
|
|
|
fi
|
2010-02-10 21:31:38 +01:00
|
|
|
|
2012-11-26 23:33:09 +01:00
|
|
|
cat <<EOF
|
2011-08-09 00:07:50 +02:00
|
|
|
IASL:=${IASL}
|
|
|
|
|
2010-02-10 21:31:38 +01:00
|
|
|
# native toolchain
|
|
|
|
HOSTCC:=${HOSTCC}
|
|
|
|
EOF
|