git: 8f391d909808 - main - Rework {clang,lldb,llvm}-tblgen invocations to add --write-if-changed

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Wed, 29 Mar 2023 17:50:05 UTC
The branch main has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=8f391d9098083044793ff036dff8c96930fb1553

commit 8f391d9098083044793ff036dff8c96930fb1553
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-03-29 17:48:43 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-03-29 17:49:49 +0000

    Rework {clang,lldb,llvm}-tblgen invocations to add --write-if-changed
    
    This flag ensures that the tblgen tools do not actually touch the
    produced .inc file, if there are no changes to the contents. In turn,
    this may prevent a number of rebuilds of files that include such .inc
    files, saving build time.
    
    While here, ensure that the shell invocations to locate the used tblgen
    binary do not show unnecessary error messages.
    
    Reported by:    des
    MFC after:      1 week
---
 lib/clang/clang.pre.mk                 |   7 +-
 lib/clang/headers/Makefile             |  12 +-
 lib/clang/libclang/Makefile            | 370 ++++++++++++++++-----------------
 lib/clang/liblldb/Makefile             |  21 +-
 lib/clang/libllvm/Makefile             |  58 +++---
 lib/clang/lldb.pre.mk                  |   6 +-
 lib/clang/llvm.pre.mk                  |   9 +-
 usr.bin/clang/lld/Makefile             |  11 +-
 usr.bin/clang/lldb-server/Makefile     |  11 +-
 usr.bin/clang/lldb/Makefile            |  11 +-
 usr.bin/clang/llvm-cxxfilt/Makefile    |  11 +-
 usr.bin/clang/llvm-dwarfutil/Makefile  |  11 +-
 usr.bin/clang/llvm-nm/Makefile         |  11 +-
 usr.bin/clang/llvm-objcopy/Makefile    |   4 +-
 usr.bin/clang/llvm-objdump/Makefile    |   4 +-
 usr.bin/clang/llvm-readobj/Makefile    |  11 +-
 usr.bin/clang/llvm-size/Makefile       |  11 +-
 usr.bin/clang/llvm-strings/Makefile    |  11 +-
 usr.bin/clang/llvm-symbolizer/Makefile |  11 +-
 19 files changed, 273 insertions(+), 328 deletions(-)

diff --git a/lib/clang/clang.pre.mk b/lib/clang/clang.pre.mk
index 9ef401645f14..41071681851e 100644
--- a/lib/clang/clang.pre.mk
+++ b/lib/clang/clang.pre.mk
@@ -2,7 +2,8 @@
 
 .include "llvm.pre.mk"
 
-CLANG_SRCS=	${LLVM_BASE}/clang
+CLANG_SRCS=		${LLVM_BASE}/clang
 
-CLANG_TBLGEN?=	clang-tblgen
-CLANG_TBLGEN_BIN!= which ${CLANG_TBLGEN}
+CLANG_TBLGEN?=		clang-tblgen
+CLANG_TBLGEN_BIN!=	which ${CLANG_TBLGEN} || echo __nonexistent_clang_tblgen__
+CLANG_TBLGEN_OPTS?=	--write-if-changed
diff --git a/lib/clang/headers/Makefile b/lib/clang/headers/Makefile
index df53b7dc7ea0..8a4a778f43e2 100644
--- a/lib/clang/headers/Makefile
+++ b/lib/clang/headers/Makefile
@@ -200,17 +200,17 @@ PPC+=		ppc_wrappers/xmmintrin.h
 .for hdr in bf16/bf16 cde/cde-header fp16/fp16 mve/mve-header neon/neon \
 	sve/sve-header
 arm_${hdr:H}.h: ${CLANG_SRCS}/include/clang/Basic/arm_${hdr:H}.td
-	${CLANG_TBLGEN} -gen-arm-${hdr:T} \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_${hdr:H}.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-${hdr:T} \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 GENINCS+=	arm_${hdr:H}.h
 .endfor
 
 .for hdr in vector/vector-header
 riscv_${hdr:H}.h: ${CLANG_SRCS}/include/clang/Basic/riscv_${hdr:H}.td
-	${CLANG_TBLGEN} -gen-riscv-${hdr:T} \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/riscv_${hdr:H}.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-riscv-${hdr:T} \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 GENINCS+=	riscv_${hdr:H}.h
 .endfor
 
diff --git a/lib/clang/libclang/Makefile b/lib/clang/libclang/Makefile
index ac85db06ed58..5e493e3509c9 100644
--- a/lib/clang/libclang/Makefile
+++ b/lib/clang/libclang/Makefile
@@ -760,358 +760,339 @@ SRCS_ALL+=	${SRCS_LDB}
 SRCS+=		${SRCS_ALL:O}
 
 clang/AST/AbstractBasicReader.inc: \
-	${CLANG_SRCS}/include/clang/AST/PropertiesBase.td
-	${CLANG_TBLGEN} -gen-clang-basic-reader \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/PropertiesBase.td
+    ${CLANG_SRCS}/include/clang/AST/PropertiesBase.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-basic-reader \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AbstractBasicReader.inc
 
 clang/AST/AbstractBasicWriter.inc: \
-	${CLANG_SRCS}/include/clang/AST/PropertiesBase.td
-	${CLANG_TBLGEN} -gen-clang-basic-writer \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/PropertiesBase.td
+    ${CLANG_SRCS}/include/clang/AST/PropertiesBase.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-basic-writer \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AbstractBasicWriter.inc
 
 clang/AST/AbstractTypeReader.inc: \
-	${CLANG_SRCS}/include/clang/AST/TypeProperties.td
-	${CLANG_TBLGEN} -gen-clang-type-reader \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/TypeProperties.td
+    ${CLANG_SRCS}/include/clang/AST/TypeProperties.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-type-reader \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AbstractTypeReader.inc
 
 clang/AST/AbstractTypeWriter.inc: \
-	${CLANG_SRCS}/include/clang/AST/TypeProperties.td
-	${CLANG_TBLGEN} -gen-clang-type-writer \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/TypeProperties.td
+    ${CLANG_SRCS}/include/clang/AST/TypeProperties.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-type-writer \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AbstractTypeWriter.inc
 
 clang/AST/AttrImpl.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-impl \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-impl \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AttrImpl.inc
 
 clang/AST/AttrNodeTraverse.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-node-traverse \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-node-traverse \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AttrNodeTraverse.inc
 
 clang/AST/AttrTextNodeDump.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-text-node-dump \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-text-node-dump \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AttrTextNodeDump.inc
 
 clang/AST/AttrVisitor.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-ast-visitor \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-ast-visitor \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/AttrVisitor.inc
 
 clang/AST/Attrs.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-classes \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-classes \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/Attrs.inc
 
 clang/AST/CommentCommandInfo.inc: \
-	${CLANG_SRCS}/include/clang/AST/CommentCommands.td
-	${CLANG_TBLGEN} -gen-clang-comment-command-info \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/CommentCommands.td
+    ${CLANG_SRCS}/include/clang/AST/CommentCommands.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-comment-command-info \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/CommentCommandInfo.inc
 
 clang/AST/CommentCommandList.inc: \
-	${CLANG_SRCS}/include/clang/AST/CommentCommands.td
-	${CLANG_TBLGEN} -gen-clang-comment-command-list \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/CommentCommands.td
+    ${CLANG_SRCS}/include/clang/AST/CommentCommands.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-comment-command-list \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/CommentCommandList.inc
 
 clang/AST/CommentHTMLNamedCharacterReferences.inc: \
-	${CLANG_SRCS}/include/clang/AST/CommentHTMLNamedCharacterReferences.td
-	${CLANG_TBLGEN} -gen-clang-comment-html-named-character-references \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/CommentHTMLNamedCharacterReferences.td
+    ${CLANG_SRCS}/include/clang/AST/CommentHTMLNamedCharacterReferences.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-comment-html-named-character-references \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/CommentHTMLNamedCharacterReferences.inc
 
 clang/AST/CommentHTMLTags.inc: \
-	${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
-	${CLANG_TBLGEN} -gen-clang-comment-html-tags \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
+    ${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-comment-html-tags \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/CommentHTMLTags.inc
 
 clang/AST/CommentHTMLTagsProperties.inc: \
-	${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
-	${CLANG_TBLGEN} -gen-clang-comment-html-tags-properties \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
+    ${CLANG_SRCS}/include/clang/AST/CommentHTMLTags.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-comment-html-tags-properties -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/CommentHTMLTagsProperties.inc
 
 clang/AST/CommentNodes.inc: ${CLANG_SRCS}/include/clang/Basic/CommentNodes.td
-	${CLANG_TBLGEN} -gen-clang-comment-nodes \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/CommentNodes.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-comment-nodes \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/CommentNodes.inc
 
 clang/AST/DeclNodes.inc: ${CLANG_SRCS}/include/clang/Basic/DeclNodes.td
-	${CLANG_TBLGEN} -gen-clang-decl-nodes \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/DeclNodes.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-decl-nodes \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/DeclNodes.inc
 
 clang/AST/StmtDataCollectors.inc: \
-	${CLANG_SRCS}/include/clang/AST/StmtDataCollectors.td
-	${CLANG_TBLGEN} -gen-clang-data-collectors \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/AST/StmtDataCollectors.td
+    ${CLANG_SRCS}/include/clang/AST/StmtDataCollectors.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-data-collectors \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/StmtDataCollectors.inc
 
 clang/AST/StmtNodes.inc: ${CLANG_SRCS}/include/clang/Basic/StmtNodes.td
-	${CLANG_TBLGEN} -gen-clang-stmt-nodes \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/StmtNodes.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-stmt-nodes \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/StmtNodes.inc
 
 clang/AST/TypeNodes.inc: ${CLANG_SRCS}/include/clang/Basic/TypeNodes.td
-	${CLANG_TBLGEN} -gen-clang-type-nodes \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/TypeNodes.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-type-nodes \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/AST/TypeNodes.inc
 
 clang/Basic/AttrHasAttributeImpl.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-has-attribute-impl \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-has-attribute-impl -I ${CLANG_SRCS}/include \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/AttrHasAttributeImpl.inc
 
 clang/Basic/AttrList.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-list \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-list \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/AttrList.inc
 
-clang/Basic/AttrSubMatchRulesList.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-subject-match-rule-list \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+clang/Basic/AttrSubMatchRulesList.inc: \
+    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-subject-match-rule-list -I ${CLANG_SRCS}/include \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/AttrSubMatchRulesList.inc
 
 .for hdr in \
 	AST Analysis Comment Common CrossTU Driver Frontend Lex Parse \
 	Refactoring Sema Serialization SemaSerialization
 clang/Basic/Diagnostic${hdr}Kinds.inc: \
-	${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
-	${CLANG_TBLGEN} -gen-clang-diags-defs -clang-component=${hdr} \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
+    ${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-diags-defs \
+	    -clang-component=${hdr} -I ${CLANG_SRCS}/include/clang/Basic \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/Diagnostic${hdr}Kinds.inc
 .endfor
 
 clang/Basic/DiagnosticGroups.inc: \
-	${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
-	${CLANG_TBLGEN} -gen-clang-diag-groups \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
+    ${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-diag-groups \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/DiagnosticGroups.inc
 
 clang/Basic/DiagnosticIndexName.inc: \
-	${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
-	${CLANG_TBLGEN} -gen-clang-diags-index-name \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
+    ${CLANG_SRCS}/include/clang/Basic/Diagnostic.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-diags-index-name \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/DiagnosticIndexName.inc
 
 clang/Basic/arm_fp16.inc: ${CLANG_SRCS}/include/clang/Basic/arm_fp16.td
-	${CLANG_TBLGEN} -gen-arm-neon-sema \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_fp16.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-neon-sema \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_fp16.inc
 
 clang/Basic/arm_neon.inc: ${CLANG_SRCS}/include/clang/Basic/arm_neon.td
-	${CLANG_TBLGEN} -gen-arm-neon-sema \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_neon.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-neon-sema \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_neon.inc
 
 clang/Basic/arm_cde_builtins.inc: ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
-	${CLANG_TBLGEN} -gen-arm-cde-builtin-def \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-cde-builtin-def \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_cde_builtins.inc
 
 clang/Basic/arm_cde_builtin_aliases.inc: \
-	${CLANG_SRCS}/include/clang/Basic/arm_cde.td
-	${CLANG_TBLGEN} -gen-arm-cde-builtin-aliases \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
+    ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-cde-builtin-aliases \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_cde_builtin_aliases.inc
 
-clang/Basic/arm_cde_builtin_cg.inc: ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
-	${CLANG_TBLGEN} -gen-arm-cde-builtin-codegen \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
+clang/Basic/arm_cde_builtin_cg.inc: \
+    ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-cde-builtin-codegen \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_cde_builtin_cg.inc
 
 clang/Basic/arm_cde_builtin_sema.inc: \
-	${CLANG_SRCS}/include/clang/Basic/arm_cde.td
-	${CLANG_TBLGEN} -gen-arm-cde-builtin-sema \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
+    ${CLANG_SRCS}/include/clang/Basic/arm_cde.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-cde-builtin-sema \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_cde_builtin_sema.inc
 
 clang/Basic/arm_mve_builtins.inc: ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
-	${CLANG_TBLGEN} -gen-arm-mve-builtin-def \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-mve-builtin-def \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_mve_builtins.inc
 
 clang/Basic/arm_mve_builtin_aliases.inc: \
-	${CLANG_SRCS}/include/clang/Basic/arm_mve.td
-	${CLANG_TBLGEN} -gen-arm-mve-builtin-aliases \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
+    ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-mve-builtin-aliases \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_mve_builtin_aliases.inc
 
-clang/Basic/arm_mve_builtin_cg.inc: ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
-	${CLANG_TBLGEN} -gen-arm-mve-builtin-codegen \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
+clang/Basic/arm_mve_builtin_cg.inc: \
+    ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-mve-builtin-codegen \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_mve_builtin_cg.inc
 
 clang/Basic/arm_mve_builtin_sema.inc: \
-	${CLANG_SRCS}/include/clang/Basic/arm_mve.td
-	${CLANG_TBLGEN} -gen-arm-mve-builtin-sema \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
+    ${CLANG_SRCS}/include/clang/Basic/arm_mve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-mve-builtin-sema \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_mve_builtin_sema.inc
 
 clang/Basic/arm_sve_builtins.inc: ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
-	${CLANG_TBLGEN} -gen-arm-sve-builtins \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-sve-builtins \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_sve_builtins.inc
 
-clang/Basic/arm_sve_builtin_cg.inc: ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
-	${CLANG_TBLGEN} -gen-arm-sve-builtin-codegen \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
+clang/Basic/arm_sve_builtin_cg.inc: \
+    ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-sve-builtin-codegen \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_sve_builtin_cg.inc
 
 clang/Basic/arm_sve_sema_rangechecks.inc: \
-	${CLANG_SRCS}/include/clang/Basic/arm_sve.td
-	${CLANG_TBLGEN} -gen-arm-sve-sema-rangechecks \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
+    ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-sve-sema-rangechecks \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_sve_sema_rangechecks.inc
 
 clang/Basic/arm_sve_typeflags.inc: \
-	${CLANG_SRCS}/include/clang/Basic/arm_sve.td
-	${CLANG_TBLGEN} -gen-arm-sve-typeflags \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
+    ${CLANG_SRCS}/include/clang/Basic/arm_sve.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-arm-sve-typeflags \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/arm_sve_typeflags.inc
 
 clang/Basic/riscv_vector_builtins.inc: \
-	${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
-	${CLANG_TBLGEN} -gen-riscv-vector-builtins \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
+    ${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-riscv-vector-builtins \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/riscv_vector_builtins.inc
 
 clang/Basic/riscv_vector_builtin_cg.inc: \
-	${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
-	${CLANG_TBLGEN} -gen-riscv-vector-builtin-codegen \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
+    ${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-riscv-vector-builtin-codegen \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/riscv_vector_builtin_cg.inc
 
 clang/Basic/riscv_vector_builtin_sema.inc: \
-	${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
-	${CLANG_TBLGEN} -gen-riscv-vector-builtin-sema \
-	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
+    ${CLANG_SRCS}/include/clang/Basic/riscv_vector.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-riscv-vector-builtin-sema \
+	    -I ${CLANG_SRCS}/include/clang/Basic -d ${.TARGET}.d \
+	    -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Basic/riscv_vector_builtin_sema.inc
 
 clang/Parse/AttrParserStringSwitches.inc: \
-	${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-parser-string-switches \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-parser-string-switches -I ${CLANG_SRCS}/include \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Parse/AttrParserStringSwitches.inc
 
 clang/Parse/AttrSubMatchRulesParserStringSwitches.inc: \
-	${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-subject-match-rules-parser-string-switches \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-subject-match-rules-parser-string-switches \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Parse/AttrSubMatchRulesParserStringSwitches.inc
 
 clang/Sema/AttrParsedAttrImpl.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-parsed-attr-impl \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-parsed-attr-impl -I ${CLANG_SRCS}/include \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Sema/AttrParsedAttrImpl.inc
 
 clang/Sema/AttrParsedAttrKinds.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-parsed-attr-kinds \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-parsed-attr-kinds -I ${CLANG_SRCS}/include \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Sema/AttrParsedAttrKinds.inc
 
 clang/Sema/AttrParsedAttrList.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-parsed-attr-list \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-parsed-attr-list -I ${CLANG_SRCS}/include \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Sema/AttrParsedAttrList.inc
 
 clang/Sema/AttrSpellingListIndex.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-spelling-index \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-spelling-index \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Sema/AttrSpellingListIndex.inc
 
 clang/Sema/AttrTemplateInstantiate.inc: \
-	${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-template-instantiate \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} \
+	    --gen-clang-attr-template-instantiate -I ${CLANG_SRCS}/include \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Sema/AttrTemplateInstantiate.inc
 
 clang/Serialization/AttrPCHRead.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-pch-read \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-pch-read \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Serialization/AttrPCHRead.inc
 
 clang/Serialization/AttrPCHWrite.inc: ${CLANG_SRCS}/include/clang/Basic/Attr.td
-	${CLANG_TBLGEN} -gen-clang-attr-pch-write \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Basic/Attr.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-attr-pch-write \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/Serialization/AttrPCHWrite.inc
 
 clang/StaticAnalyzer/Checkers/Checkers.inc: \
-	${CLANG_SRCS}/include/clang/StaticAnalyzer/Checkers/Checkers.td
-	${CLANG_TBLGEN} -gen-clang-sa-checkers \
+    ${CLANG_SRCS}/include/clang/StaticAnalyzer/Checkers/Checkers.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-sa-checkers \
 	    -I ${CLANG_SRCS}/include/clang/StaticAnalyzer/Checkers \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/StaticAnalyzer/Checkers/Checkers.td
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	clang/StaticAnalyzer/Checkers/Checkers.inc
 
 Opcodes.inc: ${CLANG_SRCS}/lib/AST/Interp/Opcodes.td
-	${CLANG_TBLGEN} -gen-clang-opcodes \
-	    -I ${CLANG_SRCS}/include -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/lib/AST/Interp/Opcodes.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-opcodes \
+	    -I ${CLANG_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	Opcodes.inc
 
 OpenCLBuiltins.inc: ${CLANG_SRCS}/lib/Sema/OpenCLBuiltins.td
-	${CLANG_TBLGEN} -gen-clang-opencl-builtins \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/lib/Sema/OpenCLBuiltins.td
+	${CLANG_TBLGEN} ${CLANG_TBLGEN_OPTS} --gen-clang-opencl-builtins \
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	OpenCLBuiltins.inc
 
 ${TGHDRS}: ${CLANG_TBLGEN_BIN}
@@ -1121,10 +1102,9 @@ DPSRCS+=	${TGHDRS}
 CLEANFILES+=	${TGHDRS} ${TGHDRS:C/$/.d/}
 
 clang/Driver/Options.inc: ${CLANG_SRCS}/include/clang/Driver/Options.td
-	${LLVM_TBLGEN} -gen-opt-parser-defs \
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
 	    -I ${LLVM_SRCS}/include -I ${CLANG_SRCS}/include/clang/Driver \
-	    -d ${.TARGET:C/$/.d/} -o ${.TARGET} \
-	    ${CLANG_SRCS}/include/clang/Driver/Options.td
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 LTGHDRS+=	clang/Driver/Options.inc
 
 ${LTGHDRS}: ${LLVM_TBLGEN_BIN}
diff --git a/lib/clang/liblldb/Makefile b/lib/clang/liblldb/Makefile
index 1a1494fd2bfb..2dfb585ee731 100644
--- a/lib/clang/liblldb/Makefile
+++ b/lib/clang/liblldb/Makefile
@@ -700,13 +700,10 @@ SRCS+=		Utility/VMRange.cpp
 SRCS+=		Utility/XcodeSDK.cpp
 SRCS+=		Version/Version.cpp
 
-LLDB_TBLGEN?=	lldb-tblgen
-LLDB_TBLGEN_BIN!= which ${LLDB_TBLGEN}
-
 CommandOptions.inc: ${LLDB_SRCS}/source/Commands/Options.td
-	${LLDB_TBLGEN} -gen-lldb-option-defs \
-	    -I ${LLDB_SRCS}/source/Commands -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${LLDB_SRCS}/source/Commands/Options.td
+	${LLDB_TBLGEN} ${LLDB_TBLGEN_OPTS} --gen-lldb-option-defs \
+	    -I ${LLDB_SRCS}/source/Commands -d ${.TARGET}.d -o ${.TARGET} \
+	    ${.ALLSRC}
 TGHDRS+=	CommandOptions.inc
 
 .for path in \
@@ -717,15 +714,15 @@ TGHDRS+=	CommandOptions.inc
 	Plugins/SymbolFile/DWARF/SymbolFileDWARF \
 	Target/Target
 ${path:T}Properties.inc: ${LLDB_SRCS}/source/${path}Properties.td
-	${LLDB_TBLGEN} -gen-lldb-property-defs \
-	    -I ${LLDB_SRCS}/source/${path:H} -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${LLDB_SRCS}/source/${path}Properties.td
+	${LLDB_TBLGEN} ${LLDB_TBLGEN_OPTS} --gen-lldb-property-defs \
+	    -I ${LLDB_SRCS}/source/${path:H} -d ${.TARGET}.d -o ${.TARGET} \
+	    ${.ALLSRC}
 TGHDRS+=	${path:T}Properties.inc
 
 ${path:T}PropertiesEnum.inc: ${LLDB_SRCS}/source/${path}Properties.td
-	${LLDB_TBLGEN} -gen-lldb-property-enum-defs \
-	    -I ${LLDB_SRCS}/source/${path:H} -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${LLDB_SRCS}/source/${path}Properties.td
+	${LLDB_TBLGEN} ${LLDB_TBLGEN_OPTS} --gen-lldb-property-enum-defs \
+	    -I ${LLDB_SRCS}/source/${path:H} -d ${.TARGET}.d -o ${.TARGET} \
+	    ${.ALLSRC}
 TGHDRS+=	${path:T}PropertiesEnum.inc
 .endfor
 
diff --git a/lib/clang/libllvm/Makefile b/lib/clang/libllvm/Makefile
index 1cfd75f509c0..63b95219735c 100644
--- a/lib/clang/libllvm/Makefile
+++ b/lib/clang/libllvm/Makefile
@@ -1907,64 +1907,57 @@ SRCS_ALL+=	${SRCS_XDW}
 SRCS+=		${GENSRCS}
 SRCS+=		${SRCS_ALL:O}
 
-llvm/Frontend/OpenMP/OMP.h.inc: ${LLVM_SRCS}/include/llvm/Frontend/OpenMP/OMP.td
-	${LLVM_TBLGEN} --gen-directive-decl \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/include/llvm/Frontend/OpenMP/OMP.td
+llvm/Frontend/OpenMP/OMP.h.inc: \
+    ${LLVM_SRCS}/include/llvm/Frontend/OpenMP/OMP.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-directive-decl \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm/Frontend/OpenMP/OMP.h.inc
 
 llvm/Frontend/OpenMP/OMP.inc: ${LLVM_SRCS}/include/llvm/Frontend/OpenMP/OMP.td
-	${LLVM_TBLGEN} --gen-directive-impl \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/include/llvm/Frontend/OpenMP/OMP.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-directive-impl \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm/Frontend/OpenMP/OMP.inc
 
 OMP.cpp: ${LLVM_SRCS}/include/llvm/Frontend/OpenMP/OMP.td
-	${LLVM_TBLGEN} --gen-directive-impl \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/include/llvm/Frontend/OpenMP/OMP.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-directive-impl \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 GENSRCS+=	OMP.cpp
 
 llvm/IR/Attributes.inc: ${LLVM_SRCS}/include/llvm/IR/Attributes.td
-	${LLVM_TBLGEN} -gen-attrs \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/include/llvm/IR/Attributes.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-attrs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm/IR/Attributes.inc
 
 llvm/IR/IntrinsicEnums.inc: ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
-	${LLVM_TBLGEN} -gen-intrinsic-enums \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-intrinsic-enums \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm/IR/IntrinsicEnums.inc
 
 llvm/IR/IntrinsicImpl.inc: ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
-	${LLVM_TBLGEN} -gen-intrinsic-impl \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-intrinsic-impl \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm/IR/IntrinsicImpl.inc
 
 .for arch in \
 	AArch64/aarch64 AMDGPU/amdgcn ARM/arm BPF/bpf DirectX/dx \
-	Hexagon/hexagon Mips/mips NVPTX/nvvm PowerPC/ppc R600/r600 RISCV/riscv \
-	S390/s390 VE/ve WebAssembly/wasm X86/x86 XCore/xcore
+	Hexagon/hexagon Mips/mips NVPTX/nvvm PowerPC/ppc R600/r600 \
+	RISCV/riscv S390/s390 VE/ve WebAssembly/wasm X86/x86 XCore/xcore
 llvm/IR/Intrinsics${arch:H}.h: ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
-	${LLVM_TBLGEN} -gen-intrinsic-enums -intrinsic-prefix=${arch:T} \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/include/llvm/IR/Intrinsics.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} \
+	    --gen-intrinsic-enums -intrinsic-prefix=${arch:T} \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm/IR/Intrinsics${arch:H}.h
 .endfor
 
 llvm-lib/Options.inc: ${LLVM_SRCS}/lib/ToolDrivers/llvm-lib/Options.td
-	${LLVM_TBLGEN} -gen-opt-parser-defs \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/lib/ToolDrivers/llvm-lib/Options.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm-lib/Options.inc
 CFLAGS.LibDriver.cpp+=	-I${.OBJDIR}/llvm-lib
 
 llvm-dlltool/Options.inc: ${LLVM_SRCS}/lib/ToolDrivers/llvm-dlltool/Options.td
-	${LLVM_TBLGEN} -gen-opt-parser-defs \
-	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/lib/ToolDrivers/llvm-dlltool/Options.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	llvm-dlltool/Options.inc
 CFLAGS.DlltoolDriver.cpp+=	-I${.OBJDIR}/llvm-dlltool
 
@@ -2009,10 +2002,9 @@ beforebuild:
 	SystemOperands/-gen-searchable-tables \
 	SystemRegister/-gen-searchable-tables
 ${arch:T}Gen${hdr:H}.inc: ${LLVM_SRCS}/lib/Target/${arch:H}/${arch:T}.td
-	${LLVM_TBLGEN} ${hdr:T:C/,/ /g} \
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} ${hdr:T:C/,/ /g} \
 	    -I ${LLVM_SRCS}/include -I ${LLVM_SRCS}/lib/Target/${arch:H} \
-	    -d ${.TARGET}.d -o ${.TARGET} \
-	    ${LLVM_SRCS}/lib/Target/${arch:H}/${arch:T}.td
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 . endfor
 .endfor
 .if ${MK_LLVM_TARGET_AARCH64} != "no"
diff --git a/lib/clang/lldb.pre.mk b/lib/clang/lldb.pre.mk
index dbbfa1dba049..b0fb73925989 100644
--- a/lib/clang/lldb.pre.mk
+++ b/lib/clang/lldb.pre.mk
@@ -2,4 +2,8 @@
 
 .include "clang.pre.mk"
 
-LLDB_SRCS=	${LLVM_BASE}/lldb
+LLDB_SRCS=		${LLVM_BASE}/lldb
+
+LLDB_TBLGEN?=		lldb-tblgen
+LLDB_TBLGEN_BIN!=	which ${LLDB_TBLGEN} || echo __nonexistent_lldb_tblgen__
+LLDB_TBLGEN_OPTS?=	--write-if-changed
diff --git a/lib/clang/llvm.pre.mk b/lib/clang/llvm.pre.mk
index 92124a7bf092..834a258c20e8 100644
--- a/lib/clang/llvm.pre.mk
+++ b/lib/clang/llvm.pre.mk
@@ -1,8 +1,9 @@
 
 # $FreeBSD$
 
-LLVM_BASE=	${SRCTOP}/contrib/llvm-project
-LLVM_SRCS=	${LLVM_BASE}/llvm
+LLVM_BASE=		${SRCTOP}/contrib/llvm-project
+LLVM_SRCS=		${LLVM_BASE}/llvm
 
-LLVM_TBLGEN?=	llvm-tblgen
-LLVM_TBLGEN_BIN!= which ${LLVM_TBLGEN}
+LLVM_TBLGEN?=		llvm-tblgen
+LLVM_TBLGEN_BIN!=	which ${LLVM_TBLGEN} || echo __nonexistent_llvm_tblgen__
+LLVM_TBLGEN_OPTS?=	--write-if-changed
diff --git a/usr.bin/clang/lld/Makefile b/usr.bin/clang/lld/Makefile
index 150f74b90984..954112a83aac 100644
--- a/usr.bin/clang/lld/Makefile
+++ b/usr.bin/clang/lld/Makefile
@@ -87,13 +87,10 @@ DPADD+=		${OBJTOP}/lib/clang/lib${lib}/lib${lib}.a
 LDADD+=		${OBJTOP}/lib/clang/lib${lib}/lib${lib}.a
 .endfor
 
-INCFILE=	Options.inc
-TDFILE=		${LLD_SRCS}/ELF/Options.td
-GENOPT=		-gen-opt-parser-defs
-${INCFILE}: ${TDFILE}
-	${LLVM_TBLGEN} ${GENOPT} -I ${LLVM_SRCS}/include -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${TDFILE}
-TGHDRS+=	${INCFILE}
+Options.inc: ${LLD_SRCS}/ELF/Options.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
+TGHDRS+=	Options.inc
 
 ${TGHDRS}: ${LLVM_TBLGEN_BIN}
 
diff --git a/usr.bin/clang/lldb-server/Makefile b/usr.bin/clang/lldb-server/Makefile
index b11fbfbbef33..974b288406c8 100644
--- a/usr.bin/clang/lldb-server/Makefile
+++ b/usr.bin/clang/lldb-server/Makefile
@@ -29,13 +29,10 @@ DPADD+=		${OBJTOP}/lib/clang/lib${lib}/lib${lib}.a
 LDADD+=		${OBJTOP}/lib/clang/lib${lib}/lib${lib}.a
 .endfor
 
-INCFILE=	LLGSOptions.inc
-TDFILE=		${LLDB_SRCS}/tools/lldb-server/LLGSOptions.td
-GENOPT=		-gen-opt-parser-defs
-${INCFILE}: ${TDFILE}
-	${LLVM_TBLGEN} ${GENOPT} -I ${LLVM_SRCS}/include -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${TDFILE}
-TGHDRS+=	${INCFILE}
+LLGSOptions.inc: ${LLDB_SRCS}/tools/lldb-server/LLGSOptions.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
+TGHDRS+=	LLGSOptions.inc
 
 ${TGHDRS}: ${LLVM_TBLGEN_BIN}
 
diff --git a/usr.bin/clang/lldb/Makefile b/usr.bin/clang/lldb/Makefile
index b6486756d882..8b6e22de5522 100644
--- a/usr.bin/clang/lldb/Makefile
+++ b/usr.bin/clang/lldb/Makefile
@@ -22,13 +22,10 @@ DPADD+=		${OBJTOP}/lib/clang/lib${lib}/lib${lib}.a
 LDADD+=		${OBJTOP}/lib/clang/lib${lib}/lib${lib}.a
 .endfor
 
-INCFILE=	Options.inc
-TDFILE=		${LLVM_BASE}/${SRCDIR}/Options.td
-GENOPT=		-gen-opt-parser-defs
-${INCFILE}: ${TDFILE}
-	${LLVM_TBLGEN} ${GENOPT} -I ${LLVM_SRCS}/include -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${TDFILE}
-TGHDRS+=	${INCFILE}
+Options.inc: ${LLVM_BASE}/${SRCDIR}/Options.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
+TGHDRS+=	Options.inc
 
 ${TGHDRS}: ${LLVM_TBLGEN_BIN}
 
diff --git a/usr.bin/clang/llvm-cxxfilt/Makefile b/usr.bin/clang/llvm-cxxfilt/Makefile
index 0ce39d66f0f5..168ba219cfc5 100644
--- a/usr.bin/clang/llvm-cxxfilt/Makefile
+++ b/usr.bin/clang/llvm-cxxfilt/Makefile
@@ -13,13 +13,10 @@ CFLAGS.llvm-cxxfilt.cpp+=	-Dllvm_cxxfilt_main=main
 
 CFLAGS+=	-I${.OBJDIR}
 
-INCFILE=	Opts.inc
-TDFILE=		${LLVM_BASE}/${SRCDIR}/Opts.td
-GENOPT=		-gen-opt-parser-defs
-${INCFILE}: ${TDFILE}
-	${LLVM_TBLGEN} ${GENOPT} -I ${LLVM_SRCS}/include -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${TDFILE}
-TGHDRS+=	${INCFILE}
+Opts.inc: ${LLVM_BASE}/${SRCDIR}/Opts.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
+TGHDRS+=	Opts.inc
 
 ${TGHDRS}: ${LLVM_TBLGEN_BIN}
 
diff --git a/usr.bin/clang/llvm-dwarfutil/Makefile b/usr.bin/clang/llvm-dwarfutil/Makefile
index 6dd9bd2d5259..fca08efcce36 100644
--- a/usr.bin/clang/llvm-dwarfutil/Makefile
+++ b/usr.bin/clang/llvm-dwarfutil/Makefile
@@ -10,13 +10,10 @@ SRCS+=		llvm-dwarfutil.cpp
 
 CFLAGS+=	-I${.OBJDIR}
 
-INCFILE=	Options.inc
-TDFILE=		${LLVM_BASE}/${SRCDIR}/Options.td
-GENOPT=		-gen-opt-parser-defs
-${INCFILE}: ${TDFILE}
-	${LLVM_TBLGEN} ${GENOPT} -I ${LLVM_SRCS}/include -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${TDFILE}
-TGHDRS+=	${INCFILE}
+Options.inc: ${LLVM_BASE}/${SRCDIR}/Options.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
+TGHDRS+=	Options.inc
 
 ${TGHDRS}: ${LLVM_TBLGEN_BIN}
 
diff --git a/usr.bin/clang/llvm-nm/Makefile b/usr.bin/clang/llvm-nm/Makefile
index d3099e5a75be..702a31e7da59 100644
--- a/usr.bin/clang/llvm-nm/Makefile
+++ b/usr.bin/clang/llvm-nm/Makefile
@@ -11,13 +11,10 @@ SRCS+=		llvm-nm.cpp
 
 CFLAGS+=	-I${.OBJDIR}
 
-INCFILE=	Opts.inc
-TDFILE=		${LLVM_BASE}/${SRCDIR}/Opts.td
-GENOPT=		-gen-opt-parser-defs
-${INCFILE}: ${TDFILE}
-	${LLVM_TBLGEN} ${GENOPT} -I ${LLVM_SRCS}/include -d ${.TARGET:C/$/.d/} \
-	    -o ${.TARGET} ${TDFILE}
-TGHDRS+=	${INCFILE}
+Opts.inc: ${LLVM_BASE}/${SRCDIR}/Opts.td
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
+	    -I ${LLVM_SRCS}/include -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
+TGHDRS+=	Opts.inc
 
 ${TGHDRS}: ${LLVM_TBLGEN_BIN}
 
diff --git a/usr.bin/clang/llvm-objcopy/Makefile b/usr.bin/clang/llvm-objcopy/Makefile
index 5cdbf5e32d2d..9077cce53b8c 100644
--- a/usr.bin/clang/llvm-objcopy/Makefile
+++ b/usr.bin/clang/llvm-objcopy/Makefile
@@ -17,9 +17,9 @@ CFLAGS+=	-I${LLVM_BASE}/${SRCDIR}
 
 .for hdr in BitcodeStripOpts InstallNameToolOpts ObjcopyOpts StripOpts
 ${hdr}.inc: ${LLVM_BASE}/${SRCDIR}/${hdr}.td
-	${LLVM_TBLGEN} -gen-opt-parser-defs \
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
 	    -I ${LLVM_SRCS}/tools/llvm-objcopy -I ${LLVM_SRCS}/include \
-	    -d ${.TARGET}.d -o ${.TARGET} ${LLVM_BASE}/${SRCDIR}/${hdr}.td
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	${hdr}.inc
 .endfor
 
diff --git a/usr.bin/clang/llvm-objdump/Makefile b/usr.bin/clang/llvm-objdump/Makefile
index b4286ffec623..a56457396819 100644
--- a/usr.bin/clang/llvm-objdump/Makefile
+++ b/usr.bin/clang/llvm-objdump/Makefile
@@ -20,9 +20,9 @@ CFLAGS+=	-I${.OBJDIR}
 
 .for hdr in ObjdumpOpts OtoolOpts
 ${hdr}.inc: ${LLVM_BASE}/${SRCDIR}/${hdr}.td
-	${LLVM_TBLGEN} -gen-opt-parser-defs \
+	${LLVM_TBLGEN} ${LLVM_TBLGEN_OPTS} --gen-opt-parser-defs \
 	    -I ${LLVM_SRCS}/tools/llvm-objcopy -I ${LLVM_SRCS}/include \
-	    -d ${.TARGET}.d -o ${.TARGET} ${LLVM_BASE}/${SRCDIR}/${hdr}.td
+	    -d ${.TARGET}.d -o ${.TARGET} ${.ALLSRC}
 TGHDRS+=	${hdr}.inc
 .endfor
 
diff --git a/usr.bin/clang/llvm-readobj/Makefile b/usr.bin/clang/llvm-readobj/Makefile
index 8926eb03bdbf..4d9611960063 100644
--- a/usr.bin/clang/llvm-readobj/Makefile
+++ b/usr.bin/clang/llvm-readobj/Makefile
@@ -22,13 +22,10 @@ SRCS+=		XCOFFDumper.cpp
 
*** 82 LINES SKIPPED ***