blob: 9a88549260aa21691a1069eaf66b5bbe76a583f2 [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
Patrick Williams8e7b46e2023-05-01 14:19:06 -05004SUMMARY = "The LLVM Compiler Infrastructure"
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005HOMEPAGE = "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
Patrick Williams7784c422022-11-17 07:29:11 -060011DEPENDS = "libffi libxml2 zlib zstd libedit ninja-native llvm-native"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012
Patrick Williams213cb262021-08-07 19:21:33 -050013RDEPENDS:${PN}:append:class-target = " ncurses-terminfo"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014
Brad Bishop19323692019-04-05 15:28:33 -040015inherit cmake pkgconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016
Patrick Williamsda295312023-12-05 16:48:56 -060017PV = "17.0.6"
Brad Bishopf3f93bb2019-10-16 14:33:32 -040018
Andrew Geissler5f350902021-07-23 13:09:54 -040019MAJOR_VERSION = "${@oe.utils.trim_version("${PV}", 1)}"
Brad Bishopf3f93bb2019-10-16 14:33:32 -040020
Brad Bishopd7bf8c12018-02-25 22:55:05 -050021LLVM_RELEASE = "${PV}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050022
Brad Bishop19323692019-04-05 15:28:33 -040023BRANCH = "release/${MAJOR_VERSION}.x"
Patrick Williamsda295312023-12-05 16:48:56 -060024SRCREV = "6009708b4367171ccdbf4b5905cb6a803753fe18"
Andrew Geissler595f6302022-01-24 19:11:47 +000025SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH};protocol=https \
Brad Bishop08902b02019-08-20 09:16:51 -040026 file://0007-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \
Andrew Geissler09209ee2020-12-13 08:44:15 -060027 file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \
Patrick Williams92b42cb2022-09-03 06:53:57 -050028 file://llvm-config \
Andrew Geissler09209ee2020-12-13 08:44:15 -060029 "
Brad Bishop19323692019-04-05 15:28:33 -040030
Andrew Geissler82c905d2020-04-13 13:39:40 -050031UPSTREAM_CHECK_GITTAGREGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)"
32
Brad Bishop19323692019-04-05 15:28:33 -040033S = "${WORKDIR}/git/llvm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050034
35LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
Brad Bishop19323692019-04-05 15:28:33 -040036
Brad Bishopd7bf8c12018-02-25 22:55:05 -050037def get_llvm_arch(bb, d, arch_var):
38 import re
39 a = d.getVar(arch_var)
Brad Bishop19323692019-04-05 15:28:33 -040040 if re.match(r'(i.86|athlon|x86.64)$', a): return 'X86'
41 elif re.match(r'arm$', a): return 'ARM'
42 elif re.match(r'armeb$', a): return 'ARM'
43 elif re.match(r'aarch64$', a): return 'AArch64'
44 elif re.match(r'aarch64_be$', a): return 'AArch64'
45 elif re.match(r'mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
Brad Bishopf3f93bb2019-10-16 14:33:32 -040046 elif re.match(r'riscv(32|64)(eb|)$', a): return 'RISCV'
Brad Bishop19323692019-04-05 15:28:33 -040047 elif re.match(r'p(pc|owerpc)(|64)', a): return 'PowerPC'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050048 else:
49 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
50
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080051def get_llvm_host_arch(bb, d):
52 return get_llvm_arch(bb, d, 'HOST_ARCH')
53
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050054PACKAGECONFIG ??= "libllvm"
55PACKAGECONFIG:class-native = "${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'libllvm', '', d)}"
Andrew Geissler615f2f12022-07-15 14:00:58 -050056# if optviewer OFF, force the modules to be not found or the ones on the host would be found
57PACKAGECONFIG[optviewer] = ",-DPY_PYGMENTS_FOUND=OFF -DPY_PYGMENTS_LEXERS_C_CPP_FOUND=OFF -DPY_YAML_FOUND=OFF,python3-pygments python3-pyyaml,python3-pygments python3-pyyaml"
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050058PACKAGECONFIG[libllvm] = ""
Andrew Geissler615f2f12022-07-15 14:00:58 -050059
Brad Bishopd7bf8c12018-02-25 22:55:05 -050060#
61# Default to build all OE-Core supported target arches (user overridable).
62#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080063LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050064
Patrick Williams213cb262021-08-07 19:21:33 -050065ARM_INSTRUCTION_SET:armv5 = "arm"
66ARM_INSTRUCTION_SET:armv4t = "arm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050067
68EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
69 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
70 -DLLVM_ENABLE_PIC=ON \
71 -DLLVM_BINDINGS_LIST='' \
72 -DLLVM_LINK_LLVM_DYLIB=ON \
73 -DLLVM_ENABLE_FFI=ON \
Brad Bishop19323692019-04-05 15:28:33 -040074 -DLLVM_ENABLE_RTTI=ON \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050075 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
76 -DLLVM_OPTIMIZED_TABLEGEN=ON \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080077 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \
Brad Bishop19323692019-04-05 15:28:33 -040078 -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
Patrick Williams2390b1b2022-11-03 13:47:49 -050079 -DCMAKE_BUILD_TYPE=Release \
Patrick Williams8e7b46e2023-05-01 14:19:06 -050080 "
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081
Patrick Williams213cb262021-08-07 19:21:33 -050082EXTRA_OECMAKE:append:class-target = "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -050083 -DCMAKE_CROSSCOMPILING:BOOL=ON \
84 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080085 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050086 "
87
Patrick Williams213cb262021-08-07 19:21:33 -050088EXTRA_OECMAKE:append:class-nativesdk = "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -050089 -DCMAKE_CROSSCOMPILING:BOOL=ON \
90 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080091 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050092 "
93
Andrew Geissler09209ee2020-12-13 08:44:15 -060094# patch out build host paths for reproducibility
Patrick Williams213cb262021-08-07 19:21:33 -050095do_compile:prepend:class-target() {
Andrew Geissler09209ee2020-12-13 08:44:15 -060096 sed -i -e "s,${WORKDIR},,g" ${B}/tools/llvm-config/BuildVariables.inc
97}
98
Brad Bishopd7bf8c12018-02-25 22:55:05 -050099do_compile() {
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500100 if ${@bb.utils.contains('PACKAGECONFIG', 'libllvm', 'true', 'false', d)}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400101 ninja -v ${PARALLEL_MAKE}
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500102 else
Brad Bishop316dfdd2018-06-25 12:45:53 -0400103 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500104 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500105}
106
107do_install() {
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500108 if ${@bb.utils.contains('PACKAGECONFIG', 'libllvm', 'true', 'false', d)}; then
Patrick Williams03907ee2022-05-01 06:28:52 -0500109 DESTDIR=${D} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110
Patrick Williams03907ee2022-05-01 06:28:52 -0500111 # llvm harcodes usr/lib as install path, so this corrects it to actual libdir
112 mv -T -n ${D}/${prefix}/lib ${D}/${libdir} || true
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500113
Patrick Williams03907ee2022-05-01 06:28:52 -0500114 # Remove opt-viewer: https://llvm.org/docs/Remarks.html
115 rm -rf ${D}${datadir}/opt-viewer
116 rmdir ${D}${datadir}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500117
Patrick Williams03907ee2022-05-01 06:28:52 -0500118 # reproducibility
119 sed -i -e 's,${WORKDIR},,g' ${D}/${libdir}/cmake/llvm/LLVMConfig.cmake
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500120 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500121}
Brad Bishop19323692019-04-05 15:28:33 -0400122
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500123do_install:append:class-native() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500124 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
125 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
Patrick Williams92b42cb2022-09-03 06:53:57 -0500126 ln -sf llvm-config${PV} ${D}${bindir}/llvm-config
127}
128
129SYSROOT_PREPROCESS_FUNCS:append:class-target = " llvm_sysroot_preprocess"
130
131llvm_sysroot_preprocess() {
132 install -d ${SYSROOT_DESTDIR}${bindir_crossscripts}/
133 install -m 0755 ${WORKDIR}/llvm-config ${SYSROOT_DESTDIR}${bindir_crossscripts}/
134 ln -sf llvm-config ${SYSROOT_DESTDIR}${bindir_crossscripts}/llvm-config${PV}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500135}
136
Brad Bishop19323692019-04-05 15:28:33 -0400137PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500138
Patrick Williams213cb262021-08-07 19:21:33 -0500139RRECOMMENDS:${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140
Patrick Williams213cb262021-08-07 19:21:33 -0500141FILES:${PN}-bugpointpasses = "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500142 ${libdir}/BugpointPasses.so \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500143"
Brad Bishop19323692019-04-05 15:28:33 -0400144
Patrick Williams213cb262021-08-07 19:21:33 -0500145FILES:${PN}-libllvm = "\
Brad Bishop19323692019-04-05 15:28:33 -0400146 ${libdir}/libLLVM-${MAJOR_VERSION}.so \
147"
148
Patrick Williams213cb262021-08-07 19:21:33 -0500149FILES:${PN}-liblto += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500150 ${libdir}/libLTO.so.* \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500151"
152
Patrick Williams213cb262021-08-07 19:21:33 -0500153FILES:${PN}-liboptremarks += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500154 ${libdir}/libRemarks.so.* \
Brad Bishop19323692019-04-05 15:28:33 -0400155"
156
Patrick Williams213cb262021-08-07 19:21:33 -0500157FILES:${PN}-llvmhello = "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500158 ${libdir}/LLVMHello.so \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500159"
160
Patrick Williams213cb262021-08-07 19:21:33 -0500161FILES:${PN}-dev += " \
Patrick Williams03907ee2022-05-01 06:28:52 -0500162 ${libdir}/llvm-config \
163 ${libdir}/libRemarks.so \
164 ${libdir}/libLLVM-${PV}.so \
Brad Bishop19323692019-04-05 15:28:33 -0400165"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500166
Patrick Williams213cb262021-08-07 19:21:33 -0500167FILES:${PN}-staticdev += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500168 ${libdir}/*.a \
Brad Bishop19323692019-04-05 15:28:33 -0400169"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500170
Patrick Williams213cb262021-08-07 19:21:33 -0500171INSANE_SKIP:${PN}-libllvm += "dev-so"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500172
173BBCLASSEXTEND = "native nativesdk"