blob: 484e85ce4244bc25abef20b71132a592689da010 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001# Copyright (C) 2014 Khem Raj <raj.khem@gmail.com>
2# Released under the MIT license (see COPYING.MIT for the terms)
3
4DESCRIPTION = "LLVM based C/C++ compiler"
5HOMEPAGE = "http://clang.llvm.org/"
6SECTION = "devel"
7
8require clang.inc
9require common-source.inc
10
11INHIBIT_DEFAULT_DEPS = "1"
12
13BUILD_AR_class-nativesdk = "llvm-ar"
14BUILD_RANLIB_class-nativesdk = "llvm-ranlib"
15BUILD_NM_class-nativesdk = "llvm-nm"
16LDFLAGS_append_class-nativesdk = " -fuse-ld=gold"
17
18inherit cmake cmake-native
19
20OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "BOTH"
21
22def get_clang_experimental_arch(bb, d, arch_var):
23 import re
24 a = d.getVar(arch_var, True)
25 if re.match('riscv(32|64)$', a): return 'RISCV'
26 return ""
27
28def get_clang_arch(bb, d, arch_var):
29 import re
30 a = d.getVar(arch_var, True)
31 if re.match('(i.86|athlon|x86.64)$', a): return 'X86'
32 elif re.match('arm$', a): return 'ARM'
33 elif re.match('armeb$', a): return 'ARM'
34 elif re.match('aarch64$', a): return 'AArch64'
35 elif re.match('aarch64_be$', a): return 'AArch64'
36 elif re.match('mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
37 elif re.match('p(pc|owerpc)(|64)', a): return 'PowerPC'
38 else:
39 bb.note("'%s' is not a primary llvm architecture" % a)
40 return ""
41
42def get_clang_host_arch(bb, d):
43 return get_clang_arch(bb, d, 'HOST_ARCH')
44
45def get_clang_target_arch(bb, d):
46 return get_clang_arch(bb, d, 'TARGET_ARCH')
47
48def get_clang_experimental_target_arch(bb, d):
49 return get_clang_experimental_arch(bb, d, 'TARGET_ARCH')
50
51PACKAGECONFIG ??= "compiler-rt libcplusplus shared-libs ${@bb.utils.filter('DISTRO_FEATURES', 'thin-lto full-lto', d)}"
52PACKAGECONFIG_class-native = ""
53PACKAGECONFIG_class-nativesdk = "thin-lto"
54
55PACKAGECONFIG[compiler-rt] = "-DCLANG_DEFAULT_RTLIB=compiler-rt,,libcxx,compiler-rt"
56PACKAGECONFIG[libcplusplus] = "-DCLANG_DEFAULT_CXX_STDLIB=libc++,,libcxx"
57PACKAGECONFIG[thin-lto] = "-DLLVM_ENABLE_LTO=Thin -DLLVM_BINUTILS_INCDIR=${STAGING_INCDIR},,binutils,"
58PACKAGECONFIG[full-lto] = "-DLLVM_ENABLE_LTO=Full -DLLVM_BINUTILS_INCDIR=${STAGING_INCDIR},,binutils,"
59PACKAGECONFIG[shared-libs] = "-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON,,,"
60PACKAGECONFIG[terminfo] = "-DLLVM_ENABLE_TERMINFO=ON,-DLLVM_ENABLE_TERMINFO=OFF,ncurses,"
61PACKAGECONFIG[pfm] = "-DLLVM_ENABLE_LIBPFM=ON,-DLLVM_ENABLE_LIBPFM=OFF,libpfm,"
62PACKAGECONFIG[libedit] = "-DLLVM_ENABLE_LIBEDIT=ON,-DLLVM_ENABLE_LIBEDIT=OFF,libedit,"
63
64#
65# Default to build all OE-Core supported target arches (user overridable).
66#
67LLVM_TARGETS_TO_BUILD ?= "AArch64;ARM;BPF;Mips;PowerPC;X86"
68LLVM_TARGETS_TO_BUILD_append = ";${@get_clang_host_arch(bb, d)};${@get_clang_target_arch(bb, d)}"
69
70LLVM_TARGETS_TO_BUILD_TARGET ?= ""
71LLVM_TARGETS_TO_BUILD_TARGET_append ?= "${@get_clang_target_arch(bb, d)}"
72
73LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ?= "RISCV"
74LLVM_EXPERIMENTAL_TARGETS_TO_BUILD_append = ";${@get_clang_experimental_target_arch(bb, d)}"
75
76HF = "${@ bb.utils.contains('TUNE_CCARGS_MFLOAT', 'hard', 'hf', '', d)}"
77HF[vardepvalue] = "${HF}"
78
79EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
80 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
81 -DLLVM_ENABLE_PIC=ON \
82 -DLLVM_BINDINGS_LIST='' \
83 -DLLVM_ENABLE_FFI=ON \
84 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
85 -DLLVM_OPTIMIZED_TABLEGEN=ON \
86 -DLLVM_ENABLE_RTTI=ON \
87 -DLLVM_ENABLE_EH=ON \
88 -DLLVM_BUILD_EXTERNAL_COMPILER_RT=ON \
89 -DCMAKE_SYSTEM_NAME=Linux \
90 -DCMAKE_BUILD_TYPE=Release \
91 -DBUILD_SHARED_LIBS=OFF \
92 -DLLVM_ENABLE_PROJECTS='clang;lld' \
93 -DLLVM_BINUTILS_INCDIR=${STAGING_INCDIR} \
94 -G Ninja ${S}/llvm \
95 -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
96"
97
98EXTRA_OECMAKE_append_class-native = "\
99 -DCLANG_ENABLE_BOOTSTRAP=On \
100 -DCLANG_BOOTSTRAP_PASSTHROUGH='${PASSTHROUGH}' \
101 -DBOOTSTRAP_LLVM_ENABLE_LTO=Thin \
102 -DBOOTSTRAP_LLVM_ENABLE_LLD=ON \
103 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS_TO_BUILD}' \
104 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}' \
105"
106EXTRA_OECMAKE_append_class-nativesdk = "\
107 -DCMAKE_CROSSCOMPILING:BOOL=ON \
108 -DCROSS_TOOLCHAIN_FLAGS_NATIVE='-DCMAKE_TOOLCHAIN_FILE=${WORKDIR}/toolchain-native.cmake' \
109 -DCMAKE_RANLIB=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-ranlib \
110 -DCMAKE_AR=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-ar \
111 -DCMAKE_NM=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-nm \
112 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS_TO_BUILD}' \
113 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}' \
114 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen \
115 -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \
116"
117EXTRA_OECMAKE_append_class-target = "\
118 -DCMAKE_CROSSCOMPILING:BOOL=ON \
119 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen \
120 -DCLANG_TABLEGEN=${STAGING_BINDIR_NATIVE}/clang-tblgen \
121 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS_TO_BUILD_TARGET}' \
122 -DCMAKE_RANLIB=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-ranlib \
123 -DCMAKE_AR=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-ar \
124 -DCMAKE_NM=${STAGING_BINDIR_TOOLCHAIN}/${TARGET_PREFIX}llvm-nm \
125 -DLLVM_TARGET_ARCH=${@get_clang_target_arch(bb, d)} \
126 -DLLVM_DEFAULT_TARGET_TRIPLE=${TARGET_SYS}${HF} \
127"
128EXTRA_OECMAKE_append_class-target_riscv64 = "\
129 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}' \
130"
131EXTRA_OECMAKE_append_class-target_riscv32 = "\
132 -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}' \
133"
134DEPENDS = "binutils zlib libffi libxml2 ninja-native"
135DEPENDS_append_class-nativesdk = " clang-crosssdk-${SDK_ARCH} virtual/${TARGET_PREFIX}binutils-crosssdk"
136DEPENDS_append_class-target = " clang-cross-${TARGET_ARCH}"
137
138BOOTSTRAPSTAGE ?= ""
139BOOTSTRAPSTAGE_class-native = "stage2"
140INSTALLTARGET ?= "install"
141INSTALLTARGET_class-native = "stage2-install"
142PASSTRHOUGH ?= ""
143PASSTHROUGH_class-native = "\
144CLANG_DEFAULT_RTLIB;CLANG_DEFAULT_CXX_STDLIB;LLVM_BUILD_LLVM_DYLIB;LLVM_LINK_LLVM_DYLIB;\
145LLVM_ENABLE_ASSERTIONS;LLVM_ENABLE_EXPENSIVE_CHECKS;LLVM_ENABLE_PIC;\
146LLVM_BINDINGS_LIST;LLVM_ENABLE_FFI;FFI_INCLUDE_DIR;LLVM_OPTIMIZED_TABLEGEN;\
147LLVM_ENABLE_RTTI;LLVM_ENABLE_EH;LLVM_BUILD_EXTERNAL_COMPILER_RT;CMAKE_SYSTEM_NAME;\
148CMAKE_BUILD_TYPE;BUILD_SHARED_LIBS;LLVM_ENABLE_PROJECTS;LLVM_BINUTILS_INCDIR;\
149LLVM_TARGETS_TO_BUILD;LLVM_EXPERIMENTAL_TARGETS_TO_BUILD;\
150"
151
152RRECOMMENDS_${PN} = "binutils"
153RRECOMMENDS_${PN}_append_class-target = " libcxx-dev"
154
155do_compile() {
156 ninja ${PARALLEL_MAKE} ${BOOTSTRAPSTAGE}
157}
158
159do_install() {
160 DESTDIR=${D} ninja ${PARALLEL_MAKE} ${INSTALLTARGET}
161}
162
163do_install_append_class-native () {
164 install -Dm 0755 ${B}/bin/clang-tblgen ${D}${bindir}/clang-tblgen
165 for f in `find ${D}${bindir} -executable -type f -not -type l`; do
166 test -n "`file $f|grep -i ELF`" && ${STRIP} $f
167 echo "stripped $f"
168 done
169}
170
171do_install_append_class-nativesdk () {
172 install -Dm 0755 ${B}/bin/clang-tblgen ${D}${bindir}/clang-tblgen
173 for f in `find ${D}${bindir} -executable -type f -not -type l`; do
174 test -n "`file $f|grep -i ELF`" && ${STRIP} $f
175 done
176 rm -rf ${D}${datadir}/llvm/cmake
177 rm -rf ${D}${datadir}/llvm
178}
179
180PACKAGE_DEBUG_SPLIT_STYLE_class-nativesdk = "debug-without-src"
181
182PACKAGES =+ "${PN}-libllvm"
183
184BBCLASSEXTEND = "native nativesdk"
185
186FILES_${PN} += "\
187 ${libdir}/BugpointPasses.so \
188 ${libdir}/LLVMHello.so \
189 ${libdir}/TestPlugin.so \
190 ${libdir}/LLVMgold.so \
191 ${datadir}/scan-* \
192 ${datadir}/opt-viewer/ \
193"
194
195FILES_${PN}-libllvm += "\
196 ${libdir}/libLLVM-${MAJOR_VER}.${MINOR_VER}.so \
197 ${libdir}/libLLVM-${MAJOR_VER}.so \
198 ${libdir}/libLLVM-${MAJOR_VER}.${MINOR_VER}svn.so \
199"
200
201FILES_${PN}-dev += "\
202 ${datadir}/llvm/cmake \
203 ${libdir}/cmake \
204"
205
206INSANE_SKIP_${PN} += "already-stripped"
207INSANE_SKIP_${PN}-dev += "dev-elf"
208
209#Avoid SSTATE_SCAN_COMMAND running sed over llvm-config.
210SSTATE_SCAN_FILES_remove = "*-config"
211
212TOOLCHAIN = "clang"
213TOOLCHAIN_class-native = "gcc"
214TOOLCHAIN_class-nativesdk = "clang"