build.sh: use a gcc with target triplet from PATH if CC=gcc is set

The motivation of this change is to be able to use the gcc version from
PATH (e.g. the bundled prebuilt) even in case CC=clang has been set
as default by the build.config:

-- Build with Clang from $PATH
$ ./build/build.sh

-- Build with GCC from $PATH
$ CC=gcc ./build/build.sh

In case of build/build.sh, $PATH is usually setup for a prebuilt
cross-compiler toolchain.
In order to accomodate any cross compiler settings when falling back to
gcc, simply unset CC to let kbuild figure out the correct compiler from
PATH.

It appears a bit hacky, but only breaks backward compatibility for the
case that somebody uses CC=gcc and expects the gcc from PATH to be used.
That case is still supported by passing an absolute path.

Change-Id: I537192168a27bdda9b288443de88ed45d7c4ec68
Signed-off-by: Matthias Maennich <maennich@google.com>
diff --git a/build.sh b/build.sh
index c4a57721..2c20ade 100755
--- a/build.sh
+++ b/build.sh
@@ -46,7 +46,10 @@
 #     for debugging purposes.
 #
 #   CC
-#     Override compiler to be used. (e.g. CC=clang)
+#     Override compiler to be used. (e.g. CC=clang) Specifying CC=gcc
+#     effectively unsets CC to fall back to the default gcc detected by kbuild
+#     (including any target triplet). To use a custom 'gcc' from PATH, use an
+#     absolute path, e.g.  CC=/usr/local/bin/gcc
 #
 #   LD
 #     Override linker (flags) to be used.
@@ -139,6 +142,11 @@
 
 export CLANG_TRIPLE CROSS_COMPILE CROSS_COMPILE_ARM32 ARCH SUBARCH
 
+# CC=gcc is effectively a fallback to the default gcc including any target
+# triplets. If the user wants to use a custom compiler, they are still able to
+# pass an absolute path, e.g. CC=/usr/bin/gcc.
+[ "${CC}" == "gcc" ] && unset CC
+
 if [ -n "${CC}" ]; then
   CC_ARG="CC=${CC}"
 fi