xref: /freebsd/lib/clang/llvm.build.mk (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
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
33BUILD_ARCH?=	${MACHINE_ARCH}
34
35# Armv6 and armv7 uses hard float abi, unless the CPUTYPE has soft in it.
36# arm (for armv4 and armv5 CPUs) always uses the soft float ABI.
37# For all other targets, we stick with 'unknown'.
38.if ${MACHINE_ARCH:Marmv[67]*} && (!defined(CPUTYPE) || ${CPUTYPE:M*soft*} == "")
39TARGET_ABI=	-gnueabihf
40.elif ${MACHINE_ARCH:Marm*}
41TARGET_ABI=	-gnueabi
42.else
43TARGET_ABI=
44.endif
45VENDOR=		unknown
46
47LLVM_TARGET_TRIPLE?=	${MACHINE_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-freebsd${OS_REVISION}${TARGET_ABI}
48LLVM_BUILD_TRIPLE?=	${BUILD_ARCH:C/amd64/x86_64/:C/[hs]f$//:S/mipsn32/mips64/}-${VENDOR}-freebsd${OS_REVISION}
49
50CFLAGS+=	-DLLVM_DEFAULT_TARGET_TRIPLE=\"${LLVM_TARGET_TRIPLE}\"
51CFLAGS+=	-DLLVM_HOST_TRIPLE=\"${LLVM_BUILD_TRIPLE}\"
52CFLAGS+=	-DDEFAULT_SYSROOT=\"${TOOLS_PREFIX}\"
53
54.if ${MK_LLVM_TARGET_AARCH64} != "no"
55CFLAGS+=	-DLLVM_TARGET_ENABLE_AARCH64
56. if ${MACHINE_CPUARCH} == "aarch64"
57LLVM_NATIVE_ARCH=	AArch64
58. endif
59.endif
60.if ${MK_LLVM_TARGET_ARM} != "no"
61CFLAGS+=	-DLLVM_TARGET_ENABLE_ARM
62. if ${MACHINE_CPUARCH} == "arm"
63LLVM_NATIVE_ARCH=	ARM
64. endif
65.endif
66.if ${MK_LLVM_TARGET_BPF} != "no"
67CFLAGS+=	-DLLVM_TARGET_ENABLE_BPF
68.endif
69.if ${MK_LLVM_TARGET_MIPS} != "no"
70CFLAGS+=	-DLLVM_TARGET_ENABLE_MIPS
71. if ${MACHINE_CPUARCH} == "mips"
72LLVM_NATIVE_ARCH=	Mips
73. endif
74.endif
75.if ${MK_LLVM_TARGET_POWERPC} != "no"
76CFLAGS+=	-DLLVM_TARGET_ENABLE_POWERPC
77. if ${MACHINE_CPUARCH} == "powerpc"
78LLVM_NATIVE_ARCH=	PowerPC
79. endif
80.endif
81.if ${MK_LLVM_TARGET_RISCV} != "no"
82CFLAGS+=	-DLLVM_TARGET_ENABLE_RISCV
83. if ${MACHINE_CPUARCH} == "riscv"
84LLVM_NATIVE_ARCH=	RISCV
85. endif
86.endif
87.if ${MK_LLVM_TARGET_X86} != "no"
88CFLAGS+=	-DLLVM_TARGET_ENABLE_X86
89. if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
90LLVM_NATIVE_ARCH=	X86
91. endif
92.endif
93
94.ifdef LLVM_NATIVE_ARCH
95CFLAGS+=	-DLLVM_NATIVE_ASMPARSER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmParser
96CFLAGS+=	-DLLVM_NATIVE_ASMPRINTER=LLVMInitialize${LLVM_NATIVE_ARCH}AsmPrinter
97CFLAGS+=	-DLLVM_NATIVE_DISASSEMBLER=LLVMInitialize${LLVM_NATIVE_ARCH}Disassembler
98CFLAGS+=	-DLLVM_NATIVE_TARGET=LLVMInitialize${LLVM_NATIVE_ARCH}Target
99CFLAGS+=	-DLLVM_NATIVE_TARGETINFO=LLVMInitialize${LLVM_NATIVE_ARCH}TargetInfo
100CFLAGS+=	-DLLVM_NATIVE_TARGETMC=LLVMInitialize${LLVM_NATIVE_ARCH}TargetMC
101.endif
102
103CFLAGS+=	-ffunction-sections
104CFLAGS+=	-fdata-sections
105.include "bsd.linker.mk"
106.if ${LINKER_TYPE} == "mac"
107LDFLAGS+=	-Wl,-dead_strip
108.else
109LDFLAGS+=	-Wl,--gc-sections
110.endif
111
112CXXSTD?=	c++14
113CXXFLAGS+=	-fno-exceptions
114CXXFLAGS+=	-fno-rtti
115.if ${.MAKE.OS} == "FreeBSD" || !defined(BOOTSTRAPPING)
116CXXFLAGS.clang+= -stdlib=libc++
117.else
118# Building on macOS/Linux needs the real sysctl() not the bootstrap tools stub.
119CFLAGS+=	-DBOOTSTRAPPING_WANT_NATIVE_SYSCTL
120.endif
121.if defined(BOOTSTRAPPING) && ${.MAKE.OS} == "Linux"
122LIBADD+=	dl
123.endif
124
125.if ${MACHINE_ARCH:Mmips64}
126STATIC_CFLAGS+= -mxgot
127STATIC_CXXFLAGS+= -mxgot
128.endif
129