summaryrefslogtreecommitdiff
path: root/payloads
diff options
context:
space:
mode:
authorStefan Reinauer <stepan@coresystems.de>2010-04-20 17:19:20 +0000
committerStefan Reinauer <stepan@openbios.org>2010-04-20 17:19:20 +0000
commit97f546cf2d317496c18b49ce4b4b43889830b759 (patch)
tree6f3ebe2f2bc7699712dab014698b4db0798e4f47 /payloads
parent338150ed18fec783063550ca0ffacecfebb4caa7 (diff)
downloadcoreboot-97f546cf2d317496c18b49ce4b4b43889830b759.tar.xz
Allow easy libpayload compilation using xcompile.
Signed-off-by: Stefan Reinauer <stepan@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5465 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'payloads')
-rw-r--r--payloads/libpayload/Makefile5
-rw-r--r--payloads/libpayload/util/xcompile/xcompile103
2 files changed, 107 insertions, 1 deletions
diff --git a/payloads/libpayload/Makefile b/payloads/libpayload/Makefile
index 94a6f17201..8783f2118c 100644
--- a/payloads/libpayload/Makefile
+++ b/payloads/libpayload/Makefile
@@ -49,7 +49,10 @@ ifneq ($(V),1)
Q := @
endif
-CC = gcc
+$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
+include .xcompile
+
+CC ?= gcc
HOSTCC = gcc
HOSTCXX = g++
HOSTCFLAGS := -I$(srck) -I$(objk) -pipe
diff --git a/payloads/libpayload/util/xcompile/xcompile b/payloads/libpayload/util/xcompile/xcompile
new file mode 100644
index 0000000000..0c5da65de8
--- /dev/null
+++ b/payloads/libpayload/util/xcompile/xcompile
@@ -0,0 +1,103 @@
+#!/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
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# 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
+ $1 -nostdlib $2 .$$$$.c -o .$$$$.tmp 2>/dev/null >/dev/null
+ ret=$?
+ rm -f .$$$$.c .$$$$.tmp
+ return $ret
+}
+
+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
+TMPFILE=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
+touch $TMPFILE
+
+# This should be a loop over all supported architectures
+TARCH=i386
+TWIDTH=32
+for gccprefixes in `pwd`/util/crossgcc/xgcc/bin/${TARCH}-elf- ${TARCH}-elf- ""; do
+ if ! which ${gccprefixes}as 2>/dev/null >/dev/null; then
+ continue
+ fi
+ rm -f ${TMPFILE}.o
+ if ${gccprefixes}as -o ${TMPFILE}.o ${TMPFILE}; then
+ TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
+ if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
+ GCCPREFIX=$gccprefixes
+ ASFLAGS=
+ CFLAGS=
+ LDFLAGS=
+ break
+ fi
+ fi
+ if ${gccprefixes}as --32 -o ${TMPFILE}.o ${TMPFILE}; then
+ TYPE=`${gccprefixes}objdump -p ${TMPFILE}.o`
+ if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
+ GCCPREFIX=$gccprefixes
+ ASFLAGS=--32
+ CFLAGS="-m32 "
+ LDFLAGS="-b elf32-i386"
+ break
+ fi
+ fi
+done
+rm -f $TMPFILE ${TMPFILE}.o
+
+if [ "$GCCPREFIX" = "invalid" ]; then
+ echo '$(error no suitable gcc found)'
+ exit 1
+fi
+
+CC="${GCCPREFIX}gcc"
+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 "
+
+if which gcc 2>/dev/null >/dev/null; then
+ HOSTCC=gcc
+else
+ HOSTCC=cc
+fi
+
+cat << EOF
+# elf${TWIDTH}-${TARCH} toolchain
+AS:=${GCCPREFIX}as ${ASFLAGS}
+CC:=${GCCPREFIX}gcc ${CFLAGS}
+CPP:=${GCCPREFIX}cpp
+AR:=${GCCPREFIX}ar
+LD:=${GCCPREFIX}ld ${LDFLAGS}
+STRIP:=${GCCPREFIX}strip
+NM:=${GCCPREFIX}nm
+OBJCOPY:=${GCCPREFIX}objcopy
+OBJDUMP:=${GCCPREFIX}objdump
+
+# native toolchain
+HOSTCC:=${HOSTCC}
+EOF
+