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 | |
| 4 | DESCRIPTION = "The LLVM Compiler Infrastructure" |
| 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 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 11 | DEPENDS = "libffi libxml2 zlib libedit ninja-native llvm-native" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 13 | COMPATIBLE_HOST_riscv64 = "null" |
| 14 | COMPATIBLE_HOST_riscv32 = "null" |
| 15 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 | RDEPENDS_${PN}_append_class-target = " ncurses-terminfo" |
| 17 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 18 | inherit cmake pkgconfig |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 19 | |
| 20 | PROVIDES += "llvm${PV}" |
| 21 | |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 22 | MAJOR_VERSION = "10" |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 23 | MINOR_VERSION = "0" |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 24 | PATCH_VERSION = "1" |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 25 | |
| 26 | PV = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}" |
| 27 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 28 | LLVM_RELEASE = "${PV}" |
| 29 | LLVM_DIR = "llvm${LLVM_RELEASE}" |
| 30 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 31 | BRANCH = "release/${MAJOR_VERSION}.x" |
Andrew Geissler | 635e0e4 | 2020-08-21 15:58:33 -0500 | [diff] [blame] | 32 | SRCREV = "ef32c611aa214dea855364efd7ba451ec5ec3f74" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 33 | SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH} \ |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 34 | file://0006-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch;striplevel=2 \ |
| 35 | file://0007-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \ |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 36 | file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \ |
| 37 | " |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 38 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 39 | UPSTREAM_CHECK_GITTAGREGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)" |
| 40 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 41 | S = "${WORKDIR}/git/llvm" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 42 | |
| 43 | LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 44 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 45 | def get_llvm_arch(bb, d, arch_var): |
| 46 | import re |
| 47 | a = d.getVar(arch_var) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 48 | if re.match(r'(i.86|athlon|x86.64)$', a): return 'X86' |
| 49 | elif re.match(r'arm$', a): return 'ARM' |
| 50 | elif re.match(r'armeb$', a): return 'ARM' |
| 51 | elif re.match(r'aarch64$', a): return 'AArch64' |
| 52 | elif re.match(r'aarch64_be$', a): return 'AArch64' |
| 53 | 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] | 54 | elif re.match(r'riscv(32|64)(eb|)$', a): return 'RISCV' |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 55 | elif re.match(r'p(pc|owerpc)(|64)', a): return 'PowerPC' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 56 | else: |
| 57 | raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a) |
| 58 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 59 | def get_llvm_host_arch(bb, d): |
| 60 | return get_llvm_arch(bb, d, 'HOST_ARCH') |
| 61 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 62 | # |
| 63 | # Default to build all OE-Core supported target arches (user overridable). |
| 64 | # |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 65 | LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 66 | |
| 67 | ARM_INSTRUCTION_SET_armv5 = "arm" |
| 68 | ARM_INSTRUCTION_SET_armv4t = "arm" |
| 69 | |
| 70 | EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \ |
| 71 | -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \ |
| 72 | -DLLVM_ENABLE_PIC=ON \ |
| 73 | -DLLVM_BINDINGS_LIST='' \ |
| 74 | -DLLVM_LINK_LLVM_DYLIB=ON \ |
| 75 | -DLLVM_ENABLE_FFI=ON \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 76 | -DLLVM_ENABLE_RTTI=ON \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 77 | -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \ |
| 78 | -DLLVM_OPTIMIZED_TABLEGEN=ON \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 79 | -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 80 | -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \ |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 81 | -DPYTHON_EXECUTABLE=${HOSTTOOLS_DIR}/python3 \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 82 | -G Ninja" |
| 83 | |
| 84 | EXTRA_OECMAKE_append_class-target = "\ |
| 85 | -DCMAKE_CROSSCOMPILING:BOOL=ON \ |
| 86 | -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 87 | -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 88 | " |
| 89 | |
| 90 | EXTRA_OECMAKE_append_class-nativesdk = "\ |
| 91 | -DCMAKE_CROSSCOMPILING:BOOL=ON \ |
| 92 | -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 93 | -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 94 | " |
| 95 | |
| 96 | do_configure_prepend() { |
| 97 | # Fix paths in llvm-config |
| 98 | sed -i "s|sys::path::parent_path(CurrentPath))\.str()|sys::path::parent_path(sys::path::parent_path(CurrentPath))).str()|g" ${S}/tools/llvm-config/llvm-config.cpp |
| 99 | sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp |
| 100 | sed -ri "s#lib/${LLVM_DIR}#${baselib}/${LLVM_DIR}#g" ${S}/tools/llvm-config/llvm-config.cpp |
| 101 | } |
| 102 | |
Andrew Geissler | 09209ee | 2020-12-13 08:44:15 -0600 | [diff] [blame] | 103 | # patch out build host paths for reproducibility |
| 104 | do_compile_prepend_class-target() { |
| 105 | sed -i -e "s,${WORKDIR},,g" ${B}/tools/llvm-config/BuildVariables.inc |
| 106 | } |
| 107 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 108 | do_compile() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 109 | ninja -v ${PARALLEL_MAKE} |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | do_compile_class-native() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 113 | ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | do_install() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 117 | DESTDIR=${LLVM_INSTALL_DIR} ninja -v install |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 118 | install -D -m 0755 ${B}/bin/llvm-config ${D}${libdir}/${LLVM_DIR}/llvm-config |
| 119 | |
| 120 | install -d ${D}${bindir}/${LLVM_DIR} |
| 121 | cp -r ${LLVM_INSTALL_DIR}${bindir}/* ${D}${bindir}/${LLVM_DIR}/ |
| 122 | |
| 123 | install -d ${D}${includedir}/${LLVM_DIR} |
| 124 | cp -r ${LLVM_INSTALL_DIR}${includedir}/* ${D}${includedir}/${LLVM_DIR}/ |
| 125 | |
| 126 | install -d ${D}${libdir}/${LLVM_DIR} |
| 127 | |
| 128 | # The LLVM sources have "/lib" embedded and so we cannot completely rely on the ${libdir} variable |
| 129 | if [ -d ${LLVM_INSTALL_DIR}${libdir}/ ]; then |
| 130 | cp -r ${LLVM_INSTALL_DIR}${libdir}/* ${D}${libdir}/${LLVM_DIR}/ |
| 131 | elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib ]; then |
| 132 | cp -r ${LLVM_INSTALL_DIR}${prefix}/lib/* ${D}${libdir}/${LLVM_DIR}/ |
| 133 | elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib64 ]; then |
| 134 | cp -r ${LLVM_INSTALL_DIR}${prefix}/lib64/* ${D}${libdir}/${LLVM_DIR}/ |
| 135 | fi |
| 136 | |
| 137 | # Remove unnecessary cmake files |
| 138 | rm -rf ${D}${libdir}/${LLVM_DIR}/cmake |
| 139 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 140 | ln -s ${LLVM_DIR}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV} ${D}${libdir}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV} |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 141 | |
| 142 | # We'll have to delete the libLLVM.so due to multiple reasons... |
| 143 | rm -rf ${D}${libdir}/${LLVM_DIR}/libLLVM.so |
| 144 | rm -rf ${D}${libdir}/${LLVM_DIR}/libLTO.so |
| 145 | } |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 146 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 147 | do_install_class-native() { |
| 148 | install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV} |
| 149 | install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV} |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 150 | install -D -m 0755 ${B}/lib/libLLVM-${MAJOR_VERSION}.so ${D}${libdir}/libLLVM-${MAJOR_VERSION}.so |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 151 | } |
| 152 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 153 | PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 154 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 155 | RRECOMMENDS_${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 156 | |
| 157 | FILES_${PN}-bugpointpasses = "\ |
| 158 | ${libdir}/${LLVM_DIR}/BugpointPasses.so \ |
| 159 | " |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 160 | |
| 161 | FILES_${PN}-libllvm = "\ |
| 162 | ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.so \ |
| 163 | ${libdir}/libLLVM-${MAJOR_VERSION}.so \ |
| 164 | " |
| 165 | |
| 166 | FILES_${PN}-liblto += "\ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 167 | ${libdir}/${LLVM_DIR}/libLTO.so.* \ |
| 168 | " |
| 169 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 170 | FILES_${PN}-liboptremarks += "\ |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 171 | ${libdir}/${LLVM_DIR}/libRemarks.so.* \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 172 | " |
| 173 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 174 | FILES_${PN}-llvmhello = "\ |
| 175 | ${libdir}/${LLVM_DIR}/LLVMHello.so \ |
| 176 | " |
| 177 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 178 | FILES_${PN}-dev += " \ |
| 179 | ${libdir}/${LLVM_DIR}/llvm-config \ |
Brad Bishop | f3f93bb | 2019-10-16 14:33:32 -0400 | [diff] [blame] | 180 | ${libdir}/${LLVM_DIR}/libRemarks.so \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 181 | ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.so \ |
| 182 | " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 183 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 184 | FILES_${PN}-staticdev += "\ |
| 185 | ${libdir}/${LLVM_DIR}/*.a \ |
| 186 | " |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 187 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 188 | INSANE_SKIP_${PN}-libllvm += "dev-so" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 189 | |
| 190 | BBCLASSEXTEND = "native nativesdk" |