blob: de79adc410b5fc2e234d8a36dac91e368f90dde0 [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 Geissler5f350902021-07-23 13:09:54 -040022PV = "12.0.0"
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}"
27LLVM_DIR = "llvm${LLVM_RELEASE}"
28
Brad Bishop19323692019-04-05 15:28:33 -040029BRANCH = "release/${MAJOR_VERSION}.x"
Andrew Geisslerc926e172021-05-07 16:11:35 -050030SRCREV = "fa0971b87fb2c9d14d1bba2551e61f02f18f329b"
Brad Bishop19323692019-04-05 15:28:33 -040031SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH} \
Brad Bishop08902b02019-08-20 09:16:51 -040032 file://0006-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch;striplevel=2 \
33 file://0007-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \
Andrew Geissler09209ee2020-12-13 08:44:15 -060034 file://0001-AsmMatcherEmitter-sort-ClassInfo-lists-by-name-as-we.patch;striplevel=2 \
35 "
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
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
65ARM_INSTRUCTION_SET_armv5 = "arm"
66ARM_INSTRUCTION_SET_armv4t = "arm"
67
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 \
Brad Bishop79641f22019-09-10 07:20:22 -040079 -DPYTHON_EXECUTABLE=${HOSTTOOLS_DIR}/python3 \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050080 -G Ninja"
81
82EXTRA_OECMAKE_append_class-target = "\
83 -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
88EXTRA_OECMAKE_append_class-nativesdk = "\
89 -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
94do_configure_prepend() {
95# Fix paths in llvm-config
96 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
97 sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp
98 sed -ri "s#lib/${LLVM_DIR}#${baselib}/${LLVM_DIR}#g" ${S}/tools/llvm-config/llvm-config.cpp
99}
100
Andrew Geissler09209ee2020-12-13 08:44:15 -0600101# patch out build host paths for reproducibility
102do_compile_prepend_class-target() {
103 sed -i -e "s,${WORKDIR},,g" ${B}/tools/llvm-config/BuildVariables.inc
104}
105
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500106do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400107 ninja -v ${PARALLEL_MAKE}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108}
109
110do_compile_class-native() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400111 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500112}
113
114do_install() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400115 DESTDIR=${LLVM_INSTALL_DIR} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500116 install -D -m 0755 ${B}/bin/llvm-config ${D}${libdir}/${LLVM_DIR}/llvm-config
117
118 install -d ${D}${bindir}/${LLVM_DIR}
119 cp -r ${LLVM_INSTALL_DIR}${bindir}/* ${D}${bindir}/${LLVM_DIR}/
120
121 install -d ${D}${includedir}/${LLVM_DIR}
122 cp -r ${LLVM_INSTALL_DIR}${includedir}/* ${D}${includedir}/${LLVM_DIR}/
123
124 install -d ${D}${libdir}/${LLVM_DIR}
125
126 # The LLVM sources have "/lib" embedded and so we cannot completely rely on the ${libdir} variable
127 if [ -d ${LLVM_INSTALL_DIR}${libdir}/ ]; then
128 cp -r ${LLVM_INSTALL_DIR}${libdir}/* ${D}${libdir}/${LLVM_DIR}/
129 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib ]; then
130 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib/* ${D}${libdir}/${LLVM_DIR}/
131 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib64 ]; then
132 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib64/* ${D}${libdir}/${LLVM_DIR}/
133 fi
134
135 # Remove unnecessary cmake files
136 rm -rf ${D}${libdir}/${LLVM_DIR}/cmake
137
Brad Bishop19323692019-04-05 15:28:33 -0400138 ln -s ${LLVM_DIR}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV} ${D}${libdir}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500139
140 # We'll have to delete the libLLVM.so due to multiple reasons...
141 rm -rf ${D}${libdir}/${LLVM_DIR}/libLLVM.so
142 rm -rf ${D}${libdir}/${LLVM_DIR}/libLTO.so
143}
Brad Bishop19323692019-04-05 15:28:33 -0400144
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500145do_install_class-native() {
146 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
147 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
Brad Bishop19323692019-04-05 15:28:33 -0400148 install -D -m 0755 ${B}/lib/libLLVM-${MAJOR_VERSION}.so ${D}${libdir}/libLLVM-${MAJOR_VERSION}.so
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500149}
150
Brad Bishop19323692019-04-05 15:28:33 -0400151PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500152
Brad Bishop19323692019-04-05 15:28:33 -0400153RRECOMMENDS_${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500154
155FILES_${PN}-bugpointpasses = "\
156 ${libdir}/${LLVM_DIR}/BugpointPasses.so \
157"
Brad Bishop19323692019-04-05 15:28:33 -0400158
159FILES_${PN}-libllvm = "\
160 ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.so \
161 ${libdir}/libLLVM-${MAJOR_VERSION}.so \
162"
163
164FILES_${PN}-liblto += "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500165 ${libdir}/${LLVM_DIR}/libLTO.so.* \
166"
167
Brad Bishop19323692019-04-05 15:28:33 -0400168FILES_${PN}-liboptremarks += "\
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400169 ${libdir}/${LLVM_DIR}/libRemarks.so.* \
Brad Bishop19323692019-04-05 15:28:33 -0400170"
171
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500172FILES_${PN}-llvmhello = "\
173 ${libdir}/${LLVM_DIR}/LLVMHello.so \
174"
175
Brad Bishop19323692019-04-05 15:28:33 -0400176FILES_${PN}-dev += " \
177 ${libdir}/${LLVM_DIR}/llvm-config \
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400178 ${libdir}/${LLVM_DIR}/libRemarks.so \
Andrew Geissler5f350902021-07-23 13:09:54 -0400179 ${libdir}/${LLVM_DIR}/libLLVM-${PV}.so \
Brad Bishop19323692019-04-05 15:28:33 -0400180"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500181
Brad Bishop19323692019-04-05 15:28:33 -0400182FILES_${PN}-staticdev += "\
183 ${libdir}/${LLVM_DIR}/*.a \
184"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500185
Brad Bishop19323692019-04-05 15:28:33 -0400186INSANE_SKIP_${PN}-libllvm += "dev-so"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500187
188BBCLASSEXTEND = "native nativesdk"