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