rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | # Copyright (C) 2014 Khem Raj <raj.khem@gmail.com> |
| 2 | # Released under the MIT license (see COPYING.MIT for the terms) |
| 3 | |
| 4 | DESCRIPTION = "LLVM based C/C++ compiler" |
| 5 | HOMEPAGE = "http://clang.llvm.org/" |
| 6 | SECTION = "devel" |
| 7 | |
| 8 | require clang.inc |
| 9 | require common-source.inc |
| 10 | |
| 11 | INHIBIT_DEFAULT_DEPS = "1" |
| 12 | |
| 13 | BUILD_AR_class-nativesdk = "llvm-ar" |
| 14 | BUILD_RANLIB_class-nativesdk = "llvm-ranlib" |
| 15 | BUILD_NM_class-nativesdk = "llvm-nm" |
| 16 | LDFLAGS_append_class-nativesdk = " -fuse-ld=gold" |
| 17 | |
| 18 | inherit cmake cmake-native |
| 19 | |
| 20 | OECMAKE_FIND_ROOT_PATH_MODE_PROGRAM = "BOTH" |
| 21 | |
| 22 | def 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 | |
| 28 | def 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 | |
| 42 | def get_clang_host_arch(bb, d): |
| 43 | return get_clang_arch(bb, d, 'HOST_ARCH') |
| 44 | |
| 45 | def get_clang_target_arch(bb, d): |
| 46 | return get_clang_arch(bb, d, 'TARGET_ARCH') |
| 47 | |
| 48 | def get_clang_experimental_target_arch(bb, d): |
| 49 | return get_clang_experimental_arch(bb, d, 'TARGET_ARCH') |
| 50 | |
| 51 | PACKAGECONFIG ??= "compiler-rt libcplusplus shared-libs ${@bb.utils.filter('DISTRO_FEATURES', 'thin-lto full-lto', d)}" |
| 52 | PACKAGECONFIG_class-native = "" |
| 53 | PACKAGECONFIG_class-nativesdk = "thin-lto" |
| 54 | |
| 55 | PACKAGECONFIG[compiler-rt] = "-DCLANG_DEFAULT_RTLIB=compiler-rt,,libcxx,compiler-rt" |
| 56 | PACKAGECONFIG[libcplusplus] = "-DCLANG_DEFAULT_CXX_STDLIB=libc++,,libcxx" |
| 57 | PACKAGECONFIG[thin-lto] = "-DLLVM_ENABLE_LTO=Thin -DLLVM_BINUTILS_INCDIR=${STAGING_INCDIR},,binutils," |
| 58 | PACKAGECONFIG[full-lto] = "-DLLVM_ENABLE_LTO=Full -DLLVM_BINUTILS_INCDIR=${STAGING_INCDIR},,binutils," |
| 59 | PACKAGECONFIG[shared-libs] = "-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ON,,," |
| 60 | PACKAGECONFIG[terminfo] = "-DLLVM_ENABLE_TERMINFO=ON,-DLLVM_ENABLE_TERMINFO=OFF,ncurses," |
| 61 | PACKAGECONFIG[pfm] = "-DLLVM_ENABLE_LIBPFM=ON,-DLLVM_ENABLE_LIBPFM=OFF,libpfm," |
| 62 | PACKAGECONFIG[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 | # |
| 67 | LLVM_TARGETS_TO_BUILD ?= "AArch64;ARM;BPF;Mips;PowerPC;X86" |
| 68 | LLVM_TARGETS_TO_BUILD_append = ";${@get_clang_host_arch(bb, d)};${@get_clang_target_arch(bb, d)}" |
| 69 | |
| 70 | LLVM_TARGETS_TO_BUILD_TARGET ?= "" |
| 71 | LLVM_TARGETS_TO_BUILD_TARGET_append ?= "${@get_clang_target_arch(bb, d)}" |
| 72 | |
| 73 | LLVM_EXPERIMENTAL_TARGETS_TO_BUILD ?= "RISCV" |
| 74 | LLVM_EXPERIMENTAL_TARGETS_TO_BUILD_append = ";${@get_clang_experimental_target_arch(bb, d)}" |
| 75 | |
| 76 | HF = "${@ bb.utils.contains('TUNE_CCARGS_MFLOAT', 'hard', 'hf', '', d)}" |
| 77 | HF[vardepvalue] = "${HF}" |
| 78 | |
| 79 | EXTRA_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 | |
| 98 | EXTRA_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 | " |
| 106 | EXTRA_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 | " |
| 117 | EXTRA_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 | " |
| 128 | EXTRA_OECMAKE_append_class-target_riscv64 = "\ |
| 129 | -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}' \ |
| 130 | " |
| 131 | EXTRA_OECMAKE_append_class-target_riscv32 = "\ |
| 132 | -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD='${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}' \ |
| 133 | " |
| 134 | DEPENDS = "binutils zlib libffi libxml2 ninja-native" |
| 135 | DEPENDS_append_class-nativesdk = " clang-crosssdk-${SDK_ARCH} virtual/${TARGET_PREFIX}binutils-crosssdk" |
| 136 | DEPENDS_append_class-target = " clang-cross-${TARGET_ARCH}" |
| 137 | |
| 138 | BOOTSTRAPSTAGE ?= "" |
| 139 | BOOTSTRAPSTAGE_class-native = "stage2" |
| 140 | INSTALLTARGET ?= "install" |
| 141 | INSTALLTARGET_class-native = "stage2-install" |
| 142 | PASSTRHOUGH ?= "" |
| 143 | PASSTHROUGH_class-native = "\ |
| 144 | CLANG_DEFAULT_RTLIB;CLANG_DEFAULT_CXX_STDLIB;LLVM_BUILD_LLVM_DYLIB;LLVM_LINK_LLVM_DYLIB;\ |
| 145 | LLVM_ENABLE_ASSERTIONS;LLVM_ENABLE_EXPENSIVE_CHECKS;LLVM_ENABLE_PIC;\ |
| 146 | LLVM_BINDINGS_LIST;LLVM_ENABLE_FFI;FFI_INCLUDE_DIR;LLVM_OPTIMIZED_TABLEGEN;\ |
| 147 | LLVM_ENABLE_RTTI;LLVM_ENABLE_EH;LLVM_BUILD_EXTERNAL_COMPILER_RT;CMAKE_SYSTEM_NAME;\ |
| 148 | CMAKE_BUILD_TYPE;BUILD_SHARED_LIBS;LLVM_ENABLE_PROJECTS;LLVM_BINUTILS_INCDIR;\ |
| 149 | LLVM_TARGETS_TO_BUILD;LLVM_EXPERIMENTAL_TARGETS_TO_BUILD;\ |
| 150 | " |
| 151 | |
| 152 | RRECOMMENDS_${PN} = "binutils" |
| 153 | RRECOMMENDS_${PN}_append_class-target = " libcxx-dev" |
| 154 | |
| 155 | do_compile() { |
| 156 | ninja ${PARALLEL_MAKE} ${BOOTSTRAPSTAGE} |
| 157 | } |
| 158 | |
| 159 | do_install() { |
| 160 | DESTDIR=${D} ninja ${PARALLEL_MAKE} ${INSTALLTARGET} |
| 161 | } |
| 162 | |
| 163 | do_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 | |
| 171 | do_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 | |
| 180 | PACKAGE_DEBUG_SPLIT_STYLE_class-nativesdk = "debug-without-src" |
| 181 | |
| 182 | PACKAGES =+ "${PN}-libllvm" |
| 183 | |
| 184 | BBCLASSEXTEND = "native nativesdk" |
| 185 | |
| 186 | FILES_${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 | |
| 195 | FILES_${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 | |
| 201 | FILES_${PN}-dev += "\ |
| 202 | ${datadir}/llvm/cmake \ |
| 203 | ${libdir}/cmake \ |
| 204 | " |
| 205 | |
| 206 | INSANE_SKIP_${PN} += "already-stripped" |
| 207 | INSANE_SKIP_${PN}-dev += "dev-elf" |
| 208 | |
| 209 | #Avoid SSTATE_SCAN_COMMAND running sed over llvm-config. |
| 210 | SSTATE_SCAN_FILES_remove = "*-config" |
| 211 | |
| 212 | TOOLCHAIN = "clang" |
| 213 | TOOLCHAIN_class-native = "gcc" |
| 214 | TOOLCHAIN_class-nativesdk = "clang" |