blob: 0067635c2b5b75dbee3016383bc7db7d7151a548 [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"
6LICENSE = "NCSA"
7SECTION = "devel"
8
Brad Bishop19323692019-04-05 15:28:33 -04009LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=c6b766a4e85dd28301eeed54a6684648"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050010
Brad Bishop316dfdd2018-06-25 12:45:53 -040011DEPENDS = "libffi libxml2 zlib 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
19LLVM_RELEASE = "${PV}"
20LLVM_DIR = "llvm${LLVM_RELEASE}"
21
Brad Bishop19323692019-04-05 15:28:33 -040022SRCREV = "d2298e74235598f15594fe2c99bbac870a507c59"
23
24BRANCH = "release/${MAJOR_VERSION}.x"
25MAJOR_VERSION = "8"
26MINOR_VERSION = "0"
27PATCH_VERSION = "0"
28SOLIBVER = "1"
29PV = "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}"
30SRC_URI = "git://github.com/llvm/llvm-project.git;branch=${BRANCH} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031 file://0001-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch \
32 file://0002-llvm-allow-env-override-of-exe-path.patch \
33 "
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'
48 elif re.match(r'p(pc|owerpc)(|64)', a): return 'PowerPC'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050049 else:
50 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
51
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080052def get_llvm_host_arch(bb, d):
53 return get_llvm_arch(bb, d, 'HOST_ARCH')
54
Brad Bishopd7bf8c12018-02-25 22:55:05 -050055#
56# Default to build all OE-Core supported target arches (user overridable).
57#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080058LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050059
60ARM_INSTRUCTION_SET_armv5 = "arm"
61ARM_INSTRUCTION_SET_armv4t = "arm"
62
63EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
64 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
65 -DLLVM_ENABLE_PIC=ON \
66 -DLLVM_BINDINGS_LIST='' \
67 -DLLVM_LINK_LLVM_DYLIB=ON \
68 -DLLVM_ENABLE_FFI=ON \
Brad Bishop19323692019-04-05 15:28:33 -040069 -DLLVM_ENABLE_RTTI=ON \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
71 -DLLVM_OPTIMIZED_TABLEGEN=ON \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \
Brad Bishop19323692019-04-05 15:28:33 -040073 -DLLVM_TEMPORARILY_ALLOW_OLD_TOOLCHAIN=ON \
74 -DPYTHON_EXECUTABLE=${HOSTTOOLS_DIR}/python2 \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050075 -G Ninja"
76
77EXTRA_OECMAKE_append_class-target = "\
78 -DCMAKE_CROSSCOMPILING:BOOL=ON \
79 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080080 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081 "
82
83EXTRA_OECMAKE_append_class-nativesdk = "\
84 -DCMAKE_CROSSCOMPILING:BOOL=ON \
85 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080086 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050087 "
88
Brad Bishop19323692019-04-05 15:28:33 -040089CXXFLAGS_append_class-target_powerpc = " -mlongcall"
90
Brad Bishopd7bf8c12018-02-25 22:55:05 -050091do_configure_prepend() {
92# Fix paths in llvm-config
93 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
94 sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp
95 sed -ri "s#lib/${LLVM_DIR}#${baselib}/${LLVM_DIR}#g" ${S}/tools/llvm-config/llvm-config.cpp
96}
97
98do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040099 ninja -v ${PARALLEL_MAKE}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500100}
101
102do_compile_class-native() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400103 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500104}
105
106do_install() {
Brad Bishop316dfdd2018-06-25 12:45:53 -0400107 DESTDIR=${LLVM_INSTALL_DIR} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108 install -D -m 0755 ${B}/bin/llvm-config ${D}${libdir}/${LLVM_DIR}/llvm-config
109
110 install -d ${D}${bindir}/${LLVM_DIR}
111 cp -r ${LLVM_INSTALL_DIR}${bindir}/* ${D}${bindir}/${LLVM_DIR}/
112
113 install -d ${D}${includedir}/${LLVM_DIR}
114 cp -r ${LLVM_INSTALL_DIR}${includedir}/* ${D}${includedir}/${LLVM_DIR}/
115
116 install -d ${D}${libdir}/${LLVM_DIR}
117
118 # The LLVM sources have "/lib" embedded and so we cannot completely rely on the ${libdir} variable
119 if [ -d ${LLVM_INSTALL_DIR}${libdir}/ ]; then
120 cp -r ${LLVM_INSTALL_DIR}${libdir}/* ${D}${libdir}/${LLVM_DIR}/
121 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib ]; then
122 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib/* ${D}${libdir}/${LLVM_DIR}/
123 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib64 ]; then
124 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib64/* ${D}${libdir}/${LLVM_DIR}/
125 fi
126
127 # Remove unnecessary cmake files
128 rm -rf ${D}${libdir}/${LLVM_DIR}/cmake
129
Brad Bishop19323692019-04-05 15:28:33 -0400130 ln -s ${LLVM_DIR}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV} ${D}${libdir}/libLLVM-${MAJOR_VERSION}${SOLIBSDEV}
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500131
132 # We'll have to delete the libLLVM.so due to multiple reasons...
133 rm -rf ${D}${libdir}/${LLVM_DIR}/libLLVM.so
134 rm -rf ${D}${libdir}/${LLVM_DIR}/libLTO.so
135}
Brad Bishop19323692019-04-05 15:28:33 -0400136
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500137do_install_class-native() {
138 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
139 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
Brad Bishop19323692019-04-05 15:28:33 -0400140 install -D -m 0755 ${B}/lib/libLLVM-${MAJOR_VERSION}.so ${D}${libdir}/libLLVM-${MAJOR_VERSION}.so
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500141}
142
Brad Bishop19323692019-04-05 15:28:33 -0400143PACKAGES =+ "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-libllvm ${PN}-liboptremarks ${PN}-liblto"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500144
Brad Bishop19323692019-04-05 15:28:33 -0400145RRECOMMENDS_${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello ${PN}-liboptremarks"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500146
147FILES_${PN}-bugpointpasses = "\
148 ${libdir}/${LLVM_DIR}/BugpointPasses.so \
149"
Brad Bishop19323692019-04-05 15:28:33 -0400150
151FILES_${PN}-libllvm = "\
152 ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.so \
153 ${libdir}/libLLVM-${MAJOR_VERSION}.so \
154"
155
156FILES_${PN}-liblto += "\
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500157 ${libdir}/${LLVM_DIR}/libLTO.so.* \
158"
159
Brad Bishop19323692019-04-05 15:28:33 -0400160FILES_${PN}-liboptremarks += "\
161 ${libdir}/${LLVM_DIR}/libOptRemarks.so.* \
162"
163
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500164FILES_${PN}-llvmhello = "\
165 ${libdir}/${LLVM_DIR}/LLVMHello.so \
166"
167
Brad Bishop19323692019-04-05 15:28:33 -0400168FILES_${PN}-dev += " \
169 ${libdir}/${LLVM_DIR}/llvm-config \
170 ${libdir}/${LLVM_DIR}/libOptRemarks.so \
171 ${libdir}/${LLVM_DIR}/libLLVM-${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}.so \
172"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500173
Brad Bishop19323692019-04-05 15:28:33 -0400174FILES_${PN}-staticdev += "\
175 ${libdir}/${LLVM_DIR}/*.a \
176"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500177
Brad Bishop19323692019-04-05 15:28:33 -0400178INSANE_SKIP_${PN}-libllvm += "dev-so"
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500179
180BBCLASSEXTEND = "native nativesdk"