| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | # Copyright (C) 2017 Khem Raj <raj.khem@gmail.com> | 
|  | 2 | # Released under the MIT license (see COPYING.MIT for the terms) | 
|  | 3 |  | 
| Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 4 | SUMMARY = "The LLVM Compiler Infrastructure" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | HOMEPAGE = "http://llvm.org" | 
| Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 6 | LICENSE = "Apache-2.0-with-LLVM-exception" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | SECTION = "devel" | 
|  | 8 |  | 
| Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 9 | LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=8a15a0759ef07f2682d2ba4b893c9afe" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 |  | 
| Patrick Williams | 7784c42 | 2022-11-17 07:29:11 -0600 | [diff] [blame] | 11 | DEPENDS = "libffi libxml2 zlib zstd libedit ninja-native llvm-native" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 13 | RDEPENDS:${PN}:append:class-target = " ncurses-terminfo" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 14 |  | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 15 | inherit cmake pkgconfig | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 |  | 
| Patrick Williams | 520786c | 2023-06-25 16:20:36 -0500 | [diff] [blame] | 17 | PV = "16.0.6" | 
| Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 18 |  | 
| Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 19 | MAJOR_VERSION = "${@oe.utils.trim_version("${PV}", 1)}" | 
| Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 20 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 21 | LLVM_RELEASE = "${PV}" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 22 |  | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 23 | BRANCH = "release/${MAJOR_VERSION}.x" | 
| Patrick Williams | 520786c | 2023-06-25 16:20:36 -0500 | [diff] [blame] | 24 | SRCREV = "7cbf1a2591520c2491aa35339f227775f4d3adf6" | 
| Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 25 | SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH};protocol=https \ | 
| Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 26 | file://0007-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \ | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 27 | file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \ | 
| Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 28 | file://llvm-config \ | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 29 | " | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 30 |  | 
| Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 31 | UPSTREAM_CHECK_GITTAGREGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)" | 
|  | 32 |  | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 33 | S = "${WORKDIR}/git/llvm" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 34 |  | 
|  | 35 | LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install" | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 37 | def get_llvm_arch(bb, d, arch_var): | 
|  | 38 | import re | 
|  | 39 | a = d.getVar(arch_var) | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 40 | 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 Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 46 | elif re.match(r'riscv(32|64)(eb|)$', a):            return 'RISCV' | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 47 | elif re.match(r'p(pc|owerpc)(|64)', a):             return 'PowerPC' | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 48 | else: | 
|  | 49 | raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a) | 
|  | 50 |  | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 51 | def get_llvm_host_arch(bb, d): | 
|  | 52 | return get_llvm_arch(bb, d, 'HOST_ARCH') | 
|  | 53 |  | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 54 | PACKAGECONFIG ??= "libllvm" | 
|  | 55 | PACKAGECONFIG:class-native = "${@bb.utils.contains('DISTRO_FEATURES', 'opengl', 'libllvm', '', d)}" | 
| Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 56 | # if optviewer OFF, force the modules to be not found or the ones on the host would be found | 
|  | 57 | PACKAGECONFIG[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 Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 58 | PACKAGECONFIG[libllvm] = "" | 
| Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 59 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 60 | # | 
|  | 61 | # Default to build all OE-Core supported target arches (user overridable). | 
|  | 62 | # | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 63 | LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 65 | ARM_INSTRUCTION_SET:armv5 = "arm" | 
|  | 66 | ARM_INSTRUCTION_SET:armv4t = "arm" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 67 |  | 
|  | 68 | EXTRA_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 Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 74 | -DLLVM_ENABLE_RTTI=ON \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 75 | -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \ | 
|  | 76 | -DLLVM_OPTIMIZED_TABLEGEN=ON \ | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 77 | -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \ | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 78 | -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \ | 
| Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 79 | -DCMAKE_BUILD_TYPE=Release \ | 
| Patrick Williams | 8e7b46e | 2023-05-01 14:19:06 -0500 | [diff] [blame] | 80 | " | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 81 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 82 | EXTRA_OECMAKE:append:class-target = "\ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 83 | -DCMAKE_CROSSCOMPILING:BOOL=ON \ | 
|  | 84 | -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 85 | -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 86 | " | 
|  | 87 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 88 | EXTRA_OECMAKE:append:class-nativesdk = "\ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 89 | -DCMAKE_CROSSCOMPILING:BOOL=ON \ | 
|  | 90 | -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ | 
| Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 91 | -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 92 | " | 
|  | 93 |  | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 94 | # patch out build host paths for reproducibility | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 95 | do_compile:prepend:class-target() { | 
| Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 96 | sed -i -e "s,${WORKDIR},,g" ${B}/tools/llvm-config/BuildVariables.inc | 
|  | 97 | } | 
|  | 98 |  | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 99 | do_compile() { | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 100 | if ${@bb.utils.contains('PACKAGECONFIG', 'libllvm', 'true', 'false', d)}; then | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 101 | ninja -v ${PARALLEL_MAKE} | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 102 | else | 
| Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 103 | ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 104 | fi | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 105 | } | 
|  | 106 |  | 
|  | 107 | do_install() { | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 108 | if ${@bb.utils.contains('PACKAGECONFIG', 'libllvm', 'true', 'false', d)}; then | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 109 | DESTDIR=${D} ninja -v install | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 110 |  | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 111 | # 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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 113 |  | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 114 | # Remove opt-viewer: https://llvm.org/docs/Remarks.html | 
|  | 115 | rm -rf ${D}${datadir}/opt-viewer | 
|  | 116 | rmdir ${D}${datadir} | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 117 |  | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 118 | # reproducibility | 
|  | 119 | sed -i -e 's,${WORKDIR},,g' ${D}/${libdir}/cmake/llvm/LLVMConfig.cmake | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 120 | fi | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 121 | } | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 122 |  | 
| Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 123 | do_install:append:class-native() { | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 124 | 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 Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 126 | ln -sf llvm-config${PV} ${D}${bindir}/llvm-config | 
|  | 127 | } | 
|  | 128 |  | 
|  | 129 | SYSROOT_PREPROCESS_FUNCS:append:class-target = " llvm_sysroot_preprocess" | 
|  | 130 |  | 
|  | 131 | llvm_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 Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 135 | } | 
|  | 136 |  | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 137 | PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 138 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 139 | RRECOMMENDS:${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 140 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 141 | FILES:${PN}-bugpointpasses = "\ | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 142 | ${libdir}/BugpointPasses.so \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 143 | " | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 144 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 145 | FILES:${PN}-libllvm = "\ | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 146 | ${libdir}/libLLVM-${MAJOR_VERSION}.so \ | 
|  | 147 | " | 
|  | 148 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 149 | FILES:${PN}-liblto += "\ | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 150 | ${libdir}/libLTO.so.* \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 151 | " | 
|  | 152 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 153 | FILES:${PN}-liboptremarks += "\ | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 154 | ${libdir}/libRemarks.so.* \ | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 155 | " | 
|  | 156 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 157 | FILES:${PN}-llvmhello = "\ | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 158 | ${libdir}/LLVMHello.so \ | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 159 | " | 
|  | 160 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 161 | FILES:${PN}-dev += " \ | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 162 | ${libdir}/llvm-config \ | 
|  | 163 | ${libdir}/libRemarks.so \ | 
|  | 164 | ${libdir}/libLLVM-${PV}.so \ | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 165 | " | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 166 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 167 | FILES:${PN}-staticdev += "\ | 
| Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 168 | ${libdir}/*.a \ | 
| Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 169 | " | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 170 |  | 
| Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 171 | INSANE_SKIP:${PN}-libllvm += "dev-so" | 
| Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 172 |  | 
|  | 173 | BBCLASSEXTEND = "native nativesdk" |