blob: db6694339c54ead796d3d7ed81dad3822fe49f39 [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
Andrew Geissler82c905d2020-04-13 13:39:40 -050013COMPATIBLE_HOST_riscv64 = "null"
14COMPATIBLE_HOST_riscv32 = "null"
15
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016RDEPENDS_${PN}_append_class-target = " ncurses-terminfo"
17
Brad Bishop19323692019-04-05 15:28:33 -040018inherit cmake pkgconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -050019
20PROVIDES += "llvm${PV}"
21
Andrew Geissler90fd73c2021-03-05 15:25:55 -060022MAJOR_VERSION = "11"
23MINOR_VERSION = "1"
24PATCH_VERSION = "0"
Brad Bishopf3f93bb2019-10-16 14:33:32 -040025
26PV = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
27
Brad Bishopd7bf8c12018-02-25 22:55:05 -050028LLVM_RELEASE = "${PV}"
29LLVM_DIR = "llvm${LLVM_RELEASE}"
30
Brad Bishop19323692019-04-05 15:28:33 -040031BRANCH = "release/${MAJOR_VERSION}.x"
Andrew Geissler90fd73c2021-03-05 15:25:55 -060032SRCREV = "1fdec59bffc11ae37eb51a1b9869f0696bfd5312"
Brad Bishop19323692019-04-05 15:28:33 -040033SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH} \
Brad Bishop08902b02019-08-20 09:16:51 -040034 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 Geissler09209ee2020-12-13 08:44:15 -060036 file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \
Andrew Geissler90fd73c2021-03-05 15:25:55 -060037 file://0001-nfc-Fix-missing-include.patch;striplevel=2 \
Andrew Geissler09209ee2020-12-13 08:44:15 -060038 "
Brad Bishop19323692019-04-05 15:28:33 -040039
Andrew Geissler82c905d2020-04-13 13:39:40 -050040UPSTREAM_CHECK_GITTAGREGEX = "llvmorg-(?P<pver>\d+(\.\d+)+)"
41
Brad Bishop19323692019-04-05 15:28:33 -040042S = "${WORKDIR}/git/llvm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050043
44LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
Brad Bishop19323692019-04-05 15:28:33 -040045
Brad Bishopd7bf8c12018-02-25 22:55:05 -050046def get_llvm_arch(bb, d, arch_var):
47 import re
48 a = d.getVar(arch_var)
Brad Bishop19323692019-04-05 15:28:33 -040049 if re.match(r'(i.86|athlon|x86.64)$', a): return 'X86'
50 elif re.match(r'arm$', a): return 'ARM'
51 elif re.match(r'armeb$', a): return 'ARM'
52 elif re.match(r'aarch64$', a): return 'AArch64'
53 elif re.match(r'aarch64_be$', a): return 'AArch64'
54 elif re.match(r'mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
Brad Bishopf3f93bb2019-10-16 14:33:32 -040055 elif re.match(r'riscv(32|64)(eb|)$', a): return 'RISCV'
Brad Bishop19323692019-04-05 15:28:33 -040056 elif re.match(r'p(pc|owerpc)(|64)', a): return 'PowerPC'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050057 else:
58 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
59
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080060def get_llvm_host_arch(bb, d):
61 return get_llvm_arch(bb, d, 'HOST_ARCH')
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
68ARM_INSTRUCTION_SET_armv5 = "arm"
69ARM_INSTRUCTION_SET_armv4t = "arm"
70
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
85EXTRA_OECMAKE_append_class-target = "\
86 -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
91EXTRA_OECMAKE_append_class-nativesdk = "\
92 -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
97do_configure_prepend() {
98# Fix paths in llvm-config
99 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
100 sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp
101 sed -ri "s#lib/${LLVM_DIR}#${baselib}/${LLVM_DIR}#g" ${S}/tools/llvm-config/llvm-config.cpp
102}
103
Andrew Geissler09209ee2020-12-13 08:44:15 -0600104# patch out build host paths for reproducibility
105do_compile_prepend_class-target() {
106 sed -i -e "s,${WORKDIR},,g" ${B}/tools/llvm-config/BuildVariables.inc
107}
108
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500109do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400110 ninja -v ${PARALLEL_MAKE}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500111}
112
113do_compile_class-native() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400114 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500115}
116
117do_install() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400118 DESTDIR=${LLVM_INSTALL_DIR} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500119 install -D -m 0755 ${B}/bin/llvm-config ${D}${libdir}/${LLVM_DIR}/llvm-config
120
121 install -d ${D}${bindir}/${LLVM_DIR}
122 cp -r ${LLVM_INSTALL_DIR}${bindir}/* ${D}${bindir}/${LLVM_DIR}/
123
124 install -d ${D}${includedir}/${LLVM_DIR}
125 cp -r ${LLVM_INSTALL_DIR}${includedir}/* ${D}${includedir}/${LLVM_DIR}/
126
127 install -d ${D}${libdir}/${LLVM_DIR}
128
129 # The LLVM sources have "/lib" embedded and so we cannot completely rely on the ${libdir} variable
130 if [ -d ${LLVM_INSTALL_DIR}${libdir}/ ]; then
131 cp -r ${LLVM_INSTALL_DIR}${libdir}/* ${D}${libdir}/${LLVM_DIR}/
132 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib ]; then
133 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib/* ${D}${libdir}/${LLVM_DIR}/
134 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib64 ]; then
135 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib64/* ${D}${libdir}/${LLVM_DIR}/
136 fi
137
138 # Remove unnecessary cmake files
139 rm -rf ${D}${libdir}/${LLVM_DIR}/cmake
140
Brad Bishop19323692019-04-05 15:28:33 -0400141 ln -s ${LLVM_DIR}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV} ${D}${libdir}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500142
143 # We'll have to delete the libLLVM.so due to multiple reasons...
144 rm -rf ${D}${libdir}/${LLVM_DIR}/libLLVM.so
145 rm -rf ${D}${libdir}/${LLVM_DIR}/libLTO.so
146}
Brad Bishop19323692019-04-05 15:28:33 -0400147
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500148do_install_class-native() {
149 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
150 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
Brad Bishop19323692019-04-05 15:28:33 -0400151 install -D -m 0755 ${B}/lib/libLLVM-${MAJOR_VERSION}.so ${D}${libdir}/libLLVM-${MAJOR_VERSION}.so
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500152}
153
Brad Bishop19323692019-04-05 15:28:33 -0400154PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500155
Brad Bishop19323692019-04-05 15:28:33 -0400156RRECOMMENDS_${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500157
158FILES_${PN}-bugpointpasses = "\
159 ${libdir}/${LLVM_DIR}/BugpointPasses.so \
160"
Brad Bishop19323692019-04-05 15:28:33 -0400161
162FILES_${PN}-libllvm = "\
163 ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.so \
164 ${libdir}/libLLVM-${MAJOR_VERSION}.so \
165"
166
167FILES_${PN}-liblto += "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500168 ${libdir}/${LLVM_DIR}/libLTO.so.* \
169"
170
Brad Bishop19323692019-04-05 15:28:33 -0400171FILES_${PN}-liboptremarks += "\
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400172 ${libdir}/${LLVM_DIR}/libRemarks.so.* \
Brad Bishop19323692019-04-05 15:28:33 -0400173"
174
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500175FILES_${PN}-llvmhello = "\
176 ${libdir}/${LLVM_DIR}/LLVMHello.so \
177"
178
Brad Bishop19323692019-04-05 15:28:33 -0400179FILES_${PN}-dev += " \
180 ${libdir}/${LLVM_DIR}/llvm-config \
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400181 ${libdir}/${LLVM_DIR}/libRemarks.so \
Brad Bishop19323692019-04-05 15:28:33 -0400182 ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.so \
183"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500184
Brad Bishop19323692019-04-05 15:28:33 -0400185FILES_${PN}-staticdev += "\
186 ${libdir}/${LLVM_DIR}/*.a \
187"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500188
Brad Bishop19323692019-04-05 15:28:33 -0400189INSANE_SKIP_${PN}-libllvm += "dev-so"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500190
191BBCLASSEXTEND = "native nativesdk"