Merge "Clang build support, -Wthread-safety with GCC 4.6." into dalvik-dev
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 7ba2e4f..508ff1b 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -33,6 +33,10 @@
 LLVM_ROOT_PATH := external/llvm
 include $(LLVM_ROOT_PATH)/llvm.mk
 
+# Clang build.
+# ART_TARGET_CLANG := true
+# ART_HOST_CLANG := true
+
 # directory used for gtests on device
 ART_NATIVETEST_DIR := /data/nativetest/art
 ART_NATIVETEST_OUT := $(TARGET_OUT_DATA_NATIVE_TESTS)/art
@@ -58,6 +62,13 @@
 	-Wstrict-aliasing=3 \
 	-fstrict-aliasing
 
+# Enable thread-safety for GCC 4.6 but not for GCC 4.7 where this feature was removed.
+# Enable GCC 4.6 builds with 'export TARGET_GCC_VERSION_EXP=4.6'
+ifneq ($(filter 4.6 4.6.%, $(TARGET_GCC_VERSION)),)
+  $(info Enabling thread-safety for GCC $(TARGET_GCC_VERSION))
+  art_cflags += -Wthread-safety
+endif
+
 ifeq ($(ART_SMALL_MODE),true)
   art_cflags += -DART_SMALL_MODE=1
 endif
diff --git a/build/Android.executable.mk b/build/Android.executable.mk
index b30e27b..ee968a7 100644
--- a/build/Android.executable.mk
+++ b/build/Android.executable.mk
@@ -62,6 +62,7 @@
 
   LOCAL_CFLAGS := $(ART_EXECUTABLES_CFLAGS)
   ifeq ($$(art_target_or_host),target)
+    LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
     ifeq ($$(art_ndebug_or_debug),debug)
       LOCAL_CFLAGS += $(ART_TARGET_DEBUG_CFLAGS)
@@ -69,6 +70,7 @@
       LOCAL_CFLAGS += $(ART_TARGET_NON_DEBUG_CFLAGS)
     endif
   else # host
+    LOCAL_CLANG := $(ART_HOST_CLANG)
     LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
     ifeq ($$(art_ndebug_or_debug),debug)
       LOCAL_CFLAGS += $(ART_HOST_DEBUG_CFLAGS)
diff --git a/build/Android.gtest.mk b/build/Android.gtest.mk
index c8aded5..f13c47e 100644
--- a/build/Android.gtest.mk
+++ b/build/Android.gtest.mk
@@ -60,6 +60,7 @@
 
   LOCAL_CFLAGS := $(ART_TEST_CFLAGS)
   ifeq ($$(art_target_or_host),target)
+    LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS) $(ART_TARGET_DEBUG_CFLAGS)
     LOCAL_SHARED_LIBRARIES += libdl libicuuc libicui18n libnativehelper libstlport libz libcutils
     LOCAL_STATIC_LIBRARIES += libgtest
@@ -69,6 +70,7 @@
     art_gtest_exe := $$(LOCAL_MODULE_PATH)/$$(LOCAL_MODULE)
     ART_TARGET_TEST_EXECUTABLES += $$(art_gtest_exe)
   else # host
+    LOCAL_CLANG := $(ART_HOST_CLANG)
     LOCAL_CFLAGS += $(ART_HOST_CFLAGS) $(ART_HOST_DEBUG_CFLAGS)
     LOCAL_SHARED_LIBRARIES += libicuuc-host libicui18n-host libnativehelper libz-host
     LOCAL_STATIC_LIBRARIES += libcutils
diff --git a/build/Android.libart-compiler.mk b/build/Android.libart-compiler.mk
index b9235d8..5e34573 100644
--- a/build/Android.libart-compiler.mk
+++ b/build/Android.libart-compiler.mk
@@ -113,8 +113,10 @@
 
   LOCAL_CFLAGS := $$(LIBART_COMPILER_CFLAGS)
   ifeq ($$(art_target_or_host),target)
+    LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
   else # host
+    LOCAL_CLANG := $(ART_HOST_CLANG)
     LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
   endif
 
diff --git a/build/Android.libart.mk b/build/Android.libart.mk
index cbc78b2..74e9b21 100644
--- a/build/Android.libart.mk
+++ b/build/Android.libart.mk
@@ -70,8 +70,10 @@
 
   LOCAL_CFLAGS := $(LIBART_CFLAGS)
   ifeq ($$(art_target_or_host),target)
+    LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS += $(ART_TARGET_CFLAGS)
   else # host
+    LOCAL_CLANG := $(ART_HOST_CLANG)
     LOCAL_CFLAGS += $(ART_HOST_CFLAGS)
   endif
   ifeq ($$(art_ndebug_or_debug),debug)
diff --git a/build/Android.libarttest.mk b/build/Android.libarttest.mk
index 855523b..50b9a10 100644
--- a/build/Android.libarttest.mk
+++ b/build/Android.libarttest.mk
@@ -38,12 +38,14 @@
   LOCAL_SHARED_LIBRARIES := libartd
   LOCAL_C_INCLUDES += $(ART_C_INCLUDES)
   ifeq ($$(art_target_or_host),target)
+    LOCAL_CLANG := $(ART_TARGET_CLANG)
     LOCAL_CFLAGS := $(ART_TARGET_CFLAGS) $(ART_TARGET_DEBUG_CFLAGS)
     LOCAL_SHARED_LIBRARIES += libdl libstlport
     LOCAL_STATIC_LIBRARIES := libgtest
     LOCAL_MODULE_PATH := $(ART_TEST_OUT)
     include $(BUILD_SHARED_LIBRARY)
   else # host
+    LOCAL_CLANG := $(ART_HOST_CLANG)
     LOCAL_CFLAGS := $(ART_HOST_CFLAGS) $(ART_HOST_DEBUG_CFLAGS)
     LOCAL_LDLIBS := -ldl -lpthread
     ifeq ($(HOST_OS),linux)