lint support.

Bug: 6167394
$make lint-<app-name>       # to lint on a single module
$make lintall               # to lint on all packages in the source
                              tree.

Change-Id: I4decc76fb75793ce44809232b0ec72b766fbb434
diff --git a/core/clear_vars.mk b/core/clear_vars.mk
index f3929ad..ef0b031 100644
--- a/core/clear_vars.mk
+++ b/core/clear_vars.mk
@@ -125,6 +125,7 @@
 # Whether to keep the generated R/Manifest classes when building static Java library
 # with Android resource. false(default), or true
 LOCAL_KEEP_R_CLASS_IN_STATIC_JAVA_LIBRARY:=
+LOCAL_LINT_FLAGS:=
 
 # Trim MAKEFILE_LIST so that $(call my-dir) doesn't need to
 # iterate over thousands of entries every time.
diff --git a/core/config.mk b/core/config.mk
index b0b5082..2af4f6e 100644
--- a/core/config.mk
+++ b/core/config.mk
@@ -295,6 +295,7 @@
 LLVM_RS_LINK := $(HOST_OUT_EXECUTABLES)/llvm-rs-link$(HOST_EXECUTABLE_SUFFIX)
 DEXOPT := $(HOST_OUT_EXECUTABLES)/dexopt$(HOST_EXECUTABLE_SUFFIX)
 DEXPREOPT := dalvik/tools/dex-preopt
+LINT := prebuilts/sdk/tools/lint
 
 # ACP is always for the build OS, not for the host OS
 ACP := $(BUILD_OUT_EXECUTABLES)/acp$(BUILD_EXECUTABLE_SUFFIX)
diff --git a/core/main.mk b/core/main.mk
index 1ab9b6c..317660f 100644
--- a/core/main.mk
+++ b/core/main.mk
@@ -817,6 +817,8 @@
 )
 endif
 
+.PHONY: lintall
+
 .PHONY: samplecode
 sample_MODULES := $(sort $(call get-tagged-modules,samples))
 sample_APKS_DEST_PATH := $(TARGET_COMMON_OUT_ROOT)/samples
diff --git a/core/package.mk b/core/package.mk
index 45f1fcf..ebc5378 100644
--- a/core/package.mk
+++ b/core/package.mk
@@ -416,4 +416,14 @@
 
 PACKAGES := $(PACKAGES) $(LOCAL_PACKAGE_NAME)
 
+# Lint phony targets
+.PHONY: lint-$(LOCAL_PACKAGE_NAME)
+lint-$(LOCAL_PACKAGE_NAME): PRIVATE_PATH := $(LOCAL_PATH)
+lint-$(LOCAL_PACKAGE_NAME): PRIVATE_LINT_FLAGS := $(LOCAL_LINT_FLAGS)
+lint-$(LOCAL_PACKAGE_NAME) :
+	@echo lint $(PRIVATE_PATH)
+	$(LINT) $(PRIVATE_LINT_FLAGS) $(PRIVATE_PATH)
+
+lintall : lint-$(LOCAL_PACKAGE_NAME)
+
 endif # skip_definition