Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
#	$NetBSD: Makefile,v 1.3 2021/05/30 01:56:50 joerg Exp $

.include <bsd.init.mk>

.if ${MKLLVM} != "no"
.PATH:	${CLANG_SRCDIR}/lib/Headers


.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
INCS=	adxintrin.h \
	ammintrin.h \
	amxintrin.h \
	avx2intrin.h \
	avx512bf16intrin.h \
	avx512bitalgintrin.h \
	avx512bwintrin.h \
	avx512cdintrin.h \
	avx512dqintrin.h \
	avx512erintrin.h \
	avx512fintrin.h \
	avx512ifmaintrin.h \
	avx512ifmavlintrin.h \
	avx512pfintrin.h \
	avx512vbmi2intrin.h \
	avx512vbmiintrin.h \
	avx512vbmivlintrin.h \
	avx512vlbf16intrin.h \
	avx512vlbitalgintrin.h \
	avx512vlbwintrin.h \
	avx512vlcdintrin.h \
	avx512vldqintrin.h \
	avx512vlintrin.h \
	avx512vlvbmi2intrin.h \
	avx512vlvnniintrin.h \
	avx512vlvp2intersectintrin.h \
	avx512vnniintrin.h \
	avx512vp2intersectintrin.h \
	avx512vpopcntdqintrin.h \
	avx512vpopcntdqvlintrin.h \
	avxintrin.h \
	avxvnniintrin.h \
	bmi2intrin.h \
	bmiintrin.h \
	cetintrin.h \
	cldemoteintrin.h \
	clflushoptintrin.h \
	clwbintrin.h \
	clzerointrin.h \
	cpuid.h \
	emmintrin.h \
	enqcmdintrin.h \
	f16cintrin.h \
	fma4intrin.h \
	fmaintrin.h \
	fxsrintrin.h \
	gfniintrin.h \
	hresetintrin.h \
	ia32intrin.h \
	immintrin.h \
	invpcidintrin.h \
	keylockerintrin.h \
	lwpintrin.h \
	lzcntintrin.h \
	mm3dnow.h \
	mmintrin.h \
	mm_malloc.h \
	movdirintrin.h \
	mwaitxintrin.h \
	nmmintrin.h \
	pconfigintrin.h \
	pkuintrin.h \
	pmmintrin.h \
	popcntintrin.h \
	prfchwintrin.h \
	ptwriteintrin.h \
	rdseedintrin.h \
	rtmintrin.h \
	serializeintrin.h \
	sgxintrin.h \
	shaintrin.h \
	smmintrin.h \
	tbmintrin.h \
	tmmintrin.h \
	tsxldtrkintrin.h \
	uintrintrin.h \
	vaesintrin.h \
	vpclmulqdqintrin.h \
	waitpkgintrin.h \
	wbnoinvdintrin.h \
	__wmmintrin_aes.h \
	wmmintrin.h \
	__wmmintrin_pclmul.h \
	x86gprintrin.h \
	x86intrin.h \
	xmmintrin.h \
	xopintrin.h \
	xsavecintrin.h \
	xsaveintrin.h \
	xsaveoptintrin.h \
	xsavesintrin.h \
	xtestintrin.h

.elif ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64"
INCS=	altivec.h \
	htmintrin.h \
	htmxlintrin.h
.elif ${MACHINE_CPU} == "arm" || ${MACHINE_CPU} == "aarch64"
INCS=	arm_acle.h \
	arm_cmse.h \
	arm_neon.h
.  if ${MACHINE_CPU} == "aarch64"
INCS+=	arm64intr.h
.  endif
.elif ${MACHINE_CPU} == "mips"
INCS=	msa.h
.endif
INCS+=	stdatomic.h tgmath.h
INCSDIR=	/usr/include/clang-${CLANG_VERSION:R}
.endif # MKLLVM

.PATH:	${LLVM_SRCDIR}/include/llvm/IR
.PATH:	${LLVM_SRCDIR}/include/llvm/Frontend/OpenACC
.PATH:	${LLVM_SRCDIR}/include/llvm/Frontend/OpenMP

TABLEGEN_SRC=	Attributes.td Intrinsics.td Options.td ACC.td OMP.td

TABLEGEN_OUTPUT.Attributes.td= \
	llvm/IR/Attributes.inc|-gen-attrs

TABLEGEN_OUTPUT.Intrinsics.td= \
	llvm/IR/IntrinsicEnums.inc|-gen-intrinsic-enums \
	llvm/IR/IntrinsicImpl.inc|-gen-intrinsic-impl \
	llvm/IR/IntrinsicsAArch64.h|-gen-intrinsic-enums^-intrinsic-prefix=aarch64 \
	llvm/IR/IntrinsicsAMDGPU.h|-gen-intrinsic-enums^-intrinsic-prefix=amdgcn \
	llvm/IR/IntrinsicsARM.h|-gen-intrinsic-enums^-intrinsic-prefix=arm \
	llvm/IR/IntrinsicsBPF.h|-gen-intrinsic-enums^-intrinsic-prefix=bpf \
	llvm/IR/IntrinsicsHexagon.h|-gen-intrinsic-enums^-intrinsic-prefix=hexagon \
	llvm/IR/IntrinsicsMips.h|-gen-intrinsic-enums^-intrinsic-prefix=mips \
	llvm/IR/IntrinsicsNVPTX.h|-gen-intrinsic-enums^-intrinsic-prefix=nvvm \
	llvm/IR/IntrinsicsPowerPC.h|-gen-intrinsic-enums^-intrinsic-prefix=ppc \
	llvm/IR/IntrinsicsR600.h|-gen-intrinsic-enums^-intrinsic-prefix=r600 \
	llvm/IR/IntrinsicsRISCV.h|-gen-intrinsic-enums^-intrinsic-prefix=riscv \
	llvm/IR/IntrinsicsS390.h|-gen-intrinsic-enums^-intrinsic-prefix=s390 \
        llvm/IR/IntrinsicsVE.h|-gen-intrinsic-enums^-intrinsic-prefix=ve \
	llvm/IR/IntrinsicsWebAssembly.h|-gen-intrinsic-enums^-intrinsic-prefix=wasm \
	llvm/IR/IntrinsicsX86.h|-gen-intrinsic-enums^-intrinsic-prefix=x86 \
	llvm/IR/IntrinsicsXCore.h|-gen-intrinsic-enums^-intrinsic-prefix=xcore \

TABLEGEN_OUTPUT.OMP.td=	\
	llvm/Frontend/OpenMP/OMP.h.inc|--gen-directive-decl \
	llvm/Frontend/OpenMP/OMP.inc|--gen-directive-impl

TABLEGEN_OUTPUT.ACC.td=	\
	llvm/Frontend/OpenACC/ACC.h.inc|--gen-directive-decl \
	llvm/Frontend/OpenACC/ACC.inc|--gen-directive-impl

.if ${MKLLVM} != "no"
.PATH:	${CLANG_SRCDIR}/include/clang/AST \
	${CLANG_SRCDIR}/include/clang/Basic \
	${CLANG_SRCDIR}/include/clang/Driver \
	${CLANG_SRCDIR}/include/clang/StaticAnalyzer/Checkers \
	${CLANG_SRCDIR}/include/clang/Tooling/Syntax
CLANG_TABLEGEN_SRC=	\
	arm_cde.td \
	arm_fp16.td \
	arm_mve.td \
	arm_neon.td \
	arm_sve.td \
	Attr.td \
	Checkers.td \
	CommentCommands.td \
	CommentHTMLNamedCharacterReferences.td \
	CommentHTMLTags.td \
	CommentNodes.td \
	DeclNodes.td \
	Diagnostic.td \
	Nodes.td \
	PropertiesBase.td \
	riscv_vector.td \
	StmtDataCollectors.td \
	StmtNodes.td \
	TypeNodes.td \
	TypeProperties.td

CLANG_TABLEGEN_INCLUDES.Attr.td=	-I${CLANG_SRCDIR}/include
CLANG_TABLEGEN_OUTPUT.Attr.td= \
	clang/AST/AttrImpl.inc|-gen-clang-attr-impl \
	clang/AST/AttrNodeTraverse.inc|-gen-clang-attr-node-traverse \
	clang/AST/AttrTextNodeDump.inc|-gen-clang-attr-text-node-dump \
	clang/AST/Attrs.inc|-gen-clang-attr-classes \
	clang/AST/AttrVisitor.inc|-gen-clang-attr-ast-visitor \
	clang/Basic/AttrHasAttributeImpl.inc|-gen-clang-attr-has-attribute-impl \
	clang/Basic/AttrList.inc|-gen-clang-attr-list \
	clang/Basic/AttrSubMatchRulesList.inc|-gen-clang-attr-subject-match-rule-list \
	clang/Parse/AttrParserStringSwitches.inc|-gen-clang-attr-parser-string-switches \
	clang/Parse/AttrSubMatchRulesParserStringSwitches.inc|-gen-clang-attr-subject-match-rules-parser-string-switches \
	clang/Sema/AttrParsedAttrImpl.inc|-gen-clang-attr-parsed-attr-impl \
	clang/Sema/AttrParsedAttrKinds.inc|-gen-clang-attr-parsed-attr-kinds \
	clang/Sema/AttrParsedAttrList.inc|-gen-clang-attr-parsed-attr-list \
	clang/Sema/AttrSpellingListIndex.inc|-gen-clang-attr-spelling-index \
	clang/Sema/AttrTemplateInstantiate.inc|-gen-clang-attr-template-instantiate \
	clang/Serialization/AttrPCHRead.inc|-gen-clang-attr-pch-read \
	clang/Serialization/AttrPCHWrite.inc|-gen-clang-attr-pch-write

CLANG_TABLEGEN_OUTPUT.PropertiesBase.td= \
	clang/AST/AbstractBasicReader.inc|-gen-clang-basic-reader \
	clang/AST/AbstractBasicWriter.inc|-gen-clang-basic-writer
CLANG_TABLEGEN_INCLUDES.PropertiesBase.td=	-I${CLANG_SRCDIR}/include

CLANG_TABLEGEN_OUTPUT.TypeProperties.td= \
	clang/AST/AbstractTypeReader.inc|-gen-clang-type-reader \
	clang/AST/AbstractTypeWriter.inc|-gen-clang-type-writer
CLANG_TABLEGEN_INCLUDES.TypeProperties.td=	-I${CLANG_SRCDIR}/include

CLANG_TABLEGEN_OUTPUT.StmtNodes.td= \
	clang/AST/StmtNodes.inc|-gen-clang-stmt-nodes
CLANG_TABLEGEN_INCLUDES.StmtNodes.td=	-I${CLANG_SRCDIR}/include

CLANG_TABLEGEN_OUTPUT.StmtDataCollectors.td= \
	clang/AST/StmtDataCollectors.inc|-gen-clang-data-collectors

CLANG_TABLEGEN_OUTPUT.DeclNodes.td= \
	clang/AST/DeclNodes.inc|-gen-clang-decl-nodes
CLANG_TABLEGEN_INCLUDES.DeclNodes.td=	-I${CLANG_SRCDIR}/include

CLANG_TABLEGEN_OUTPUT.CommentNodes.td= \
	clang/AST/CommentNodes.inc|-gen-clang-comment-nodes
CLANG_TABLEGEN_INCLUDES.CommentNodes.td=	-I${CLANG_SRCDIR}/include

CLANG_TABLEGEN_OUTPUT.CommentCommands.td= \
	clang/AST/CommentCommandInfo.inc|-gen-clang-comment-command-info \
	clang/AST/CommentCommandList.inc|-gen-clang-comment-command-list

CLANG_TABLEGEN_OUTPUT.CommentHTMLTags.td= \
	clang/AST/CommentHTMLTags.inc|-gen-clang-comment-html-tags \
	clang/AST/CommentHTMLTagsProperties.inc|-gen-clang-comment-html-tags-properties

CLANG_TABLEGEN_OUTPUT.CommentHTMLNamedCharacterReferences.td= \
	clang/AST/CommentHTMLNamedCharacterReferences.inc|-gen-clang-comment-html-named-character-references

CLANG_TABLEGEN_INCLUDES.Nodes.td=	-I${CLANG_SRCDIR}/include
CLANG_TABLEGEN_OUTPUT.Nodes.td= \
	clang/Tooling/Syntax/NodeClasses.inc|-gen-clang-syntax-node-classes \
	clang/Tooling/Syntax/Nodes.inc|-gen-clang-syntax-node-list

CLANG_TABLEGEN_OUTPUT.TypeNodes.td= \
	clang/AST/TypeNodes.inc|-gen-clang-type-nodes
CLANG_TABLEGEN_INCLUDES.TypeNodes.td=	-I${CLANG_SRCDIR}/include

CLANG_TABLEGEN_INCLUDES.Diagnostic.td=	-I${CLANG_SRCDIR}/include/clang/Basic
CLANG_TABLEGEN_OUTPUT.Diagnostic.td= \
	clang/Basic/DiagnosticAnalysisKinds.inc|-gen-clang-diags-defs^-clang-component=Analysis \
	clang/Basic/DiagnosticASTKinds.inc|-gen-clang-diags-defs^-clang-component=AST \
	clang/Basic/DiagnosticCommentKinds.inc|-gen-clang-diags-defs^-clang-component=Comment \
	clang/Basic/DiagnosticCommonKinds.inc|-gen-clang-diags-defs^-clang-component=Common \
	clang/Basic/DiagnosticCrossTUKinds.inc|-gen-clang-diags-defs^-clang-component=CrossTU \
	clang/Basic/DiagnosticDriverKinds.inc|-gen-clang-diags-defs^-clang-component=Driver \
	clang/Basic/DiagnosticFrontendKinds.inc|-gen-clang-diags-defs^-clang-component=Frontend \
	clang/Basic/DiagnosticGroups.inc|-gen-clang-diag-groups \
	clang/Basic/DiagnosticIndexName.inc|-gen-clang-diags-index-name \
	clang/Basic/DiagnosticLexKinds.inc|-gen-clang-diags-defs^-clang-component=Lex \
	clang/Basic/DiagnosticParseKinds.inc|-gen-clang-diags-defs^-clang-component=Parse \
	clang/Basic/DiagnosticRefactoringKinds.inc|-gen-clang-diags-defs^-clang-component=Refactoring \
	clang/Basic/DiagnosticSemaKinds.inc|-gen-clang-diags-defs^-clang-component=Sema \
	clang/Basic/DiagnosticSerializationKinds.inc|-gen-clang-diags-defs^-clang-component=Serialization

CLANG_TABLEGEN_INCLUDES.arm_cde.td=	-I${CLANG_SRCDIR}/include/clang/Basic
CLANG_TABLEGEN_OUTPUT.arm_cde.td= \
	clang/Basic/arm_cde_builtins.inc|-gen-arm-cde-builtin-def \
	clang/Basic/arm_cde_builtin_cg.inc|-gen-arm-cde-builtin-codegen \
	clang/Basic/arm_cde_builtin_sema.inc|-gen-arm-cde-builtin-sema \
	clang/Basic/arm_cde_builtin_aliases.inc|-gen-arm-cde-builtin-aliases

CLANG_TABLEGEN_INCLUDES.arm_sve.td=	-I${CLANG_SRCDIR}/include/clang/Basic
CLANG_TABLEGEN_OUTPUT.arm_sve.td= \
	clang/Basic/arm_sve_builtins.inc|-gen-arm-sve-builtins \
	clang/Basic/arm_sve_builtin_cg.inc|-gen-arm-sve-builtin-codegen \
	clang/Basic/arm_sve_sema_rangechecks.inc|-gen-arm-sve-sema-rangechecks \
	clang/Basic/arm_sve_typeflags.inc|-gen-arm-sve-typeflags

CLANG_TABLEGEN_INCLUDES.arm_neon.td=	-I${CLANG_SRCDIR}/include/clang/Basic
CLANG_TABLEGEN_OUTPUT.arm_neon.td= \
	clang/Basic/arm_neon.inc|-gen-arm-neon-sema \
	arm_neon.h|-gen-arm-neon

CLANG_TABLEGEN_INCLUDES.arm_fp16.td=	-I${CLANG_SRCDIR}/include/clang/Basic
CLANG_TABLEGEN_OUTPUT.arm_fp16.td= \
	clang/Basic/arm_fp16.inc|-gen-arm-neon-sema
CLANG_TABLEGEN_INCLUDES.arm_mve.td=	-I${CLANG_SRCDIR}/include/clang/Basic
CLANG_TABLEGEN_OUTPUT.arm_mve.td= \
	clang/Basic/arm_mve_builtins.inc|-gen-arm-mve-builtin-def \
	clang/Basic/arm_mve_builtin_aliases.inc|-gen-arm-mve-builtin-aliases \
	clang/Basic/arm_mve_builtin_cg.inc|-gen-arm-mve-builtin-codegen \
	clang/Basic/arm_mve_builtin_sema.inc|-gen-arm-mve-builtin-sema \

#CLANG_TABLEGEN_INCLUDES.riscv_vector.td=	-I${CLANG_SRCDIR}/include/clang/Basic
CLANG_TABLEGEN_OUTPUT.riscv_vector.td= \
	clang/Basic/riscv_vector_builtins.inc|-gen-riscv-vector-builtins \
	clang/Basic/riscv_vector_builtin_cg.inc|-gen-riscv-vector-builtin-codegen

CLANG_TABLEGEN_INCLUDES.Checkers.td=	\
	-I${CLANG_SRCDIR}/include \
	-I${CLANG_SRCDIR}/include/clang/StaticAnalyzer/Checkers
CLANG_TABLEGEN_OUTPUT.Checkers.td= \
	clang/StaticAnalyzer/Checkers/Checkers.inc|-gen-clang-sa-checkers

TABLEGEN_INCLUDES.Options.td=	-I${CLANG_SRCDIR}/include/clang/Driver
TABLEGEN_OUTPUT.Options.td= \
	clang/Driver/Options.inc|-gen-opt-parser-defs

.endif # MKLLVM

.include "${.PARSEDIR}/../tablegen.mk"

DPSRCS+=	llvm/Support/VCSRevision.h
DPSRC+=		llvm/Support/VCSRevision.h

llvm/Support/VCSRevision.h: ${LLVM_TOPLEVEL}/Makefile.inc
	mkdir -p ${.TARGET:H}
	printf '#define LLVM_REVISION "git-${LLVM_REVISION}"\n' >> ${.TARGET}.tmp
	mv ${.TARGET}.tmp ${.TARGET}

.if ${MKLLVM} != "no"
DPSRCS+=	clang/Basic/Version.inc
CLEANFILES+=	clang/Basic/Version.inc

clang/Basic/Version.inc: ${LLVM_TOPLEVEL}/Makefile.inc
	mkdir -p ${.TARGET:H}
	printf '#define CLANG_VERSION ${CLANG_VERSION}\n' > ${.TARGET}.tmp
	printf '#define CLANG_VERSION_STRING "${CLANG_VERSION}"\n' >> ${.TARGET}.tmp
	printf '#define CLANG_VERSION_MAJOR ${CLANG_VERSION:R:R}\n' >> ${.TARGET}.tmp
	printf '#define CLANG_VERSION_MINOR ${CLANG_VERSION:R:E}\n' >> ${.TARGET}.tmp
	printf '#define CLANG_VERSION_PATCHLEVEL ${CLANG_VERSION:R:R}\n' >> ${.TARGET}.tmp
	mv ${.TARGET}.tmp ${.TARGET}
.endif # MKLLVM

.ifndef HOST_BUILD

DPSRCS+=	llvm/Config/config.h llvm/Config/llvm-config.h
CLEANFILES+=	llvm/Config/config.h llvm/Config/llvm-config.h

NATIVE_LIBS=	-lm -lexecinfo

.if ${MACHINE_ARCH} == "i386" || ${MACHINE_ARCH} == "x86_64"
NATIVE_LLVM_ARCH=		X86
.endif

.if ${MACHINE_ARCH} == "aarch64" || ${MACHINE_ARCH} == "aarch64eb"
NATIVE_LLVM_ARCH=		AArch64
.endif

.if !empty(MACHINE_ARCH:Mearm*) || !empty(MACHINE_ARCH:Marm*)
NATIVE_LLVM_ARCH=		ARM
.endif

.if !empty(MACHINE_ARCH:Mmips*)
NATIVE_LLVM_ARCH=		Mips
.endif

.if ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "powerpc64"
NATIVE_LLVM_ARCH=		PowerPC
.endif

.if ${MACHINE_ARCH} == "sparc" || ${MACHINE_ARCH} == "sparc64"
NATIVE_LLVM_ARCH=		Sparc
.endif

.if defined(NATIVE_LLVM_ARCH)
NATIVE_LLVM_ASMPARSER=		LLVMInitialize${NATIVE_LLVM_ARCH}AsmParser
NATIVE_LLVM_ASMPRINTER=		LLVMInitialize${NATIVE_LLVM_ARCH}AsmPrinter
NATIVE_LLVM_DISASSEMBLER=	LLVMInitialize${NATIVE_LLVM_ARCH}Disassembler
NATIVE_LLVM_TARGET=		LLVMInitialize${NATIVE_LLVM_ARCH}Target
NATIVE_LLVM_TARGETINFO=		LLVMInitialize${NATIVE_LLVM_ARCH}TargetInfo
NATIVE_LLVM_TARGETMC=		LLVMInitialize${NATIVE_LLVM_ARCH}TargetMC
.endif

llvm/Config/config.h: ${LLVM_TOPLEVEL}/Makefile.inc ${LLVM_TOPLEVEL}/config/llvm/Config/config.h.in
	mkdir -p ${.TARGET:H}
	${TOOL_SED} -e /LLVM_DEFAULT_TARGET_TRIPLE/d \
		    -e /LLVM_HOST_TRIPLE/d \
		    -e /LLVM_NATIVE_/d \
		    -e /LLVM_VERSION_/d \
		    -e /PACKAGE_VERSION/d -e 'x' \
	    < ${LLVM_TOPLEVEL}/config/llvm/Config/config.h.in \
	    > ${.TARGET}.tmp
	printf '#define LLVM_DEFAULT_TARGET_TRIPLE "${MACHINE_GNU_PLATFORM}"\n' >> ${.TARGET}.tmp
	printf '#define LLVM_HOST_TRIPLE "${MACHINE_GNU_PLATFORM}"\n' >> ${.TARGET}.tmp
.if defined(NATIVE_LLVM_ARCH)
	printf '#define LLVM_NATIVE_ARCH ${NATIVE_LLVM_ARCH}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_ASMPARSER ${NATIVE_LLVM_ASMPARSER}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_ASMPRINTER ${NATIVE_LLVM_ASMPRINTER}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_DISASSEMBLER ${NATIVE_LLVM_DISASSEMBLER}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_TARGET ${NATIVE_LLVM_TARGET}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_TARGETINFO ${NATIVE_LLVM_TARGETINFO}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_TARGETMC ${NATIVE_LLVM_TARGETMC}\n' >> ${.TARGET}.tmp
.endif
	printf '#define PACKAGE_VERSION "${LLVM_VERSION} (trunk ${LLVM_REVISION})"\n' >> ${.TARGET}.tmp
	printf '#define LLVM_VERSION_MAJOR ${LLVM_VERSION:R:R}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_VERSION_MINOR ${LLVM_VERSION:R:E}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_VERSION_PATCH ${LLVM_VERSION:E}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_VERSION_STRING "${LLVM_VERSION}"\n' >> ${.TARGET}.tmp
	printf '#endif\n' >> ${.TARGET}.tmp
	mv ${.TARGET}.tmp ${.TARGET}

llvm/Config/llvm-config.h: ${LLVM_TOPLEVEL}/Makefile.inc ${LLVM_TOPLEVEL}/config/llvm/Config/llvm-config.h.in
	mkdir -p ${.TARGET:H}
	${TOOL_SED} -e /LLVM_DEFAULT_TARGET_TRIPLE/d \
		    -e /LLVM_HOST_TRIPLE/d \
		    -e /LLVM_NATIVE_/d \
		    -e /LLVM_VERSION_/d \
		    -e /PACKAGE_VERSION/d -e 'x' \
	    < ${LLVM_TOPLEVEL}/config/llvm/Config/llvm-config.h.in \
	    > ${.TARGET}.tmp
	printf '#define LLVM_DEFAULT_TARGET_TRIPLE "${MACHINE_GNU_PLATFORM}"\n' >> ${.TARGET}.tmp
	printf '#define LLVM_HOST_TRIPLE "${MACHINE_GNU_PLATFORM}"\n' >> ${.TARGET}.tmp
.if defined(NATIVE_LLVM_ARCH)
	printf '#define LLVM_NATIVE_ARCH ${NATIVE_LLVM_ARCH}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_ASMPARSER ${NATIVE_LLVM_ASMPARSER}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_ASMPRINTER ${NATIVE_LLVM_ASMPRINTER}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_DISASSEMBLER ${NATIVE_LLVM_DISASSEMBLER}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_TARGET ${NATIVE_LLVM_TARGET}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_TARGETINFO ${NATIVE_LLVM_TARGETINFO}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_NATIVE_TARGETMC ${NATIVE_LLVM_TARGETMC}\n' >> ${.TARGET}.tmp
.endif
	printf '#define LLVM_VERSION_MAJOR ${LLVM_VERSION:R:R}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_VERSION_MINOR ${LLVM_VERSION:R:E}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_VERSION_PATCH ${LLVM_VERSION:E}\n' >> ${.TARGET}.tmp
	printf '#define LLVM_VERSION_STRING "${LLVM_VERSION}"\n' >> ${.TARGET}.tmp
	printf '#endif\n' >> ${.TARGET}.tmp
	mv ${.TARGET}.tmp ${.TARGET}

run-configure:
	[ ! -d tmp ] || rm -r tmp
	mkdir -p tmp
	cd tmp && CONFIG_SITE= ${CONFIG_DIR}/configure ${LLVM_CONFIGURE_ARGS} \
	    CC=${CC:Q} CFLAGS=${CFLAGS:N-Werror:Q} CXX=${CXX:Q} CXXFLAGS=${CXXFLAGS:N-Werror:Q} \
	    CPPFLAGS=${CPPFLAGS:N-std=c++11:Q} LDFLAGS=${LDFLAGS:Q} LD=${LD:Q} LIBS=${NATIVE_LIBS:Q} \
	    BUILD_CC=${CC:Q} BUILD_CXX=${CXX:Q}
	cp -r tmp/include/llvm/* ${LLVM_INCLUDE_CONFIG}/llvm/
	mv ${LLVM_INCLUDE_CONFIG}/llvm/Config/llvm-config.h \
	   ${LLVM_INCLUDE_CONFIG}/llvm/Config/llvm-config.h.in
	cp -r tmp/include/clang/* ${CLANG_INCLUDE_CONFIG}/clang/
	rm -r tmp
	mv ${LLVM_INCLUDE_CONFIG}/llvm/Config/config.h \
	    ${LLVM_INCLUDE_CONFIG}/llvm/Config/config.h.in
	cp ${.CURDIR}/module.modulemap ${LLVM_INCLUDE_CONFIG}/llvm/module.modulemap
.endif

DPSRCS+=	llvm/Support/Extension.def
CLEANFILES+=	llvm/Support/Extension.def

llvm/Support/Extension.def:
	mkdir -p ${.TARGET:H}
	printf '//extension handlers\n#undef HANDLE_EXTENSION\n' > ${.TARGET}

includes depend dependall all: ${DPSRCS}

depend dependall: clean-modulecache

clean-modulecache:
	rm -rf ${LLVM_MODULE_CACHE}

.include <bsd.prog.mk>