Use newest clang static analyzers.

* When WITH_STATIC_ANALYZER is set and non-zero, and clang compiler is used,
  call new clang ccc-analyzer or c++-analyzer.
* Otherwise, if WITH_SYNTAX_CHECK is set and non-zero,
  call compiler with -fsyntax-only.
* Replace "--sysroot=path" with "--sysroot path", to work with ccc-analyzer.
* ccc-analyzer executes the original compilation command to generate
  object files before calling clang with --analyze to do static analysis.
* When clang is called with --analyze, macro __clang_analyzer__ is defined.

BUG: 13287788

Change-Id: I5edb25b52998d871385dd000778db2ce83224078
diff --git a/core/binary.mk b/core/binary.mk
index 4f5ced5..1c7ffda 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -402,6 +402,12 @@
   LOCAL_NO_STATIC_ANALYZER := true
 endif
 
+# Clang does not recognize all gcc flags.
+# Use static analyzer only if clang is used.
+ifneq ($(my_clang),true)
+  LOCAL_NO_STATIC_ANALYZER := true
+endif
+
 ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
   my_syntax_arch := host
 else
@@ -416,13 +422,16 @@
   endif
   my_cc := $(my_cc_wrapper) $(my_cc)
 endif
+
 ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
-  my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(my_cc)"
+  my_cc := CCC_CC=$(CLANG) CLANG=$(CLANG) \
+           $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer
 else
 ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
-  my_cc := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(my_cc)"
+  my_cc := $(my_cc) -fsyntax-only
 endif
 endif
+
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(my_cc)
 
 ifeq ($(strip $(my_cxx)),)
@@ -433,13 +442,16 @@
   endif
   my_cxx := $(my_cxx_wrapper) $(my_cxx)
 endif
+
 ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
-  my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(my_cxx)"
+  my_cxx := CCC_CXX=$(CLANG_CXX) CLANG_CXX=$(CLANG_CXX) \
+            $(SYNTAX_TOOLS_PREFIX)/c++-analyzer
 else
 ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
-  my_cxx := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(my_cxx)"
+  my_cxx := $(my_cxx) -fsyntax-only
 endif
 endif
+
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_LINKER := $(my_linker)
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(my_cxx)
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CLANG := $(my_clang)