Add "WITH_STATIC_ANALYZER=1 m/mm/mmm/mma/mmma ..."

The new option WITH_STATIC_ANALYZER=1 instructs build system to
run static analyzer via "clang --analyze" on a successful build.
If analyzer finds any issue, instruction to open report is displayed.
See http://clang-analyzer.llvm.org/scan-build.html for details.

WITH_STATIC_ANALYZER trumps WITH_SYNTAX_CHECK if both exist.

Project use lots of GCC extensions (eg. nested function) not supported
by clang may opt out by adding LOCAL_NO_STATIC_ANALYZER:=true

Change-Id: I9970560560bd52ce5f0fd7129c3488629627c735
diff --git a/core/binary.mk b/core/binary.mk
index 75f6ede..f40c444 100644
--- a/core/binary.mk
+++ b/core/binary.mk
@@ -174,6 +174,10 @@
   LOCAL_NO_SYNTAX_CHECK := true
 endif
 
+ifeq ($(strip $(WITH_STATIC_ANALYZER)),)
+  LOCAL_NO_STATIC_ANALYZER := true
+endif
+
 ifneq ($(strip $(LOCAL_IS_HOST_MODULE)),)
   my_syntax_arch := host
 else
@@ -187,9 +191,13 @@
     LOCAL_CC := $($(my_prefix)CC)
   endif
 endif
+ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
+  LOCAL_CC := $(SYNTAX_TOOLS_PREFIX)/ccc-analyzer $(my_syntax_arch) "$(LOCAL_CC)"
+else
 ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
   LOCAL_CC := $(SYNTAX_TOOLS_PREFIX)/ccc-syntax $(my_syntax_arch) "$(LOCAL_CC)"
 endif
+endif
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CC := $(LOCAL_CC)
 
 ifeq ($(strip $(LOCAL_CXX)),)
@@ -199,9 +207,13 @@
     LOCAL_CXX := $($(my_prefix)CXX)
   endif
 endif
+ifneq ($(LOCAL_NO_STATIC_ANALYZER),true)
+  LOCAL_CXX := $(SYNTAX_TOOLS_PREFIX)/cxx-analyzer $(my_syntax_arch) "$(LOCAL_CXX)"
+else
 ifneq ($(LOCAL_NO_SYNTAX_CHECK),true)
   LOCAL_CXX := $(SYNTAX_TOOLS_PREFIX)/cxx-syntax $(my_syntax_arch) "$(LOCAL_CXX)"
 endif
+endif
 $(LOCAL_INTERMEDIATE_TARGETS): PRIVATE_CXX := $(LOCAL_CXX)
 
 # TODO: support a mix of standard extensions so that this isn't necessary