xref: /freebsd/lib/clang/llvm.build.mk (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1
2.include <src.opts.mk>
3
4.ifndef LLVM_BASE
5.error Please define LLVM_BASE before including this file
6.endif
7
8.ifndef LLVM_SRCS
9.error Please define LLVM_SRCS before including this file
10.endif
11
12.ifndef SRCDIR
13.error Please define SRCDIR before including this file
14.endif
15
16.ifndef OS_REVISION
17.error Please define OS_REVISION before including this file
18.endif
19
20.PATH:		${LLVM_BASE}/${SRCDIR}
21
22CFLAGS+=	-I${SRCTOP}/lib/clang/include
23CFLAGS+=	-I${LLVM_SRCS}/include
24CFLAGS+=	-D__STDC_CONSTANT_MACROS
25CFLAGS+=	-D__STDC_FORMAT_MACROS
26CFLAGS+=	-D__STDC_LIMIT_MACROS
27CFLAGS+=	-DHAVE_VCS_VERSION_INC
28.if ${MK_LLVM_ASSERTIONS} == "no"
29CFLAGS+=	-DNDEBUG
30.endif
31
32# Note that using TARGET_ARCH here is essential for a functional native-xtools
33# build!  For native-xtools, we're building binaries that will work on the
34# *host* machine (MACHINE_ARCH), but they should default to producing binaries
35# for the *target* machine (TARGET_ARCH).
36TARGET_ARCH?=	${MACHINE_ARCH}
37BUILD_ARCH?=	${MACHINE_ARCH}
38
39# Armv6 and armv7 uses hard float abi, unless the CPUTYPE has soft in it.
40# For all other targets, we stick with 'unknown'.
41.if ${TARGET_ARCH:Marm*}
42.if !defined(CPUTYPE) || ${CPUTYPE:M*soft*} == ""
43TARGET_TRIPLE_ABI=-gnueabihf
44.else
45TARGET_TRIPLE_ABI=-gnueabi
46.endif
47.else
48TARGET_TRIPLE_ABI=
49.endif
50VENDOR=		unknown
51
52LLVM_TARGET_TRIPLE?=	${TARGET_ARCH:C/amd64/x86_64/}-${VENDOR}-freebsd${OS_REVISION}${TARGET_TRIPLE_ABI}
53LLVM_BUILD_TRIPLE?=	${BUILD_ARCH:C/amd64/x86_64/}-${VENDOR}-freebsd${OS_REVISION}
54
55CFLAGS+=	-DLLVM_DEFAULT_TARGET_TRIPLE=\"${LLVM_TARGET_TRIPLE}\"
56CFLAGS+=	-DLLVM_HOST_TRIPLE=\"${LLVM_BUILD_TRIPLE}\"
57CFLAGS+=	-DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
58
59.if ${MK_LLVM_TARGET_AARCH64} != "no"
60CFLAGS+=	-DLLVM_TARGET_ENABLE_AARCH64
61. if ${MACHINE_CPUARCH} == "aarch64"
62LLVM_NATIVE_ARCH=	AArch64
63. endif
64.endif
65.if ${MK_LLVM_TARGET_ARM} != "no"
66CFLAGS+=	-DLLVM_TARGET_ENABLE_ARM
67. if ${MACHINE_CPUARCH} == "arm"
68LLVM_NATIVE_ARCH=	ARM
69. endif
70.endif
71.if ${MK_LLVM_TARGET_BPF} != "no"
72CFLAGS+=	-DLLVM_TARGET_ENABLE_BPF
73.endif
74.if ${MK_LLVM_TARGET_MIPS} != "no"
75CFLAGS+=	-DLLVM_TARGET_ENABLE_MIPS
76.endif
77.if ${MK_LLVM_TARGET_POWERPC} != "no"
78CFLAGS+=	-DLLVM_TARGET_ENABLE_POWERPC
79. if ${MACHINE_CPUARCH} == "powerpc"
80LLVM_NATIVE_ARCH=	PowerPC
81. endif
82.endif
83.if ${MK_LLVM_TARGET_RISCV} != "no"
84CFLAGS+=	-DLLVM_TARGET_ENABLE_RISCV
85. if ${MACHINE_CPUARCH} == "riscv"
86LLVM_NATIVE_ARCH=	RISCV
87. endif
88.endif
89.if ${MK_LLVM_TARGET_X86} != "no"
90CFLAGS+=	-DLLVM_TARGET_ENABLE_X86
91. if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
92LLVM_NATIVE_ARCH=	X86
93. endif
94.endif
95
96.ifdef LLVM_NATIVE_ARCH
97CFLAGS+=	-DLLVM_NATIVE_ASMPARSER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser
98CFLAGS+=	-DLLVM_NATIVE_ASMPRINTER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter
99CFLAGS+=	-DLLVM_NATIVE_DISASSEMBLER=LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler
100CFLAGS+=	-DLLVM_NATIVE_TARGET=LLVMInitialize${LLVM_NATIVE_ARCH}Target
101CFLAGS+=	-DLLVM_NATIVE_TARGETINFO=LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo
102CFLAGS+=	-DLLVM_NATIVE_TARGETMC=LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC
103.endif
104
105CFLAGS+=	-ffunction-sections
106CFLAGS+=	-fdata-sections
107.include "bsd.linker.mk"
108.if ${LINKER_TYPE} == "mac"
109LDFLAGS+=	-Wl,-dead_strip
110.else
111LDFLAGS+=	-Wl,--gc-sections
112.endif
113
114CXXSTD?=	c++17
115CXXFLAGS+=	-fno-exceptions
116CXXFLAGS+=	-fno-rtti
117.if ${.MAKE.OS} == "FreeBSD" || !defined(BOOTSTRAPPING)
118CXXFLAGS.clang+= -stdlib=libc++
119.else
120# Building on macOS/Linux needs the real sysctl() not the bootstrap tools stub.
121CFLAGS+=	-DBOOTSTRAPPING_WANT_NATIVE_SYSCTL
122.endif
123.if defined(BOOTSTRAPPING) && ${.MAKE.OS} == "Linux"
124LIBADD+=	dl
125.endif
126