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