Merge "Define __USE_MINGW_ANSI_STDIO for windows build"
diff --git a/core/clang/config.mk b/core/clang/config.mk
index b8f76f2..c598e7d 100644
--- a/core/clang/config.mk
+++ b/core/clang/config.mk
@@ -31,7 +31,8 @@
   -funswitch-loops \
   -Wno-psabi \
   -Wno-unused-but-set-variable \
-  -Wno-unused-but-set-parameter
+  -Wno-unused-but-set-parameter \
+  -fno-canonical-system-headers
 
 # Clang flags for all host rules
 CLANG_CONFIG_HOST_EXTRA_ASFLAGS :=
diff --git a/core/combo/HOST_linux-x86.mk b/core/combo/HOST_linux-x86.mk
index 85d536b..1472849 100644
--- a/core/combo/HOST_linux-x86.mk
+++ b/core/combo/HOST_linux-x86.mk
@@ -52,7 +52,8 @@
 endif # BUILD_HOST_static
 
 HOST_GLOBAL_CFLAGS += -fPIC \
-    -include $(call select-android-config-h,linux-x86)
+  -no-canonical-prefixes \
+  -include $(call select-android-config-h,linux-x86)
 
 # Disable new longjmp in glibc 2.11 and later. See bug 2967937.
 HOST_GLOBAL_CFLAGS += -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0
diff --git a/core/combo/TARGET_linux-arm.mk b/core/combo/TARGET_linux-arm.mk
index 81d0813..8c8a01a 100644
--- a/core/combo/TARGET_linux-arm.mk
+++ b/core/combo/TARGET_linux-arm.mk
@@ -103,6 +103,8 @@
 			-Werror=format-security \
 			-D_FORTIFY_SOURCE=2 \
 			-fno-short-enums \
+			-no-canonical-prefixes \
+			-fno-canonical-system-headers \
 			$(arch_variant_cflags) \
 			-include $(android_config_h) \
 			-I $(dir $(android_config_h))
diff --git a/core/combo/TARGET_linux-arm64.mk b/core/combo/TARGET_linux-arm64.mk
index 5e50f9f..6515eb5 100644
--- a/core/combo/TARGET_linux-arm64.mk
+++ b/core/combo/TARGET_linux-arm64.mk
@@ -87,6 +87,8 @@
 			-Werror=format-security \
 			-D_FORTIFY_SOURCE=2 \
 			-fno-short-enums \
+			-no-canonical-prefixes \
+			-fno-canonical-system-headers \
 			$(arch_variant_cflags) \
 			-include $(android_config_h) \
 			-I $(dir $(android_config_h))
diff --git a/core/combo/TARGET_linux-mips.mk b/core/combo/TARGET_linux-mips.mk
index 1250767..015d46b 100644
--- a/core/combo/TARGET_linux-mips.mk
+++ b/core/combo/TARGET_linux-mips.mk
@@ -90,6 +90,8 @@
 			-Wa,--noexecstack \
 			-Werror=format-security \
 			-D_FORTIFY_SOURCE=2 \
+			-no-canonical-prefixes \
+			-fno-canonical-system-headers \
 			$(arch_variant_cflags) \
 			-include $(android_config_h) \
 			-I $(dir $(android_config_h))
diff --git a/core/combo/TARGET_linux-mips64.mk b/core/combo/TARGET_linux-mips64.mk
index 2130d03..a7b03b2 100644
--- a/core/combo/TARGET_linux-mips64.mk
+++ b/core/combo/TARGET_linux-mips64.mk
@@ -95,6 +95,8 @@
 			-Wa,--noexecstack \
 			-Werror=format-security \
 			-D_FORTIFY_SOURCE=2 \
+			-no-canonical-prefixes \
+			-fno-canonical-system-headers \
 			$(arch_variant_cflags) \
 			-include $(android_config_h) \
 			-I $(dir $(android_config_h))
diff --git a/core/combo/TARGET_linux-x86.mk b/core/combo/TARGET_linux-x86.mk
index 4f66765..4ebcd93 100644
--- a/core/combo/TARGET_linux-x86.mk
+++ b/core/combo/TARGET_linux-x86.mk
@@ -122,6 +122,8 @@
 			-fstack-protector \
 			-m32 \
 			-msse2 \
+			-no-canonical-prefixes \
+			-fno-canonical-system-headers \
 			-include $(android_config_h) \
 			-I $(dir $(android_config_h))
 
diff --git a/core/combo/TARGET_linux-x86_64.mk b/core/combo/TARGET_linux-x86_64.mk
index 42953ae..ee6c6e2 100644
--- a/core/combo/TARGET_linux-x86_64.mk
+++ b/core/combo/TARGET_linux-x86_64.mk
@@ -120,7 +120,9 @@
 			-funswitch-loops \
 			-funwind-tables \
 			-fstack-protector \
-			-m64
+			-m64 \
+			-no-canonical-prefixes \
+			-fno-canonical-system-headers
 
 # Help catch common 32/64-bit errors.
 TARGET_GLOBAL_CFLAGS += \
diff --git a/core/combo/javac.mk b/core/combo/javac.mk
index 153ab5f..4248af0 100644
--- a/core/combo/javac.mk
+++ b/core/combo/javac.mk
@@ -10,9 +10,9 @@
 #
 
 ifneq ($(LEGACY_USE_JAVA6),)
-common_flags := -target 1.5 -Xmaxerrs 9999999
+common_jdk_flags := -target 1.5 -Xmaxerrs 9999999
 else
-common_flags := -source 1.7 -target 1.7 -Xmaxerrs 9999999
+common_jdk_flags := -source 1.7 -target 1.7 -Xmaxerrs 9999999
 endif
 
 # Use the indexer wrapper to index the codebase instead of the javac compiler
@@ -25,9 +25,9 @@
 # Whatever compiler is on this system.
 ifeq ($(BUILD_OS), windows)
     COMMON_JAVAC := development/host/windows/prebuilt/javawrap.exe -J-Xmx256m \
-        $(common_flags)
+        $(common_jdk_flags)
 else
-    COMMON_JAVAC := $(JAVACC) -J-Xmx1024M $(common_flags)
+    COMMON_JAVAC := $(JAVACC) -J-Xmx1024M $(common_jdk_flags)
 endif
 
 # Eclipse.
diff --git a/core/dex_preopt_libart.mk b/core/dex_preopt_libart.mk
index 73e8494..7f3285c 100644
--- a/core/dex_preopt_libart.mk
+++ b/core/dex_preopt_libart.mk
@@ -23,9 +23,9 @@
 
 PRELOADED_CLASSES := frameworks/base/preloaded-classes
 
-LIBART_BOOT_IMAGE := /$(DEXPREOPT_BOOT_JAR_DIR)/boot.art
+LIBART_BOOT_IMAGE := /$(DEXPREOPT_BOOT_JAR_DIR)/boot-$(DEX2OAT_TARGET_ARCH).art
 
-DEFAULT_DEX_PREOPT_BUILT_IMAGE := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot.art
+DEFAULT_DEX_PREOPT_BUILT_IMAGE := $(DEXPREOPT_BOOT_JAR_DIR_FULL_PATH)/boot-$(DEX2OAT_TARGET_ARCH).art
 
 DEFAULT_DEX_PREOPT_INSTALLED_IMAGE :=
 ifneq ($(PRODUCT_DEX_PREOPT_IMAGE_IN_DATA),true)
diff --git a/core/executable_prefer_symlink.mk b/core/executable_prefer_symlink.mk
new file mode 100644
index 0000000..c6abed4
--- /dev/null
+++ b/core/executable_prefer_symlink.mk
@@ -0,0 +1,25 @@
+# include this makefile to create the LOCAL_MODULE symlink to the primary version binary.
+# but this requires the primary version name specified via LOCAL_MODULE_STEM_32 or LOCAL_MODULE_STEM_64,
+# and different with the LOCAL_MODULE value
+#
+# Note: now only limited to the binaries that will be installed under system/bin directory
+
+my_symlink := $(addprefix $(TARGET_OUT)/bin/, $(LOCAL_MODULE))
+# create link to the one used for prefer version
+ifneq ($(TARGET_PREFER_32_BIT_APPS),true)
+  $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_64)
+else
+  $(my_symlink): PRIVATE_SRC_BINARY_NAME := $(LOCAL_MODULE_STEM_32)
+endif
+
+$(my_symlink): $(LOCAL_INSTALLED_MODULE) $(LOCAL_MODULE_MAKEFILE)
+	@echo "Symlink: $@ -> $(PRIVATE_SRC_BINARY_NAME)"
+	@mkdir -p $(dir $@)
+	@rm -rf $@
+	$(hide) ln -sf $(PRIVATE_SRC_BINARY_NAME) $@
+
+# We need this so that the installed files could be picked up based on the
+# local module name
+ALL_MODULES.$(LOCAL_MODULE).INSTALLED += $(my_symlink)
+
+my_symlink :=
diff --git a/core/main.mk b/core/main.mk
index 8f60da7..e7a97be 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -228,22 +228,8 @@
 
 
 ifndef BUILD_EMULATOR
-ifeq (darwin,$(HOST_OS))
-GCC_REALPATH = $(realpath $(shell which $(HOST_CC)))
-ifneq ($(findstring llvm-gcc,$(GCC_REALPATH)),)
-  # Using LLVM GCC results in a non functional emulator due to it
-  # not honouring global register variables
-  $(warning ****************************************)
-  $(warning * gcc is linked to llvm-gcc which will *)
-  $(warning * not create a useable emulator.       *)
-  $(warning ****************************************)
+  # Emulator binaries are now provided under prebuilts/android-emulator/
   BUILD_EMULATOR := false
-else
-  BUILD_EMULATOR := true
-endif
-else   # HOST_OS is not darwin
-  BUILD_EMULATOR := true
-endif  # HOST_OS is darwin
 endif
 
 $(shell echo 'VERSIONS_CHECKED := $(VERSION_CHECK_SEQUENCE_NUMBER)' \
diff --git a/envsetup.sh b/envsetup.sh
index 60726d3..d026466 100644
--- a/envsetup.sh
+++ b/envsetup.sh
@@ -171,6 +171,25 @@
     export ANDROID_QTOOLS=$T/development/emulator/qtools
     export ANDROID_DEV_SCRIPTS=$T/development/scripts:$T/prebuilts/devtools/tools
     export ANDROID_BUILD_PATHS=$(get_build_var ANDROID_BUILD_PATHS):$ANDROID_QTOOLS:$ANDROID_TOOLCHAIN:$ANDROID_KERNEL_TOOLCHAIN_PATH$ANDROID_DEV_SCRIPTS:
+
+    # If prebuilts/android-emulator/<system>/ exists, prepend it to our PATH
+    # to ensure that the corresponding 'emulator' binaries are used.
+    case $(uname -s) in
+        Darwin)
+            ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/darwin-x86_64
+            ;;
+        Linux)
+            ANDROID_EMULATOR_PREBUILTS=$T/prebuilts/android-emulator/linux-x86_64
+            ;;
+        *)
+            ANDROID_EMULATOR_PREBUILTS=
+            ;;
+    esac
+    if [ -n "$ANDROID_EMULATOR_PREBUILTS" -a -d "$ANDROID_EMULATOR_PREBUILTS" ]; then
+        ANDROID_BUILD_PATHS=$ANDROID_EMULATOR_PREBUILTS:$ANDROID_BUILD_PATHS
+        export ANDROID_EMULATOR_PREBUILTS
+    fi
+
     export PATH=$ANDROID_BUILD_PATHS$PATH
 
     unset ANDROID_JAVA_TOOLCHAIN
diff --git a/target/board/generic_arm64/BoardConfig.mk b/target/board/generic_arm64/BoardConfig.mk
index 1768ffc..9d3bcc0 100644
--- a/target/board/generic_arm64/BoardConfig.mk
+++ b/target/board/generic_arm64/BoardConfig.mk
@@ -55,4 +55,3 @@
 BOARD_FLASH_BLOCK_SIZE := 512
 TARGET_USERIMAGES_SPARSE_EXT_DISABLED := true
 
-BUILD_EMULATOR := false