Fix GCC toolchain paths when using Clang

Fix the GCC toolchain paths to distinguish between the base
directory, and the bin directory. This doesn't impact any of the
targets being built now, but is needed for adding future targets.

The COMMON_CFLAGS --gcc-toolchain flag should also refer to the
base rather than the bin directory, although it didn't matter
for kvm-unit-tests.

No change in the tools used for current compilations (confimred
with strace).

Signed-off-by: Fuad Tabba <tabba@google.com>
Change-Id: Ia4de39da5ad98f4016d099313d98f0c283f573bd
diff --git a/Makefile b/Makefile
index 105a114..a7be173 100644
--- a/Makefile
+++ b/Makefile
@@ -73,10 +73,11 @@
 TARGET = aarch64-linux-gnu
 # The GCC toolchain is needed when building kvm-unit-tests as well as Linux
 # with Clang, because of lack of support for the LLVM integrated assembler.
-GCC_TOOLCHAIN_DIR = $(TOOLCHAIN_GCC_49)/bin/
+GCC_TOOLCHAIN_DIR = $(TOOLCHAIN_GCC_49)
+GCC_TOOLCHAIN_BIN = $(GCC_TOOLCHAIN_DIR)/bin/
 LLVM = "LLVM=1"
-# KVM Unit Tests requires additional flags to build with Clang.
-KUT_COMMON_CFLAGS := -Qunused-arguments --target=$(TARGET) -fno-integrated-as -Wno-asm-operand-widths -fpic --gcc-toolchain=$(GCC_TOOLCHAIN_DIR) --prefix=$(GCC_TOOLCHAIN_DIR)/$(TARGET)-
+# Some targets require additional flags to build with Clang.
+COMMON_CFLAGS := -Qunused-arguments --target=$(TARGET) -fno-integrated-as -Wno-asm-operand-widths -fpic --gcc-toolchain=$(GCC_TOOLCHAIN_DIR) --sysroot=$(GCC_TOOLCHAIN_DIR)/$(TARGET)/libc --prefix=$(GCC_TOOLCHAIN_BIN)/$(TARGET)-
 else
 $(error Unrecognized toolchain: TOOLCHAIN=$(TOOLCHAIN))
 endif
@@ -87,7 +88,7 @@
 LD := $(TOOLCHAIN_BIN)/$(TARGET)-ld
 OBJCOPY := $(TOOLCHAIN_BIN)/$(TARGET)-objcopy
 OBJDUMP := $(TOOLCHAIN_BIN)/$(TARGET)-objdump
-GCC_TOOLCHAIN_DIR := $(TOOLCHAIN_BIN)
+GCC_TOOLCHAIN_BIN := $(TOOLCHAIN_BIN)
 endif
 
 ##
@@ -172,7 +173,7 @@
 			--prefix=$(KUT_OUT) --arch=$(ARCH) \
 			--cc=$(CC) --ld=$(LD) \
 			--objcopy=$(OBJCOPY) --objdump=$(OBJDUMP)
-	COMMON_CFLAGS="$(KUT_COMMON_CFLAGS)" \
+	COMMON_CFLAGS="$(COMMON_CFLAGS)" \
 		$(MAKE) -C $(KUT_OUT) standalone
 	touch $(KUT_STAMP)
 
@@ -195,7 +196,7 @@
 	CROSS_COMPILE="$(TARGET)-" \
 	$(MAKE) \
 	$(LLVM) \
-	GCC_TOOLCHAIN_DIR="$(GCC_TOOLCHAIN_DIR)" \
+	GCC_TOOLCHAIN_DIR="$(GCC_TOOLCHAIN_BIN)" \
 	-C $(LINUX_SRC) \
 	V=$(LINUX_VERBOSE) \
 	O=$(LINUX_OUT)