blob: f133653903ef4f8728231952d68f899a3da89827 [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
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 -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
Patrick Williams864cc432023-02-09 14:54:44 -060022PV = "15.0.7"
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"
Patrick Williams864cc432023-02-09 14:54:44 -060029SRCREV = "8dfdcc7b7bf66834a761bd8de445840ef68e4d1a"
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://0007-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \
Andrew Geissler09209ee2020-12-13 08:44:15 -060032 file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \
Andrew Geissler517393d2023-01-13 08:55:19 -060033 file://0035-cmake-Enable-64bit-off_t-on-32bit-glibc-systems.patch;striplevel=2 \
Patrick Williams92b42cb2022-09-03 06:53:57 -050034 file://llvm-config \
Andrew Geissler09209ee2020-12-13 08:44:15 -060035 "
Brad Bishop19323692019-04-05 15:28:33 -040036
Andrew Geissler82c905d2020-04-13 13:39:40 -050037UPSTREAM_CHECK_GITTAGREGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)"
38
Brad Bishop19323692019-04-05 15:28:33 -040039S = "${WORKDIR}/git/llvm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050040
41LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
Brad Bishop19323692019-04-05 15:28:33 -040042
Brad Bishopd7bf8c12018-02-25 22:55:05 -050043def get_llvm_arch(bb, d, arch_var):
44 import re
45 a = d.getVar(arch_var)
Brad Bishop19323692019-04-05 15:28:33 -040046 if re.match(r'(i.86|athlon|x86.64)$', a): return 'X86'
47 elif re.match(r'arm$', a): return 'ARM'
48 elif re.match(r'armeb$', a): return 'ARM'
49 elif re.match(r'aarch64$', a): return 'AArch64'
50 elif re.match(r'aarch64_be$', a): return 'AArch64'
51 elif re.match(r'mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
Brad Bishopf3f93bb2019-10-16 14:33:32 -040052 elif re.match(r'riscv(32|64)(eb|)$', a): return 'RISCV'
Brad Bishop19323692019-04-05 15:28:33 -040053 elif re.match(r'p(pc|owerpc)(|64)', a): return 'PowerPC'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050054 else:
55 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
56
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080057def get_llvm_host_arch(bb, d):
58 return get_llvm_arch(bb, d, 'HOST_ARCH')
59
Andrew Geisslerfc113ea2023-03-31 09:59:46 -050060PACKAGECONFIG ??= "libllvm"
61PACKAGECONFIG:class-native = "${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'libllvm', '', d)}"
Andrew Geissler615f2f12022-07-15 14:00:58 -050062# if optviewer OFF, force the modules to be not found or the ones on the host would be found
63PACKAGECONFIG[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 -050064PACKAGECONFIG[libllvm] = ""
Andrew Geissler615f2f12022-07-15 14:00:58 -050065
Brad Bishopd7bf8c12018-02-25 22:55:05 -050066#
67# Default to build all OE-Core supported target arches (user overridable).
68#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080069LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070
Patrick Williams213cb262021-08-07 19:21:33 -050071ARM_INSTRUCTION_SET:armv5 = "arm"
72ARM_INSTRUCTION_SET:armv4t = "arm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050073
74EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
75 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
76 -DLLVM_ENABLE_PIC=ON \
77 -DLLVM_BINDINGS_LIST='' \
78 -DLLVM_LINK_LLVM_DYLIB=ON \
79 -DLLVM_ENABLE_FFI=ON \
Brad Bishop19323692019-04-05 15:28:33 -040080 -DLLVM_ENABLE_RTTI=ON \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
82 -DLLVM_OPTIMIZED_TABLEGEN=ON \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080083 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \
Brad Bishop19323692019-04-05 15:28:33 -040084 -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
Brad Bishop79641f22019-09-10 07:20:22 -040085 -DPYTHON_EXECUTABLE=${HOSTTOOLS_DIR}/python3 \
Patrick Williams2390b1b2022-11-03 13:47:49 -050086 -DCMAKE_BUILD_TYPE=Release \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087 -G Ninja"
88
Patrick Williams213cb262021-08-07 19:21:33 -050089EXTRA_OECMAKE:append:class-target = "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -050090 -DCMAKE_CROSSCOMPILING:BOOL=ON \
91 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080092 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093 "
94
Patrick Williams213cb262021-08-07 19:21:33 -050095EXTRA_OECMAKE:append:class-nativesdk = "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -050096 -DCMAKE_CROSSCOMPILING:BOOL=ON \
97 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080098 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050099 "
100
Andrew Geissler09209ee2020-12-13 08:44:15 -0600101# patch out build host paths for reproducibility
Patrick Williams213cb262021-08-07 19:21:33 -0500102do_compile:prepend:class-target() {
Andrew Geissler09209ee2020-12-13 08:44:15 -0600103 sed -i -e "s,${WORKDIR},,g" ${B}/tools/llvm-config/BuildVariables.inc
104}
105
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500106do_compile() {
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500107 if ${@bb.utils.contains('PACKAGECONFIG', 'libllvm', 'true', 'false', d)}; then
Brad Bishop316dfdd2018-06-25 12:45:53 -0400108 ninja -v ${PARALLEL_MAKE}
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500109 else
Brad Bishop316dfdd2018-06-25 12:45:53 -0400110 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500111 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112}
113
114do_install() {
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500115 if ${@bb.utils.contains('PACKAGECONFIG', 'libllvm', 'true', 'false', d)}; then
Patrick Williams03907ee2022-05-01 06:28:52 -0500116 DESTDIR=${D} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500117
Patrick Williams03907ee2022-05-01 06:28:52 -0500118 # llvm harcodes usr/lib as install path, so this corrects it to actual libdir
119 mv -T -n ${D}/${prefix}/lib ${D}/${libdir} || true
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500120
Patrick Williams03907ee2022-05-01 06:28:52 -0500121 # Remove opt-viewer: https://llvm.org/docs/Remarks.html
122 rm -rf ${D}${datadir}/opt-viewer
123 rmdir ${D}${datadir}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500124
Patrick Williams03907ee2022-05-01 06:28:52 -0500125 # reproducibility
126 sed -i -e 's,${WORKDIR},,g' ${D}/${libdir}/cmake/llvm/LLVMConfig.cmake
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500127 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500128}
Brad Bishop19323692019-04-05 15:28:33 -0400129
Andrew Geisslerfc113ea2023-03-31 09:59:46 -0500130do_install:append:class-native() {
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500131 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
132 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
Patrick Williams92b42cb2022-09-03 06:53:57 -0500133 ln -sf llvm-config${PV} ${D}${bindir}/llvm-config
134}
135
136SYSROOT_PREPROCESS_FUNCS:append:class-target = " llvm_sysroot_preprocess"
137
138llvm_sysroot_preprocess() {
139 install -d ${SYSROOT_DESTDIR}${bindir_crossscripts}/
140 install -m 0755 ${WORKDIR}/llvm-config ${SYSROOT_DESTDIR}${bindir_crossscripts}/
141 ln -sf llvm-config ${SYSROOT_DESTDIR}${bindir_crossscripts}/llvm-config${PV}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500142}
143
Brad Bishop19323692019-04-05 15:28:33 -0400144PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500145
Patrick Williams213cb262021-08-07 19:21:33 -0500146RRECOMMENDS:${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500147
Patrick Williams213cb262021-08-07 19:21:33 -0500148FILES:${PN}-bugpointpasses = "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500149 ${libdir}/BugpointPasses.so \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500150"
Brad Bishop19323692019-04-05 15:28:33 -0400151
Patrick Williams213cb262021-08-07 19:21:33 -0500152FILES:${PN}-libllvm = "\
Brad Bishop19323692019-04-05 15:28:33 -0400153 ${libdir}/libLLVM-${MAJOR_VERSION}.so \
154"
155
Patrick Williams213cb262021-08-07 19:21:33 -0500156FILES:${PN}-liblto += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500157 ${libdir}/libLTO.so.* \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500158"
159
Patrick Williams213cb262021-08-07 19:21:33 -0500160FILES:${PN}-liboptremarks += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500161 ${libdir}/libRemarks.so.* \
Brad Bishop19323692019-04-05 15:28:33 -0400162"
163
Patrick Williams213cb262021-08-07 19:21:33 -0500164FILES:${PN}-llvmhello = "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500165 ${libdir}/LLVMHello.so \
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500166"
167
Patrick Williams213cb262021-08-07 19:21:33 -0500168FILES:${PN}-dev += " \
Patrick Williams03907ee2022-05-01 06:28:52 -0500169 ${libdir}/llvm-config \
170 ${libdir}/libRemarks.so \
171 ${libdir}/libLLVM-${PV}.so \
Brad Bishop19323692019-04-05 15:28:33 -0400172"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500173
Patrick Williams213cb262021-08-07 19:21:33 -0500174FILES:${PN}-staticdev += "\
Patrick Williams03907ee2022-05-01 06:28:52 -0500175 ${libdir}/*.a \
Brad Bishop19323692019-04-05 15:28:33 -0400176"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500177
Patrick Williams213cb262021-08-07 19:21:33 -0500178INSANE_SKIP:${PN}-libllvm += "dev-so"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500179
180BBCLASSEXTEND = "native nativesdk"