edk2: Fix compilation errors on latest Android

1) Update HOST tools with CLANG, since gcc is no longer supported.
2) Suppress the warnings of shift negative values.
3) Use Python & LD from prebuilds.
4) Backward compatible with existing baselines.

Change-Id: I9fdeaec7d4cdc95997f07fd05a47c67c1177cb2d
diff --git a/AndroidBoot.mk b/AndroidBoot.mk
index 4b55d0d..4270e2f 100644
--- a/AndroidBoot.mk
+++ b/AndroidBoot.mk
@@ -13,10 +13,17 @@
   ABL_USE_SDLLVM := true
 endif
 
+# LD is not available for older Android versions
+ifeq (1,$(filter 1,$(shell echo "$$(( $(PLATFORM_SDK_VERSION) > 27 ))" )))
+LDOPT="-fuse-ld=$(ANDROID_TOP)/$(SOONG_LLVM_PREBUILTS_PATH)/ld.lld"
+endif
+
 # Use host tools from prebuilts. Partner should determine the correct host tools to use
-PREBUILT_HOST_TOOLS := CC=$(ANDROID_TOP)/$(HOST_CC)\ \
-		       CXX=$(ANDROID_TOP)/$(HOST_CXX)\ \
+PREBUILT_HOST_TOOLS := CC=$(ANDROID_TOP)/$(CLANG)\ \
+		       CXX=$(ANDROID_TOP)/$(CLANG_CXX)\ \
+		       LDPATH=$(LDOPT)\ \
 		       AR=$(ANDROID_TOP)/$(HOST_AR)
+PREBUILT_PYTHON_PATH=$(ANDROID_TOP)/prebuilts/python/linux-x86/2.7.5/bin/python2
 
 DISABLE_PARALLEL_DOWNLOAD_FLASH := DISABLE_PARALLEL_DOWNLOAD_FLASH=0
 ifeq ($(PRODUCTS.$(INTERNAL_PRODUCT).PRODUCT_SUPPORTS_VERITY),true)
@@ -98,6 +105,7 @@
 		BOOTLOADER_OUT=../../../$(ABL_OUT) \
 		all \
 		PREBUILT_HOST_TOOLS=$(PREBUILT_HOST_TOOLS) \
+		PREBUILT_PYTHON_PATH=$(PREBUILT_PYTHON_PATH) \
 		$(BUILD_SYSTEM_ROOT_IMAGE) \
 		$(VERIFIED_BOOT) \
 		$(VERIFIED_BOOT_2) \
diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
index 09d2bff..8a8b2b3 100644
--- a/BaseTools/Source/C/Makefiles/header.makefile
+++ b/BaseTools/Source/C/Makefiles/header.makefile
@@ -26,7 +26,9 @@
 AS ?= gcc

 AR ?= ar

 LD ?= ld

-LINKER ?= $(CC)

+

+LINKER ?= $(CC) $(LDPATH)

+

 ifeq ($(ARCH), IA32)

 ARCH_INCLUDE = -I $(MAKEROOT)/Include/Ia32/

 endif

@@ -47,9 +49,9 @@
 CPPFLAGS = $(INCLUDE)

 ifeq ($(DARWIN),Darwin)

 # assume clang or clang compatible flags on OS X

-CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -nostdlib -c -g

+CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-shift-negative-value -Wno-self-assign -nostdlib -c -g

 else

-CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -nostdlib -c -g

+CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror -Wno-deprecated-declarations -Wno-shift-negative-value -nostdlib -c -g

 endif

 LFLAGS =

 

diff --git a/BaseTools/Source/C/VfrCompile/GNUmakefile b/BaseTools/Source/C/VfrCompile/GNUmakefile
index e446d14..3d7f177 100644
--- a/BaseTools/Source/C/VfrCompile/GNUmakefile
+++ b/BaseTools/Source/C/VfrCompile/GNUmakefile
@@ -26,7 +26,7 @@
 

 VFR_CPPFLAGS = -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)

 

-LINKER = $(CXX)

+LINKER = $(CXX) $(LDPATH)

 

 EXTRA_CLEAN_OBJECTS = EfiVfrParser.cpp EfiVfrParser.h VfrParser.dlg VfrTokens.h VfrLexer.cpp VfrLexer.h VfrSyntax.cpp tokens.h

 

diff --git a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
index c49cfd8..f2476dd 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
@@ -179,7 +179,7 @@
         globals.o hash.o lex.o main.o misc.o set.o pred.o egman.o mrhoist.o fcache.o

 

 $(BIN_DIR)/antlr : $(OBJ) $(SRC)

-		$(CC) $(CFLAGS) -o $(BIN_DIR)/antlr $(OBJ)

+		$(CC) $(CFLAGS) -o $(BIN_DIR)/antlr $(OBJ) $(LDPATH)

 

 # what files does PCCTS generate (both ANTLR and DLG)

 PCCTS_GEN=antlr.c scan.c err.c tokens.h mode.h parser.dlg stdpccts.h remap.h

diff --git a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
index dfcf3ee..abe9270 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
@@ -125,7 +125,7 @@
         relabel.o automata.o

 

 $(BIN_DIR)/dlg : $(OBJ) $(SRC)

-		$(CC) $(CFLAGS) -o $(BIN_DIR)/dlg $(OBJ)

+		$(CC) $(CFLAGS) -o $(BIN_DIR)/dlg $(OBJ) $(LDPATH)

 

 SRC = dlg_p.c dlg_a.c main.c err.c $(SET)/set.c support.c output.c \

         relabel.c automata.c

diff --git a/makefile b/makefile
index a131b00..aa61b52 100644
--- a/makefile
+++ b/makefile
@@ -6,7 +6,7 @@
 export $(BOOTLOADER_OUT)
 
 BUILDDIR=$(shell pwd)
-export WRAPPER := $(BUILDDIR)/clang-wrapper.py
+export WRAPPER := $(PREBUILT_PYTHON_PATH) $(BUILDDIR)/clang-wrapper.py
 
 export CLANG35_BIN := $(CLANG_BIN)
 export CLANG35_GCC_TOOLCHAIN := $(CLANG35_GCC_TOOLCHAIN)