xref: /freebsd/lib/clang/llvm.build.mk (revision d5b0e70f7e04d971691517ce1304d86a1e367e2e)
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/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-freebsd${OS_REVISION}${TARGET_TRIPLE_ABI}
53LLVM_BUILD_TRIPLE?=	${BUILD_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${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. if ${MACHINE_CPUARCH} == "mips"
77LLVM_NATIVE_ARCH=	Mips
78. endif
79.endif
80.if ${MK_LLVM_TARGET_POWERPC} != "no"
81CFLAGS+=	-DLLVM_TARGET_ENABLE_POWERPC
82. if ${MACHINE_CPUARCH} == "powerpc"
83LLVM_NATIVE_ARCH=	PowerPC
84. endif
85.endif
86.if ${MK_LLVM_TARGET_RISCV} != "no"
87CFLAGS+=	-DLLVM_TARGET_ENABLE_RISCV
88. if ${MACHINE_CPUARCH} == "riscv"
89LLVM_NATIVE_ARCH=	RISCV
90. endif
91.endif
92.if ${MK_LLVM_TARGET_X86} != "no"
93CFLAGS+=	-DLLVM_TARGET_ENABLE_X86
94. if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
95LLVM_NATIVE_ARCH=	X86
96. endif
97.endif
98
99.ifdef LLVM_NATIVE_ARCH
100CFLAGS+=	-DLLVM_NATIVE_ASMPARSER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser
101CFLAGS+=	-DLLVM_NATIVE_ASMPRINTER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter
102CFLAGS+=	-DLLVM_NATIVE_DISASSEMBLER=LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler
103CFLAGS+=	-DLLVM_NATIVE_TARGET=LLVMInitialize${LLVM_NATIVE_ARCH}Target
104CFLAGS+=	-DLLVM_NATIVE_TARGETINFO=LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo
105CFLAGS+=	-DLLVM_NATIVE_TARGETMC=LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC
106.endif
107
108CFLAGS+=	-ffunction-sections
109CFLAGS+=	-fdata-sections
110.include "bsd.linker.mk"
111.if ${LINKER_TYPE} == "mac"
112LDFLAGS+=	-Wl,-dead_strip
113.else
114LDFLAGS+=	-Wl,--gc-sections
115.endif
116
117CXXSTD?=	c++14
118CXXFLAGS+=	-fno-exceptions
119CXXFLAGS+=	-fno-rtti
120.if ${.MAKE.OS} == "FreeBSD" || !defined(BOOTSTRAPPING)
121CXXFLAGS.clang+= -stdlib=libc++
122.else
123# Building on macOS/Linux needs the real sysctl() not the bootstrap tools stub.
124CFLAGS+=	-DBOOTSTRAPPING_WANT_NATIVE_SYSCTL
125.endif
126.if defined(BOOTSTRAPPING) && ${.MAKE.OS} == "Linux"
127LIBADD+=	dl
128.endif
129
130.if ${MACHINE_ARCH:Mmips64}
131STATIC_CFLAGS+= -mxgot
132STATIC_CXXFLAGS+= -mxgot
133.endif
134