Improve compiler detection and configuration in xcompile.
Move -fno-stack-protector support from Makefile to xcompile. Signed-off-by: Patrick Georgi <patrick.georgi@coresystems.de> Acked-by: Stefan Reinauer <stepan@coresystems.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5113 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
This commit is contained in:
parent
942a40da3a
commit
e82f4754ee
14
Makefile
14
Makefile
|
@ -221,19 +221,7 @@ INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)inclu
|
||||||
INCLUDES += -I$(top)/util/x86emu/include
|
INCLUDES += -I$(top)/util/x86emu/include
|
||||||
INCLUDES += -include $(obj)/build.h
|
INCLUDES += -include $(obj)/build.h
|
||||||
|
|
||||||
try-run= $(shell set -e; \
|
CFLAGS = $(INCLUDES) -Os -nostdinc
|
||||||
TMP=".$$$$.tmp"; \
|
|
||||||
if ($(1)) > /dev/null 2>&1; \
|
|
||||||
then echo "$(2)"; \
|
|
||||||
else echo "$(3)"; \
|
|
||||||
fi; rm -rf "$$TMP")
|
|
||||||
|
|
||||||
cc-option= $(call try-run,\
|
|
||||||
$(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
|
|
||||||
|
|
||||||
STACKPROTECT += $(call cc-option, -fno-stack-protector,)
|
|
||||||
|
|
||||||
CFLAGS = $(STACKPROTECT) $(INCLUDES) -Os -nostdinc
|
|
||||||
CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
|
CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
|
||||||
CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
|
CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
|
||||||
CFLAGS += -Wstrict-aliasing -Wshadow
|
CFLAGS += -Wstrict-aliasing -Wshadow
|
||||||
|
|
|
@ -1,3 +1,31 @@
|
||||||
|
#!/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 version 2 as
|
||||||
|
# published by the Free Software Foundation.
|
||||||
|
#
|
||||||
|
# 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
|
for make in make gmake gnumake; do
|
||||||
if [ "`$make --version 2>/dev/null | grep -c GNU`" -gt 0 ]; then
|
if [ "`$make --version 2>/dev/null | grep -c GNU`" -gt 0 ]; then
|
||||||
|
@ -8,39 +36,67 @@ done
|
||||||
|
|
||||||
GCCPREFIX=invalid
|
GCCPREFIX=invalid
|
||||||
TMP=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
|
TMP=`mktemp /tmp/temp.XXXX 2>/dev/null || echo /tmp/temp.78gOIUGz`
|
||||||
echo "mov %eax, %eax" > ${TMP}.s
|
touch $TMP
|
||||||
printf "\x7fELF\n" > ${TMP}.compare
|
|
||||||
for gccprefixes in `pwd`/util/crossgcc/xgcc/bin/i386-elf- i386-elf- ""; do
|
# This should be a loop over all supported architectures
|
||||||
if which ${gccprefixes}as 2>/dev/null >/dev/null; then
|
TARCH=i386
|
||||||
printf ""
|
TWIDTH=32
|
||||||
else
|
for gccprefixes in `pwd`/util/crossgcc/xgcc/bin/${TARCH}-elf- ${TARCH}-elf- ""; do
|
||||||
|
if ! which ${gccprefixes}as 2>/dev/null >/dev/null; then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
rm -f ${TMP}.o
|
rm -f ${TMP}.o
|
||||||
if ${gccprefixes}as --32 -o ${TMP}.o ${TMP}.s; then
|
if ${gccprefixes}as -o ${TMP}.o ${TMP}; then
|
||||||
cut -c-4 ${TMP}.o > ${TMP}.test 2>/dev/null
|
TYPE=`${gccprefixes}objdump -p ${TMP}.o`
|
||||||
if cmp ${TMP}.test ${TMP}.compare; then
|
if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
|
||||||
GCCPREFIX=$gccprefixes
|
GCCPREFIX=$gccprefixes
|
||||||
|
ASFLAGS=
|
||||||
|
CFLAGS=
|
||||||
|
LDFLAGS=
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if ${gccprefixes}as --32 -o ${TMP}.o ${TMP}; then
|
||||||
|
TYPE=`${gccprefixes}objdump -p ${TMP}.o`
|
||||||
|
if [ ${TYPE##* } == "elf${TWIDTH}-${TARCH}" ]; then
|
||||||
|
GCCPREFIX=$gccprefixes
|
||||||
|
ASFLAGS=--32
|
||||||
|
CFLAGS="-m32 "
|
||||||
|
LDFLAGS="-b elf32-i386"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
rm -f $TMP ${TMP}.s ${TMP}.o ${TMP}.compare ${TMP}.test
|
rm -f $TMP ${TMP}.o
|
||||||
|
|
||||||
if [ "$GCCPREFIX" = "invalid" ]; then
|
if [ "$GCCPREFIX" = "invalid" ]; then
|
||||||
echo '$(error no suitable gcc found)'
|
echo '$(error no suitable gcc found)'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat << afteroptions
|
CC="${GCCPREFIX}gcc"
|
||||||
AS:=${GCCPREFIX}as --32
|
testcc "$CC" "$CFLAGS-fno-stack-protector " && CFLAGS="$CFLAGS-fno-stack-protector "
|
||||||
CC:=${GCCPREFIX}gcc -m32
|
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
|
CPP:=${GCCPREFIX}cpp
|
||||||
AR:=${GCCPREFIX}ar
|
AR:=${GCCPREFIX}ar
|
||||||
LD:=${GCCPREFIX}ld -b elf32-i386
|
LD:=${GCCPREFIX}ld ${LDFLAGS}
|
||||||
STRIP:=${GCCPREFIX}strip
|
STRIP:=${GCCPREFIX}strip
|
||||||
NM:=${GCCPREFIX}nm
|
NM:=${GCCPREFIX}nm
|
||||||
OBJCOPY:=${GCCPREFIX}objcopy
|
OBJCOPY:=${GCCPREFIX}objcopy
|
||||||
OBJDUMP:=${GCCPREFIX}objdump
|
OBJDUMP:=${GCCPREFIX}objdump
|
||||||
HOSTCC:=gcc
|
|
||||||
afteroptions
|
# native toolchain
|
||||||
|
HOSTCC:=${HOSTCC}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue