[coreboot-gerrit] New patch to review for coreboot: 442b9e5 xcompile: Detect clang compilers

Patrick Georgi (pgeorgi@google.com) gerrit at coreboot.org
Thu Jun 4 13:58:25 CEST 2015


Patrick Georgi (pgeorgi at google.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/10424

-gerrit

commit 442b9e5741356e7ad7cbd841c85749e8b7f45351
Author: Patrick Georgi <patrick at georgi-clan.de>
Date:   Thu Jun 4 13:44:41 2015 +0200

    xcompile: Detect clang compilers
    
    This uses the availability of CONFIG_* variables in .xcompile and tests for
    compilers in xcompile so that the build system doesn't need to probe them.
    
    Change-Id: I359ad6245d2527efa7e848a9b38f5f194744c827
    Signed-off-by: Patrick Georgi <patrick at georgi-clan.de>
    Signed-off-by: Edward O'Callaghan <eocallaghan at alterapraxis.com>
---
 util/xcompile/xcompile | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/util/xcompile/xcompile b/util/xcompile/xcompile
index 0a22c34..f96857d 100755
--- a/util/xcompile/xcompile
+++ b/util/xcompile/xcompile
@@ -159,11 +159,15 @@ detect_special_flags() {
 
 report_arch_toolchain() {
 	cat <<EOF
-# elf${TWIDTH}-${TBFDARCH} toolchain (${GCCPREFIX}gcc)
+# elf${TWIDTH}-${TBFDARCH} toolchain (${GCC})
 ARCH_SUPPORTED+=${TARCH}
 SUBARCH_SUPPORTED+=${TSUPP-${TARCH}}
-CC_${TARCH}:=${GCCPREFIX}gcc
+ifeq (\$(CONFIG_COMPILER_GCC),y)
+CC_${TARCH}:=${GCC}
 CFLAGS_${TARCH}:=${CFLAGS_GCC}
+else
+CC_${TARCH}:=${CLANG}
+endif
 CPP_${TARCH}:=${GCCPREFIX}cpp
 AS_${TARCH}:=${GCCPREFIX}as ${ASFLAGS}
 LD_${TARCH}:=${GCCPREFIX}ld${LINKER_SUFFIX} ${LDFLAGS}
@@ -231,6 +235,7 @@ test_architecture() {
 
 	GCCPREFIX="invalid"
 	unset TABI TARCH TBFDARCH TCLIST TENDIAN TSUPP TWIDTH
+	unset GCC CLANG
 	if type arch_config_$architecture > /dev/null; then
 		arch_config_$architecture
 	else
@@ -257,21 +262,36 @@ test_architecture() {
 			program_exists "${gccprefix}as" || continue
 			for endian in $TENDIAN ""; do
 				testas "$gccprefix" "$TWIDTH" "$TBFDARCH" \
-					"" "$endian" && return 0
+					"" "$endian" && break
 				testas "$gccprefix" "$TWIDTH" "$TBFDARCH" \
-					"TRUE" "$endian" && return 0
+					"TRUE" "$endian" && break
 			done
 		done
 	done
+	if [ "invalid" != "$GCCPREFIX" ]; then
+		GCC="${GCCPREFIX}gcc"
+	fi
+
+	for clang_arch in $TCLIST invalid; do
+		testcc "clang" "-target ${clang_arch}-$TABI -c" && break
+	done
 
-	echo "Warning: no suitable GCC for $architecture." >&2
-	return 1
+	if [ "invalid" != "$clang_arch" ]; then
+		# FIXME: this may break in a clang && !gcc configuration,
+		# but that's more of a clang limitation. Let's be optimistic
+		# that this will change in the future.
+		CLANG="clang -target ${clang_arch}-${TABI} -ccc-gcc-name ${GCC}"
+	fi
+
+	if [ -z "$GCC" -a -z "$CLANG" ]; then
+		echo "Warning: no suitable compiler for $architecture." >&2
+		return 1
+	fi
 }
 
 # This loops over all supported architectures.
 for architecture in $SUPPORTED_ARCHITECTURES; do
 	if test_architecture $architecture; then
-		CC="${GCCPREFIX}"gcc
 		detect_special_flags "$architecture"
 		report_arch_toolchain
 	fi



More information about the coreboot-gerrit mailing list