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