blob: 5f9277fc0f0dae23dcb92e5e33c1114aef674ae0 [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
13RDEPENDS_${PN}_append_class-target = " ncurses-terminfo"
14
Brad Bishop19323692019-04-05 15:28:33 -040015inherit cmake pkgconfig
Brad Bishopd7bf8c12018-02-25 22:55:05 -050016
17PROVIDES += "llvm${PV}"
18
Brad Bishopf3f93bb2019-10-16 14:33:32 -040019MAJOR_VERSION = "9"
20MINOR_VERSION = "0"
21PATCH_VERSION = "0"
22
23PV = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
24
Brad Bishopd7bf8c12018-02-25 22:55:05 -050025LLVM_RELEASE = "${PV}"
26LLVM_DIR = "llvm${LLVM_RELEASE}"
27
Brad Bishop19323692019-04-05 15:28:33 -040028BRANCH = "release/${MAJOR_VERSION}.x"
Brad Bishopf3f93bb2019-10-16 14:33:32 -040029SRCREV = "0399d5a9682b3cef71c653373e38890c63c4c365"
Brad Bishop19323692019-04-05 15:28:33 -040030SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH} \
Brad Bishop08902b02019-08-20 09:16:51 -040031 file://0006-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch;striplevel=2 \
32 file://0007-llvm-allow-env-override-of-exe-path.patch;striplevel=2 \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050033 "
Brad Bishop19323692019-04-05 15:28:33 -040034
35S = "${WORKDIR}/git/llvm"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050036
37LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
Brad Bishop19323692019-04-05 15:28:33 -040038
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039def get_llvm_arch(bb, d, arch_var):
40 import re
41 a = d.getVar(arch_var)
Brad Bishop19323692019-04-05 15:28:33 -040042 if re.match(r'(i.86|athlon|x86.64)$', a): return 'X86'
43 elif re.match(r'arm$', a): return 'ARM'
44 elif re.match(r'armeb$', a): return 'ARM'
45 elif re.match(r'aarch64$', a): return 'AArch64'
46 elif re.match(r'aarch64_be$', a): return 'AArch64'
47 elif re.match(r'mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
Brad Bishopf3f93bb2019-10-16 14:33:32 -040048 elif re.match(r'riscv(32|64)(eb|)$', a): return 'RISCV'
Brad Bishop19323692019-04-05 15:28:33 -040049 elif re.match(r'p(pc|owerpc)(|64)', a): return 'PowerPC'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050050 else:
51 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
52
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080053def get_llvm_host_arch(bb, d):
54 return get_llvm_arch(bb, d, 'HOST_ARCH')
55
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056#
57# Default to build all OE-Core supported target arches (user overridable).
58#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080059LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050060
61ARM_INSTRUCTION_SET_armv5 = "arm"
62ARM_INSTRUCTION_SET_armv4t = "arm"
63
64EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
65 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
66 -DLLVM_ENABLE_PIC=ON \
67 -DLLVM_BINDINGS_LIST='' \
68 -DLLVM_LINK_LLVM_DYLIB=ON \
69 -DLLVM_ENABLE_FFI=ON \
Brad Bishop19323692019-04-05 15:28:33 -040070 -DLLVM_ENABLE_RTTI=ON \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050071 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
72 -DLLVM_OPTIMIZED_TABLEGEN=ON \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080073 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \
Brad Bishop19323692019-04-05 15:28:33 -040074 -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
Brad Bishop79641f22019-09-10 07:20:22 -040075 -DPYTHON_EXECUTABLE=${HOSTTOOLS_DIR}/python3 \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 -G Ninja"
77
78EXTRA_OECMAKE_append_class-target = "\
79 -DCMAKE_CROSSCOMPILING:BOOL=ON \
80 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080081 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050082 "
83
84EXTRA_OECMAKE_append_class-nativesdk = "\
85 -DCMAKE_CROSSCOMPILING:BOOL=ON \
86 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080087 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050088 "
89
90do_configure_prepend() {
91# Fix paths in llvm-config
92 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
93 sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp
94 sed -ri "s#lib/${LLVM_DIR}#${baselib}/${LLVM_DIR}#g" ${S}/tools/llvm-config/llvm-config.cpp
95}
96
97do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040098 ninja -v ${PARALLEL_MAKE}
Brad Bishopd7bf8c12018-02-25 22:55:05 -050099}
100
101do_compile_class-native() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400102 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500103}
104
105do_install() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400106 DESTDIR=${LLVM_INSTALL_DIR} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500107 install -D -m 0755 ${B}/bin/llvm-config ${D}${libdir}/${LLVM_DIR}/llvm-config
108
109 install -d ${D}${bindir}/${LLVM_DIR}
110 cp -r ${LLVM_INSTALL_DIR}${bindir}/* ${D}${bindir}/${LLVM_DIR}/
111
112 install -d ${D}${includedir}/${LLVM_DIR}
113 cp -r ${LLVM_INSTALL_DIR}${includedir}/* ${D}${includedir}/${LLVM_DIR}/
114
115 install -d ${D}${libdir}/${LLVM_DIR}
116
117 # The LLVM sources have "/lib" embedded and so we cannot completely rely on the ${libdir} variable
118 if [ -d ${LLVM_INSTALL_DIR}${libdir}/ ]; then
119 cp -r ${LLVM_INSTALL_DIR}${libdir}/* ${D}${libdir}/${LLVM_DIR}/
120 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib ]; then
121 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib/* ${D}${libdir}/${LLVM_DIR}/
122 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib64 ]; then
123 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib64/* ${D}${libdir}/${LLVM_DIR}/
124 fi
125
126 # Remove unnecessary cmake files
127 rm -rf ${D}${libdir}/${LLVM_DIR}/cmake
128
Brad Bishop19323692019-04-05 15:28:33 -0400129 ln -s ${LLVM_DIR}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV} ${D}${libdir}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500130
131 # We'll have to delete the libLLVM.so due to multiple reasons...
132 rm -rf ${D}${libdir}/${LLVM_DIR}/libLLVM.so
133 rm -rf ${D}${libdir}/${LLVM_DIR}/libLTO.so
134}
Brad Bishop19323692019-04-05 15:28:33 -0400135
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500136do_install_class-native() {
137 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
138 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
Brad Bishop19323692019-04-05 15:28:33 -0400139 install -D -m 0755 ${B}/lib/libLLVM-${MAJOR_VERSION}.so ${D}${libdir}/libLLVM-${MAJOR_VERSION}.so
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500140}
141
Brad Bishop19323692019-04-05 15:28:33 -0400142PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500143
Brad Bishop19323692019-04-05 15:28:33 -0400144RRECOMMENDS_${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500145
146FILES_${PN}-bugpointpasses = "\
147 ${libdir}/${LLVM_DIR}/BugpointPasses.so \
148"
Brad Bishop19323692019-04-05 15:28:33 -0400149
150FILES_${PN}-libllvm = "\
151 ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.so \
152 ${libdir}/libLLVM-${MAJOR_VERSION}.so \
153"
154
155FILES_${PN}-liblto += "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500156 ${libdir}/${LLVM_DIR}/libLTO.so.* \
157"
158
Brad Bishop19323692019-04-05 15:28:33 -0400159FILES_${PN}-liboptremarks += "\
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400160 ${libdir}/${LLVM_DIR}/libRemarks.so.* \
Brad Bishop19323692019-04-05 15:28:33 -0400161"
162
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500163FILES_${PN}-llvmhello = "\
164 ${libdir}/${LLVM_DIR}/LLVMHello.so \
165"
166
Brad Bishop19323692019-04-05 15:28:33 -0400167FILES_${PN}-dev += " \
168 ${libdir}/${LLVM_DIR}/llvm-config \
Brad Bishopf3f93bb2019-10-16 14:33:32 -0400169 ${libdir}/${LLVM_DIR}/libRemarks.so \
Brad Bishop19323692019-04-05 15:28:33 -0400170 ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.so \
171"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500172
Brad Bishop19323692019-04-05 15:28:33 -0400173FILES_${PN}-staticdev += "\
174 ${libdir}/${LLVM_DIR}/*.a \
175"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500176
Brad Bishop19323692019-04-05 15:28:33 -0400177INSANE_SKIP_${PN}-libllvm += "dev-so"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500178
179BBCLASSEXTEND = "native nativesdk"