2010-02-10 21:31:38 +01:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# This file is part of the coreboot project.
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007-2010 coresystems GmbH
|
|
|
|
#
|
|
|
|
# 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
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
testcc()
|
|
|
|
{
|
|
|
|
echo "_start(void) {}" > .$$$$.c
|
2011-10-25 21:28:40 +02:00
|
|
|
$1 -nostdlib -Werror $2 .$$$$.c -o .$$$$.tmp 2>/dev/null >/dev/null
|
2010-02-10 21:31:38 +01:00
|
|
|
ret=$?
|
|
|
|
rm -f .$$$$.c .$$$$.tmp
|
|
|
|
return $ret
|
|
|
|
}
|
2009-08-12 17:00:51 +02:00
|
|
|
|
|
|
|
for make in make gmake gnumake; do
|
|
|
|
if [ "`$make --version 2>/dev/null | grep -c GNU`" -gt 0 ]; then
|
|
|
|
MAKE=$make
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
GCCPREFIX=invalid
|
2011-10-08 01:20:30 +02:00
|
|
|
XGCCPATH=${1:-"`pwd`/util/crossgcc/xgcc/bin/"}
|
|
|
|
echo '#XGCCPATH='${XGCCPATH}
|
2010-04-14 16:35:40 +02:00
|
|
|
TMPFILE=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
|
|
|
|
touch $TMPFILE
|
2010-02-10 21:31:38 +01:00
|
|
|
|
|
|
|
# This should be a loop over all supported architectures
|
|
|
|
TARCH=i386
|
|
|
|
TWIDTH=32
|
2011-08-09 00:07:50 +02:00
|
|
|
for gccprefixes in ${XGCCPATH}${TARCH}-elf- ${TARCH}-elf- ""; do
|
2010-02-10 21:31:38 +01:00
|
|
|
if ! which ${gccprefixes}as 2>/dev/null >/dev/null; then
|
2009-08-12 17:00:51 +02:00
|
|
|
continue
|
|
|
|
fi
|
2010-04-14 16:35:40 +02:00
|
|
|
rm -f ${TMPFILE}.o
|
|
|
|
if ${gccprefixes}as -o ${TMPFILE}.o ${TMPFILE}; then
|
|
|
|
TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
|
2010-02-10 21:31:38 +01:00
|
|
|
if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
|
|
|
|
GCCPREFIX=$gccprefixes
|
|
|
|
ASFLAGS=
|
|
|
|
CFLAGS=
|
|
|
|
LDFLAGS=
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
2010-04-14 16:35:40 +02:00
|
|
|
if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then
|
|
|
|
TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
|
2010-02-10 21:31:38 +01:00
|
|
|
if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
|
2009-08-12 17:00:51 +02:00
|
|
|
GCCPREFIX=$gccprefixes
|
2010-02-10 21:31:38 +01:00
|
|
|
ASFLAGS=--32
|
|
|
|
CFLAGS="-m32 "
|
|
|
|
LDFLAGS="-b elf32-i386"
|
2009-08-12 17:00:51 +02:00
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
2010-04-14 16:35:40 +02:00
|
|
|
rm -f $TMPFILE ${TMPFILE}.o
|
2009-08-12 17:00:51 +02:00
|
|
|
|
|
|
|
if [ "$GCCPREFIX" = "invalid" ]; then
|
|
|
|
echo '$(error no suitable gcc found)'
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-02-10 21:31:38 +01:00
|
|
|
CC="${GCCPREFIX}gcc"
|
2010-03-16 13:01:13 +01:00
|
|
|
testcc "$CC" "$CFLAGS-Wa,--divide " && CFLAGS="$CFLAGS-Wa,--divide "
|
2010-02-10 21:31:38 +01:00
|
|
|
testcc "$CC" "$CFLAGS-fno-stack-protector " && CFLAGS="$CFLAGS-fno-stack-protector "
|
|
|
|
testcc "$CC" "$CFLAGS-Wl,--build-id=none " && CFLAGS="$CFLAGS-Wl,--build-id=none "
|
2011-10-12 21:54:08 +02:00
|
|
|
# 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 "
|
2010-02-10 21:31:38 +01:00
|
|
|
|
|
|
|
if which gcc 2>/dev/null >/dev/null; then
|
|
|
|
HOSTCC=gcc
|
|
|
|
else
|
|
|
|
HOSTCC=cc
|
|
|
|
fi
|
|
|
|
|
2011-08-09 00:07:50 +02:00
|
|
|
if [ "`${XGCCPATH}/iasl 2>/dev/null | grep -c ACPI`" -gt 0 ]; then
|
|
|
|
IASL=${XGCCPATH}iasl
|
|
|
|
else
|
|
|
|
IASL=iasl
|
|
|
|
fi
|
|
|
|
|
2010-02-10 21:31:38 +01:00
|
|
|
cat << EOF
|
|
|
|
# elf${TWIDTH}-${TARCH} toolchain
|
|
|
|
AS:=${GCCPREFIX}as ${ASFLAGS}
|
|
|
|
CC:=${GCCPREFIX}gcc ${CFLAGS}
|
2009-08-12 17:00:51 +02:00
|
|
|
AR:=${GCCPREFIX}ar
|
2010-02-10 21:31:38 +01:00
|
|
|
LD:=${GCCPREFIX}ld ${LDFLAGS}
|
2009-08-12 17:00:51 +02:00
|
|
|
STRIP:=${GCCPREFIX}strip
|
|
|
|
NM:=${GCCPREFIX}nm
|
|
|
|
OBJCOPY:=${GCCPREFIX}objcopy
|
|
|
|
OBJDUMP:=${GCCPREFIX}objdump
|
2010-02-10 21:31:38 +01:00
|
|
|
|
2011-08-09 00:07:50 +02:00
|
|
|
IASL:=${IASL}
|
|
|
|
|
2010-02-10 21:31:38 +01:00
|
|
|
# native toolchain
|
|
|
|
HOSTCC:=${HOSTCC}
|
|
|
|
EOF
|
|
|
|
|