xref: /freebsd/lib/clang/llvm.build.mk (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
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.ifndef OS_REVISION
18.error Please define OS_REVISION before including this file
19.endif
20
21.PATH:		${LLVM_BASE}/${SRCDIR}
22
23CFLAGS+=	-I${SRCTOP}/lib/clang/include
24CFLAGS+=	-I${LLVM_SRCS}/include
25CFLAGS+=	-D__STDC_CONSTANT_MACROS
26CFLAGS+=	-D__STDC_FORMAT_MACROS
27CFLAGS+=	-D__STDC_LIMIT_MACROS
28CFLAGS+=	-DHAVE_VCS_VERSION_INC
29.if ${MK_LLVM_ASSERTIONS} == "no"
30CFLAGS+=	-DNDEBUG
31.endif
32
33# Note that using TARGET_ARCH here is essential for a functional native-xtools
34# build!  For native-xtools, we're building binaries that will work on the
35# *host* machine (MACHINE_ARCH), but they should default to producing binaries
36# for the *target* machine (TARGET_ARCH).
37TARGET_ARCH?=	${MACHINE_ARCH}
38BUILD_ARCH?=	${MACHINE_ARCH}
39
40# Armv6 and armv7 uses hard float abi, unless the CPUTYPE has soft in it.
41# arm (for armv4 and armv5 CPUs) always uses the soft float ABI.
42# For all other targets, we stick with 'unknown'.
43.if ${TARGET_ARCH:Marmv[67]*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "")
44TARGET_TRIPLE_ABI=	-gnueabihf
45.elif ${TARGET_ARCH:Marm*}
46TARGET_TRIPLE_ABI=	-gnueabi
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++14
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