Merge "Hardcode CLANG_ROOT_PATH"
diff --git a/clang-device-build.mk b/clang-device-build.mk
index cc490e9..4d30ed8 100644
--- a/clang-device-build.mk
+++ b/clang-device-build.mk
@@ -41,5 +41,5 @@
 	-I $(LLVM_ROOT_PATH)/lib/Target	\
 	$(if $(strip $(CLANG_ROOT_PATH)),-I $(CLANG_ROOT_PATH)/include,)	\
 	-gen-$(strip $(1))	\
-	-o $@ $<
+	-d $@.d -o $@ $<
 endef
diff --git a/clang-host-build.mk b/clang-host-build.mk
index 618ed4c..a6dab2f 100644
--- a/clang-host-build.mk
+++ b/clang-host-build.mk
@@ -52,5 +52,5 @@
 	-I $(LLVM_ROOT_PATH)/lib/Target	\
 	$(if $(strip $(CLANG_ROOT_PATH)),-I $(CLANG_ROOT_PATH)/include,)	\
 	-gen-$(strip $(1))	\
-	-o $@ $<
+	-d $@.d -o $@ $<
 endef
diff --git a/clang-tblgen-rules.mk b/clang-tblgen-rules.mk
index 8e408a2..ba28e10 100644
--- a/clang-tblgen-rules.mk
+++ b/clang-tblgen-rules.mk
@@ -13,234 +13,199 @@
 	$(call transform-device-clang-td-to-out,$(1)))
 endef
 
-define transform-td-to-out
-$(if $(LOCAL_IS_HOST_MODULE),	\
-	$(call transform-host-td-to-out,$(1)),	\
-	$(call transform-device-td-to-out,$(1)))
+# $(1): an output file
+# $(2): an input .td file
+# $(3): a parameter passed to transform-td-to-out
+# You must call this with $(eval).
+define define-clang-tblgen-rule
+LOCAL_GENERATED_SOURCES += $(1)
+$(1): TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
+$(1): $(2) $(CLANG_TBLGEN)
+	$$(call transform-clang-td-to-out,$(3))
+$$(call include-depfile, $(1).d, $(1))
 endef
 
 generated_sources := $(call local-generated-sources-dir)
 
-ifneq ($(findstring AttrDump.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/AttrDump.inc
-$(generated_sources)/include/clang/AST/AttrDump.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/AttrDump.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-dump)
+ifneq ($(filter AttrDump.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/AttrDump.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-dump))
 endif
 
-ifneq ($(findstring AttrImpl.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/AttrImpl.inc
-$(generated_sources)/include/clang/AST/AttrImpl.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/AttrImpl.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-impl)
+ifneq ($(filter AttrImpl.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/AttrImpl.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-impl))
 endif
 
-ifneq ($(findstring AttrHasAttributeImpl.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Basic/AttrHasAttributeImpl.inc
-$(generated_sources)/include/clang/Basic/AttrHasAttributeImpl.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Basic/AttrHasAttributeImpl.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-has-attribute-impl)
+ifneq ($(filter AttrHasAttributeImpl.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Basic/AttrHasAttributeImpl.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-has-attribute-impl))
 endif
 
-ifneq ($(findstring AttrList.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Basic/AttrList.inc
-$(generated_sources)/include/clang/Basic/AttrList.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Basic/AttrList.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-list)
+ifneq ($(filter AttrList.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Basic/AttrList.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-list))
 endif
 
-ifneq ($(findstring AttrSpellingListIndex.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Sema/AttrSpellingListIndex.inc
-$(generated_sources)/include/clang/Sema/AttrSpellingListIndex.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Sema/AttrSpellingListIndex.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-spelling-index)
+ifneq ($(filter AttrSpellingListIndex.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Sema/AttrSpellingListIndex.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-spelling-index))
 endif
 
-ifneq ($(findstring AttrPCHRead.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Serialization/AttrPCHRead.inc
-$(generated_sources)/include/clang/Serialization/AttrPCHRead.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Serialization/AttrPCHRead.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-pch-read)
+ifneq ($(filter AttrPCHRead.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Serialization/AttrPCHRead.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-pch-read))
 endif
 
-ifneq ($(findstring AttrPCHWrite.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Serialization/AttrPCHWrite.inc
-$(generated_sources)/include/clang/Serialization/AttrPCHWrite.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Serialization/AttrPCHWrite.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-pch-write)
+ifneq ($(filter AttrPCHWrite.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Serialization/AttrPCHWrite.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-pch-write))
 endif
 
-ifneq ($(findstring Attrs.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/Attrs.inc
-$(generated_sources)/include/clang/AST/Attrs.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/Attrs.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-classes)
+ifneq ($(filter Attrs.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/Attrs.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-classes))
 endif
 
-ifneq ($(findstring AttrParserStringSwitches.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Parse/AttrParserStringSwitches.inc
-$(generated_sources)/include/clang/Parse/AttrParserStringSwitches.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Parse/AttrParserStringSwitches.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-parser-string-switches)
+ifneq ($(filter AttrParserStringSwitches.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Parse/AttrParserStringSwitches.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-parser-string-switches))
 endif
 
-ifneq ($(findstring AttrVisitor.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/AttrVisitor.inc
-$(generated_sources)/include/clang/AST/AttrVisitor.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/AttrVisitor.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-ast-visitor)
+ifneq ($(filter AttrVisitor.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/AttrVisitor.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-ast-visitor))
 endif
 
-ifneq ($(findstring AttrParsedAttrKinds.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Sema/AttrParsedAttrKinds.inc
-$(generated_sources)/include/clang/Sema/AttrParsedAttrKinds.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Sema/AttrParsedAttrKinds.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-parsed-attr-kinds)
+ifneq ($(filter AttrParsedAttrKinds.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Sema/AttrParsedAttrKinds.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-parsed-attr-kinds))
 endif
 
-ifneq ($(findstring AttrParsedAttrImpl.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Sema/AttrParsedAttrImpl.inc
-$(generated_sources)/include/clang/Sema/AttrParsedAttrImpl.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Sema/AttrParsedAttrImpl.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-parsed-attr-impl)
+ifneq ($(filter AttrParsedAttrImpl.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Sema/AttrParsedAttrImpl.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-parsed-attr-impl))
 endif
 
-ifneq ($(findstring AttrParsedAttrList.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Sema/AttrParsedAttrList.inc
-$(generated_sources)/include/clang/Sema/AttrParsedAttrList.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Sema/AttrParsedAttrList.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-parsed-attr-list)
+ifneq ($(filter AttrParsedAttrList.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Sema/AttrParsedAttrList.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-parsed-attr-list))
 endif
 
-ifneq ($(findstring AttrTemplateInstantiate.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Sema/AttrTemplateInstantiate.inc
-$(generated_sources)/include/clang/Sema/AttrTemplateInstantiate.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Sema/AttrTemplateInstantiate.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-attr-template-instantiate)
+ifneq ($(filter AttrTemplateInstantiate.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Sema/AttrTemplateInstantiate.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Attr.td,clang-attr-template-instantiate))
 endif
 
-ifneq ($(findstring Checkers.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/Checkers.inc
-$(generated_sources)/Checkers.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/Checkers.inc: \
-  $(CLANG_ROOT_PATH)/lib/StaticAnalyzer/Checkers/Checkers.td \
-  $(CLANG_ROOT_PATH)/include/clang/StaticAnalyzer/Checkers/CheckerBase.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-sa-checkers)
+ifneq ($(filter Checkers.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/Checkers.inc, \
+    $(CLANG_ROOT_PATH)/lib/StaticAnalyzer/Checkers/Checkers.td,clang-sa-checkers))
 endif
 
-ifneq ($(findstring CommentCommandInfo.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/CommentCommandInfo.inc
-$(generated_sources)/include/clang/AST/CommentCommandInfo.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/CommentCommandInfo.inc: \
-  $(CLANG_ROOT_PATH)/include/clang/AST/CommentCommands.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-comment-command-info)
+ifneq ($(filter CommentCommandInfo.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/CommentCommandInfo.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/AST/CommentCommands.td,clang-comment-command-info))
 endif
 
-ifneq ($(findstring CommentCommandList.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/CommentCommandList.inc
-$(generated_sources)/include/clang/AST/CommentCommandList.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/CommentCommandList.inc: \
-  $(CLANG_ROOT_PATH)/include/clang/AST/CommentCommands.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-comment-command-list)
+ifneq ($(filter CommentCommandList.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/CommentCommandList.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/AST/CommentCommands.td,clang-comment-command-list))
 endif
 
-ifneq ($(findstring CommentHTMLNamedCharacterReferences.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/CommentHTMLNamedCharacterReferences.inc
-$(generated_sources)/include/clang/AST/CommentHTMLNamedCharacterReferences.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/CommentHTMLNamedCharacterReferences.inc: \
-  $(CLANG_ROOT_PATH)/include/clang/AST/CommentHTMLNamedCharacterReferences.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-comment-html-named-character-references)
+ifneq ($(filter CommentHTMLNamedCharacterReferences.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/CommentHTMLNamedCharacterReferences.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/AST/CommentHTMLNamedCharacterReferences.td,clang-comment-html-named-character-references))
 endif
 
-ifneq ($(findstring CommentHTMLTagsProperties.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/CommentHTMLTagsProperties.inc
-$(generated_sources)/include/clang/AST/CommentHTMLTagsProperties.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/CommentHTMLTagsProperties.inc: \
-  $(CLANG_ROOT_PATH)/include/clang/AST/CommentHTMLTags.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-comment-html-tags-properties)
+ifneq ($(filter CommentHTMLTagsProperties.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/CommentHTMLTagsProperties.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/AST/CommentHTMLTags.td,clang-comment-html-tags-properties))
 endif
 
-ifneq ($(findstring CommentHTMLTags.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/CommentHTMLTags.inc
-$(generated_sources)/include/clang/AST/CommentHTMLTags.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/CommentHTMLTags.inc: \
-  $(CLANG_ROOT_PATH)/include/clang/AST/CommentHTMLTags.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-comment-html-tags)
+ifneq ($(filter CommentHTMLTags.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/CommentHTMLTags.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/AST/CommentHTMLTags.td,clang-comment-html-tags))
 endif
 
-ifneq ($(findstring CommentNodes.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/CommentNodes.inc
-$(generated_sources)/include/clang/AST/CommentNodes.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/CommentNodes.inc: \
-  $(CLANG_ROOT_PATH)/include/clang/Basic/CommentNodes.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-comment-nodes)
+ifneq ($(filter CommentNodes.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/CommentNodes.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/CommentNodes.td,clang-comment-nodes))
 endif
 
-ifneq ($(filter Diagnostic%Kinds.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(addprefix $(generated_sources)/include/clang/Basic/,$(filter Diagnostic%Kinds.inc,$(TBLGEN_TABLES)))
-$(generated_sources)/include/clang/Basic/Diagnostic%Kinds.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Basic/Diagnostic%Kinds.inc: \
-  $(CLANG_ROOT_PATH)/include/clang/Basic/Diagnostic.td \
-  $(CLANG_ROOT_PATH)/include/clang/Basic/Diagnostic%Kinds.td \
-  $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-diags-defs -clang-component=$(patsubst Diagnostic%Kinds.inc,%,$(@F)))
+$(foreach genfile,$(filter Diagnostic%Kinds.inc,$(TBLGEN_TABLES)), \
+    $(eval $(call define-clang-tblgen-rule, \
+        $(generated_sources)/include/clang/Basic/$(genfile), \
+        $(CLANG_ROOT_PATH)/include/clang/Basic/Diagnostic.td,clang-diags-defs \
+        -clang-component=$(patsubst Diagnostic%Kinds.inc,%,$(genfile)))))
+
+ifneq ($(filter DiagnosticGroups.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Basic/DiagnosticGroups.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Diagnostic.td,clang-diag-groups))
 endif
 
-ifneq ($(findstring DiagnosticGroups.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Basic/DiagnosticGroups.inc
-$(generated_sources)/include/clang/Basic/DiagnosticGroups.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Basic/DiagnosticGroups.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Diagnostic.td $(CLANG_ROOT_PATH)/include/clang/Basic/DiagnosticGroups.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-diag-groups)
+ifneq ($(filter DiagnosticIndexName.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Basic/DiagnosticIndexName.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/Diagnostic.td,clang-diag-groups))
 endif
 
-ifneq ($(findstring DiagnosticIndexName.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Basic/DiagnosticIndexName.inc
-$(generated_sources)/include/clang/Basic/DiagnosticIndexName.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Basic/DiagnosticIndexName.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/Diagnostic.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-diag-groups)
+ifneq ($(filter DeclNodes.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/DeclNodes.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/DeclNodes.td,clang-decl-nodes))
 endif
 
-ifneq ($(findstring DeclNodes.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/DeclNodes.inc
-$(generated_sources)/include/clang/AST/DeclNodes.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/DeclNodes.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/DeclNodes.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-decl-nodes)
+ifneq ($(filter StmtNodes.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/AST/StmtNodes.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/StmtNodes.td,clang-stmt-nodes))
 endif
 
-ifneq ($(findstring StmtNodes.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/AST/StmtNodes.inc
-$(generated_sources)/include/clang/AST/StmtNodes.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/AST/StmtNodes.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/StmtNodes.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,clang-stmt-nodes)
+ifneq ($(filter arm_neon.inc,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Basic/arm_neon.inc, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/arm_neon.td,arm-neon-sema))
 endif
 
-ifneq ($(findstring arm_neon.inc,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Basic/arm_neon.inc
-$(generated_sources)/include/clang/Basic/arm_neon.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Basic/arm_neon.inc: $(CLANG_ROOT_PATH)/include/clang/Basic/arm_neon.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,arm-neon-sema)
-endif
-
-ifneq ($(findstring Options.inc,$(TBLGEN_TABLES)),)
+ifneq ($(filter Options.inc,$(TBLGEN_TABLES)),)
 LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Driver/Options.inc
+# We cannot use define-tblgen-rule in external/llvm/llvm-tblgen-rules.mk
+# as define-tblgen-rule may be not yet. We use transform-td-to-out,
+# which is evaluated at recipe-evaluation-time and is always available.
 $(generated_sources)/include/clang/Driver/Options.inc: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Driver/Options.inc: $(CLANG_ROOT_PATH)/include/clang/Driver/Options.td $(LLVM_ROOT_PATH)/include/llvm/Option/OptParser.td $(CLANG_ROOT_PATH)/include/clang/Driver/CC1Options.td \
-    $(CLANG_TBLGEN) $(LLVM_TBLGEN)
+$(generated_sources)/include/clang/Driver/Options.inc: $(CLANG_ROOT_PATH)/include/clang/Driver/Options.td $(CLANG_TBLGEN) $(LLVM_TBLGEN)
 	$(call transform-td-to-out,opt-parser-defs)
+$(call include-depfile, \
+    $(generated_sources)/include/clang/Driver/Options.inc.d, \
+    $(generated_sources)/include/clang/Driver/Options.inc)
 endif
 
-ifneq ($(findstring arm_neon.h,$(TBLGEN_TABLES)),)
-LOCAL_GENERATED_SOURCES += $(generated_sources)/include/clang/Basic/arm_neon.h
-$(generated_sources)/include/clang/Basic/arm_neon.h: TBLGEN_LOCAL_MODULE := $(LOCAL_MODULE)
-$(generated_sources)/include/clang/Basic/arm_neon.h: $(CLANG_ROOT_PATH)/include/clang/Basic/arm_neon.td $(CLANG_TBLGEN)
-	$(call transform-clang-td-to-out,arm-neon)
+ifneq ($(filter arm_neon.h,$(TBLGEN_TABLES)),)
+$(eval $(call define-clang-tblgen-rule, \
+    $(generated_sources)/include/clang/Basic/arm_neon.h, \
+    $(CLANG_ROOT_PATH)/include/clang/Basic/arm_neon.td,arm-neon))
 endif
 
 LOCAL_C_INCLUDES += $(generated_sources)/include
diff --git a/lib/Frontend/Android.mk b/lib/Frontend/Android.mk
index 9536a8e..aae042d 100644
--- a/lib/Frontend/Android.mk
+++ b/lib/Frontend/Android.mk
@@ -17,6 +17,7 @@
   DiagnosticLexKinds.inc \
   DiagnosticSemaKinds.inc \
   DeclNodes.inc \
+  Options.inc \
   StmtNodes.inc
 
 clang_frontend_SRC_FILES := \
diff --git a/lib/FrontendTool/Android.mk b/lib/FrontendTool/Android.mk
index 60bc981..37830db 100644
--- a/lib/FrontendTool/Android.mk
+++ b/lib/FrontendTool/Android.mk
@@ -15,6 +15,7 @@
   DiagnosticFrontendKinds.inc \
   CC1Options.inc \
   CommentCommandList.inc \
+  Options.inc \
   StmtNodes.inc
 
 clang_frontend_tool_SRC_FILES := \
diff --git a/tools/driver/Android.mk b/tools/driver/Android.mk
index 9e3d0d7..bd051ac 100644
--- a/tools/driver/Android.mk
+++ b/tools/driver/Android.mk
@@ -14,7 +14,8 @@
   DiagnosticDriverKinds.inc \
   DiagnosticFrontendKinds.inc \
   CC1Options.inc \
-  CC1AsOptions.inc
+  CC1AsOptions.inc \
+  Options.inc
 
 clang_SRC_FILES := \
   cc1_main.cpp \