xref: /freebsd/lib/clang/llvm.build.mk (revision f9a159da2a292968cd5c37b56a6c43b6af8c5eed)
1# $FreeBSD$
2
3.include <src.opts.mk>
4
5.ifndef LLVM_BASE
6.error Please define LLVM_BASE before including this file
7.endif
8
9.ifndef LLVM_SRCS
10.error Please define LLVM_SRCS before including this file
11.endif
12
13.ifndef SRCDIR
14.error Please define SRCDIR before including this file
15.endif
16
17.PATH:		${LLVM_BASE}/${SRCDIR}
18
19CFLAGS+=	-I${SRCTOP}/lib/clang/include
20CFLAGS+=	-I${LLVM_SRCS}/include
21CFLAGS+=	-D__STDC_CONSTANT_MACROS
22CFLAGS+=	-D__STDC_FORMAT_MACROS
23CFLAGS+=	-D__STDC_LIMIT_MACROS
24CFLAGS+=	-DHAVE_VCS_VERSION_INC
25.if ${MK_LLVM_ASSERTIONS} == "no"
26CFLAGS+=	-DNDEBUG
27.endif
28
29TARGET_ARCH?=	${MACHINE_ARCH}
30BUILD_ARCH?=	${MACHINE_ARCH}
31
32# Armv6 and armv7 uses hard float abi, unless the CPUTYPE has soft in it.
33# arm (for armv4 and armv5 CPUs) always uses the soft float ABI.
34# For all other targets, we stick with 'unknown'.
35.if ${TARGET_ARCH:Marmv[67]*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "")
36TARGET_ABI=	-gnueabihf
37.elif ${TARGET_ARCH:Marm*}
38TARGET_ABI=	-gnueabi
39.else
40TARGET_ABI=
41.endif
42VENDOR=		unknown
43OS_VERSION=	freebsd14.0
44
45LLVM_TARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-${OS_VERSION}${TARGET_ABI}
46LLVM_BUILD_TRIPLE?=	${BUILD_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-${OS_VERSION}
47
48CFLAGS+=	-DLLVM_DEFAULT_TARGET_TRIPLE=\"${LLVM_TARGET_TRIPLE}\"
49CFLAGS+=	-DLLVM_HOST_TRIPLE=\"${LLVM_BUILD_TRIPLE}\"
50CFLAGS+=	-DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
51
52.if ${MK_LLVM_TARGET_AARCH64} != "no"
53CFLAGS+=	-DLLVM_TARGET_ENABLE_AARCH64
54. if ${MACHINE_CPUARCH} == "aarch64"
55LLVM_NATIVE_ARCH=	AArch64
56. endif
57.endif
58.if ${MK_LLVM_TARGET_ARM} != "no"
59CFLAGS+=	-DLLVM_TARGET_ENABLE_ARM
60. if ${MACHINE_CPUARCH} == "arm"
61LLVM_NATIVE_ARCH=	ARM
62. endif
63.endif
64.if ${MK_LLVM_TARGET_BPF} != "no"
65CFLAGS+=	-DLLVM_TARGET_ENABLE_BPF
66.endif
67.if ${MK_LLVM_TARGET_MIPS} != "no"
68CFLAGS+=	-DLLVM_TARGET_ENABLE_MIPS
69. if ${MACHINE_CPUARCH} == "mips"
70LLVM_NATIVE_ARCH=	Mips
71. endif
72.endif
73.if ${MK_LLVM_TARGET_POWERPC} != "no"
74CFLAGS+=	-DLLVM_TARGET_ENABLE_POWERPC
75. if ${MACHINE_CPUARCH} == "powerpc"
76LLVM_NATIVE_ARCH=	PowerPC
77. endif
78.endif
79.if ${MK_LLVM_TARGET_RISCV} != "no"
80CFLAGS+=	-DLLVM_TARGET_ENABLE_RISCV
81. if ${MACHINE_CPUARCH} == "riscv"
82LLVM_NATIVE_ARCH=	RISCV
83. endif
84.endif
85.if ${MK_LLVM_TARGET_X86} != "no"
86CFLAGS+=	-DLLVM_TARGET_ENABLE_X86
87. if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
88LLVM_NATIVE_ARCH=	X86
89. endif
90.endif
91
92.ifdef LLVM_NATIVE_ARCH
93CFLAGS+=	-DLLVM_NATIVE_ASMPARSER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser
94CFLAGS+=	-DLLVM_NATIVE_ASMPRINTER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter
95CFLAGS+=	-DLLVM_NATIVE_DISASSEMBLER=LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler
96CFLAGS+=	-DLLVM_NATIVE_TARGET=LLVMInitialize${LLVM_NATIVE_ARCH}Target
97CFLAGS+=	-DLLVM_NATIVE_TARGETINFO=LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo
98CFLAGS+=	-DLLVM_NATIVE_TARGETMC=LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC
99.endif
100
101CFLAGS+=	-ffunction-sections
102CFLAGS+=	-fdata-sections
103LDFLAGS+=	-Wl,--gc-sections
104
105CXXSTD?=	c++14
106CXXFLAGS+=	-fno-exceptions
107CXXFLAGS+=	-fno-rtti
108CXXFLAGS.clang+= -stdlib=libc++
109
110.if ${MACHINE_ARCH:Mmips64}
111STATIC_CFLAGS+= -mxgot
112STATIC_CXXFLAGS+= -mxgot
113.endif
114