blob: 2ec5c1e1c0a364909c4b4c593196771537729e7f [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001# Copyright (C) 2017 Khem Raj <raj.khem@gmail.com>
2# Released under the MIT license (see COPYING.MIT for the terms)
3
4DESCRIPTION = "The LLVM Compiler Infrastructure"
5HOMEPAGE = "http://llvm.org"
Brad Bishopf3f93bb2019-10-16 14:33:32 -04006LICENSE = "Apache-2.0-with-LLVM-exception"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007SECTION = "devel"
8
Brad Bishopf3f93bb2019-10-16 14:33:32 -04009LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=8a15a0759ef07f2682d2ba4b893c9afe"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
Brad Bishop08902b02019-08-20 09:16:51 -040011DEPENDS = "libffi libxml2 zlib libedit ninja-native llvm-native"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012
Patrick Williams213cb262021-08-07 19:21:33 -050013COMPATIBLE_HOST:riscv64 = "null"
14COMPATIBLE_HOST:riscv32 = "null"
Andrew Geissler82c905d2020-04-13 13:39:40 -050015
Patrick Williams213cb262021-08-07 19:21:33 -050016RDEPENDS:${PN}:append:class-target = " ncurses-terminfo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050017
Brad Bishop19323692019-04-05 15:28:33 -040018inherit cmake pkgconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019
20PROVIDES += "llvm${PV}"
21
Andrew Geissler78b72792022-06-14 06:47:25 -050022PV = "14.0.4"
Brad Bishopf3f93bb2019-10-16 14:33:32 -040023
Andrew Geissler5f350902021-07-23 13:09:54 -040024MAJOR_VERSION = "${@oe.utils.trim_version("${PV}", 1)}"
Brad Bishopf3f93bb2019-10-16 14:33:32 -040025
Brad Bishopd7bf8c12018-02-25 22:55:05 -050026LLVM_RELEASE = "${PV}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027
Brad Bishop19323692019-04-05 15:28:33 -040028BRANCH = "release/${MAJOR_VERSION}.x"
Andrew Geissler78b72792022-06-14 06:47:25 -050029SRCREV = "29f1039a7285a5c3a9c353d054140bf2556d4c4d"
Andrew Geissler595f6302022-01-24 19:11:47 +000030SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH};protocol=https \
Brad Bishop08902b02019-08-20 09:16:51 -040031 file://0006-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch;striplevel=2 \
32 file://0007-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \
Andrew Geissler09209ee2020-12-13 08:44:15 -060033 file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \
34 "
Brad Bishop19323692019-04-05 15:28:33 -040035
Andrew Geissler82c905d2020-04-13 13:39:40 -050036UPSTREAM_CHECK_GITTAGREGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)"
37
Brad Bishop19323692019-04-05 15:28:33 -040038S = "${WORKDIR}/git/llvm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039
40LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
Brad Bishop19323692019-04-05 15:28:33 -040041
Brad Bishopd7bf8c12018-02-25 22:55:05 -050042def get_llvm_arch(bb, d, arch_var):
43 import re
44 a = d.getVar(arch_var)
Brad Bishop19323692019-04-05 15:28:33 -040045 if re.match(r'(i.86|athlon|x86.64)$', a): return 'X86'
46 elif re.match(r'arm$', a): return 'ARM'
47 elif re.match(r'armeb$', a): return 'ARM'
48 elif re.match(r'aarch64$', a): return 'AArch64'
49 elif re.match(r'aarch64_be$', a): return 'AArch64'
50 elif re.match(r'mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
Brad Bishopf3f93bb2019-10-16 14:33:32 -040051 elif re.match(r'riscv(32|64)(eb|)$', a): return 'RISCV'
Brad Bishop19323692019-04-05 15:28:33 -040052 elif re.match(r'p(pc|owerpc)(|64)', a): return 'PowerPC'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050053 else:
54 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
55
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080056def get_llvm_host_arch(bb, d):
57 return get_llvm_arch(bb, d, 'HOST_ARCH')
58
Andrew Geissler615f2f12022-07-15 14:00:58 -050059PACKAGECONFIG ??= ""
60# if optviewer OFF, force the modules to be not found or the ones on the host would be found
61PACKAGECONFIG[optviewer] = ",-DPY_PYGMENTS_FOUND=OFF -DPY_PYGMENTS_LEXERS_C_CPP_FOUND=OFF -DPY_YAML_FOUND=OFF,python3-pygments python3-pyyaml,python3-pygments python3-pyyaml"
62
Brad Bishopd7bf8c12018-02-25 22:55:05 -050063#
64# Default to build all OE-Core supported target arches (user overridable).
65#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050067
Patrick Williams213cb262021-08-07 19:21:33 -050068ARM_INSTRUCTION_SET:armv5 = "arm"
69ARM_INSTRUCTION_SET:armv4t = "arm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070
71EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
72 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
73 -DLLVM_ENABLE_PIC=ON \
74 -DLLVM_BINDINGS_LIST='' \
75 -DLLVM_LINK_LLVM_DYLIB=ON \
76 -DLLVM_ENABLE_FFI=ON \
Brad Bishop19323692019-04-05 15:28:33 -040077 -DLLVM_ENABLE_RTTI=ON \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050078 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
79 -DLLVM_OPTIMIZED_TABLEGEN=ON \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \
Brad Bishop19323692019-04-05 15:28:33 -040081 -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
Brad Bishop79641f22019-09-10 07:20:22 -040082 -DPYTHON_EXECUTABLE=${HOSTTOOLS_DIR}/python3 \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050083 -G Ninja"
84
Patrick Williams213cb262021-08-07 19:21:33 -050085EXTRA_OECMAKE:append:class-target = "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -050086 -DCMAKE_CROSSCOMPILING:BOOL=ON \
87 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050089 "
90
Patrick Williams213cb262021-08-07 19:21:33 -050091EXTRA_OECMAKE:append:class-nativesdk = "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -050092 -DCMAKE_CROSSCOMPILING:BOOL=ON \
93 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080094 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050095 "
96
Andrew Geissler09209ee2020-12-13 08:44:15 -060097# patch out build host paths for reproducibility
Patrick Williams213cb262021-08-07 19:21:33 -050098do_compile:prepend:class-target() {
Andrew Geissler09209ee2020-12-13 08:44:15 -060099 sed -i -e "s,${WORKDIR},,g" ${B}/tools/llvm-config/BuildVariables.inc
100}
101
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500102do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400103 ninja -v ${PARALLEL_MAKE}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500104}
105
Patrick Williams213cb262021-08-07 19:21:33 -0500106do_compile:class-native() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400107 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108}
109
110do_install() {
Patrick Williams03907ee2022-05-01 06:28:52 -0500111 DESTDIR=${D} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112
Patrick Williams03907ee2022-05-01 06:28:52 -0500113 # llvm harcodes usr/lib as install path, so this corrects it to actual libdir
114 mv -T -n ${D}/${prefix}/lib ${D}/${libdir} || true
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500115
Patrick Williams03907ee2022-05-01 06:28:52 -0500116 # Remove opt-viewer: https://llvm.org/docs/Remarks.html
117 rm -rf ${D}${datadir}/opt-viewer
118 rmdir ${D}${datadir}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500119
Patrick Williams03907ee2022-05-01 06:28:52 -0500120 # reproducibility
121 sed -i -e 's,${WORKDIR},,g' ${D}/${libdir}/cmake/llvm/LLVMConfig.cmake
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500122}
Brad Bishop19323692019-04-05 15:28:33 -0400123
Patrick Williams213cb262021-08-07 19:21:33 -0500124do_install:class-native() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500125 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
126 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500127}
128
Brad Bishop19323692019-04-05 15:28:33 -0400129PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500130
Patrick Williams213cb262021-08-07 19:21:33 -0500131RRECOMMENDS:${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500132
Patrick Williams213cb262021-08-07 19:21:33 -0500133FILES:${PN}-bugpointpasses = "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500134 ${libdir}/BugpointPasses.so \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500135"
Brad Bishop19323692019-04-05 15:28:33 -0400136
Patrick Williams213cb262021-08-07 19:21:33 -0500137FILES:${PN}-libllvm = "\
Brad Bishop19323692019-04-05 15:28:33 -0400138 ${libdir}/libLLVM-${MAJOR_VERSION}.so \
139"
140
Patrick Williams213cb262021-08-07 19:21:33 -0500141FILES:${PN}-liblto += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500142 ${libdir}/libLTO.so.* \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500143"
144
Patrick Williams213cb262021-08-07 19:21:33 -0500145FILES:${PN}-liboptremarks += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500146 ${libdir}/libRemarks.so.* \
Brad Bishop19323692019-04-05 15:28:33 -0400147"
148
Patrick Williams213cb262021-08-07 19:21:33 -0500149FILES:${PN}-llvmhello = "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500150 ${libdir}/LLVMHello.so \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151"
152
Patrick Williams213cb262021-08-07 19:21:33 -0500153FILES:${PN}-dev += " \
Patrick Williams03907ee2022-05-01 06:28:52 -0500154 ${libdir}/llvm-config \
155 ${libdir}/libRemarks.so \
156 ${libdir}/libLLVM-${PV}.so \
Brad Bishop19323692019-04-05 15:28:33 -0400157"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500158
Patrick Williams213cb262021-08-07 19:21:33 -0500159FILES:${PN}-staticdev += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500160 ${libdir}/*.a \
Brad Bishop19323692019-04-05 15:28:33 -0400161"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500162
Patrick Williams213cb262021-08-07 19:21:33 -0500163INSANE_SKIP:${PN}-libllvm += "dev-so"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164
165BBCLASSEXTEND = "native nativesdk"