blob: 0c5da65de86f726129de6d0e1fe066694c0d356f [file] [log] [blame]
Stefan Reinauer97f546c2010-04-20 17:19:20 +00001#!/bin/sh
2#
3# This file is part of the coreboot project.
4#
5# Copyright (C) 2007-2010 coresystems GmbH
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; version 2 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19#
20
21testcc()
22{
23 echo "_start(void) {}" > .$$$$.c
24 $1 -nostdlib $2 .$$$$.c -o .$$$$.tmp 2>/dev/null >/dev/null
25 ret=$?
26 rm -f .$$$$.c .$$$$.tmp
27 return $ret
28}
29
30for make in make gmake gnumake; do
31 if [ "`$make --version 2>/dev/null | grep -c GNU`" -gt 0 ]; then
32 MAKE=$make
33 break
34 fi
35done
36
37GCCPREFIX=invalid
38TMPFILE=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
39touch $TMPFILE
40
41# This should be a loop over all supported architectures
42TARCH=i386
43TWIDTH=32
44for gccprefixes in `pwd`/util/crossgcc/xgcc/bin/${TARCH}-elf- ${TARCH}-elf- ""; do
45 if ! which ${gccprefixes}as 2>/dev/null >/dev/null; then
46 continue
47 fi
48 rm -f ${TMPFILE}.o
49 if ${gccprefixes}as -o ${TMPFILE}.o ${TMPFILE}; then
50 TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
51 if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
52 GCCPREFIX=$gccprefixes
53 ASFLAGS=
54 CFLAGS=
55 LDFLAGS=
56 break
57 fi
58 fi
59 if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then
60 TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
61 if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
62 GCCPREFIX=$gccprefixes
63 ASFLAGS=--32
64 CFLAGS="-m32 "
65 LDFLAGS="-b elf32-i386"
66 break
67 fi
68 fi
69done
70rm -f $TMPFILE ${TMPFILE}.o
71
72if [ "$GCCPREFIX" = "invalid" ]; then
73 echo '$(error no suitable gcc found)'
74 exit 1
75fi
76
77CC="${GCCPREFIX}gcc"
78testcc "$CC" "$CFLAGS-Wa,--divide " && CFLAGS="$CFLAGS-Wa,--divide "
79testcc "$CC" "$CFLAGS-fno-stack-protector " && CFLAGS="$CFLAGS-fno-stack-protector "
80testcc "$CC" "$CFLAGS-Wl,--build-id=none " && CFLAGS="$CFLAGS-Wl,--build-id=none "
81
82if which gcc 2>/dev/null >/dev/null; then
83 HOSTCC=gcc
84else
85 HOSTCC=cc
86fi
87
88cat << EOF
89# elf${TWIDTH}-${TARCH} toolchain
90AS:=${GCCPREFIX}as ${ASFLAGS}
91CC:=${GCCPREFIX}gcc ${CFLAGS}
92CPP:=${GCCPREFIX}cpp
93AR:=${GCCPREFIX}ar
94LD:=${GCCPREFIX}ld ${LDFLAGS}
95STRIP:=${GCCPREFIX}strip
96NM:=${GCCPREFIX}nm
97OBJCOPY:=${GCCPREFIX}objcopy
98OBJDUMP:=${GCCPREFIX}objdump
99
100# native toolchain
101HOSTCC:=${HOSTCC}
102EOF
103