blob: 727876303d6e28daaa4e9c438d3d2abd4f4e831d [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
9LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=e825e017edc35cfd58e26116e5251771"
10
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
15inherit perlnative pythonnative cmake pkgconfig
16
17PROVIDES += "llvm${PV}"
18
19LLVM_RELEASE = "${PV}"
20LLVM_DIR = "llvm${LLVM_RELEASE}"
21
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080022SRCREV = "5136df4d089a086b70d452160ad5451861269498"
Brad Bishop316dfdd2018-06-25 12:45:53 -040023PV = "6.0"
24BRANCH = "release_60"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080025PATCH_VERSION = "1"
Brad Bishop316dfdd2018-06-25 12:45:53 -040026SRC_URI = "git://github.com/llvm-mirror/llvm.git;branch=${BRANCH};protocol=http \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027 file://0001-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch \
28 file://0002-llvm-allow-env-override-of-exe-path.patch \
29 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040030UPSTREAM_CHECK_COMMITS = "1"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050031S = "${WORKDIR}/git"
32
33LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
34def get_llvm_arch(bb, d, arch_var):
35 import re
36 a = d.getVar(arch_var)
37 if re.match('(i.86|athlon|x86.64)$', a): return 'X86'
38 elif re.match('arm$', a): return 'ARM'
39 elif re.match('armeb$', a): return 'ARM'
40 elif re.match('aarch64$', a): return 'AArch64'
41 elif re.match('aarch64_be$', a): return 'AArch64'
42 elif re.match('mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
43 elif re.match('p(pc|owerpc)(|64)', a): return 'PowerPC'
44 else:
45 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
46
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080047def get_llvm_host_arch(bb, d):
48 return get_llvm_arch(bb, d, 'HOST_ARCH')
49
Brad Bishopd7bf8c12018-02-25 22:55:05 -050050#
51# Default to build all OE-Core supported target arches (user overridable).
52#
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080053LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050054
55ARM_INSTRUCTION_SET_armv5 = "arm"
56ARM_INSTRUCTION_SET_armv4t = "arm"
57
58EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
59 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
60 -DLLVM_ENABLE_PIC=ON \
61 -DLLVM_BINDINGS_LIST='' \
62 -DLLVM_LINK_LLVM_DYLIB=ON \
63 -DLLVM_ENABLE_FFI=ON \
64 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
65 -DLLVM_OPTIMIZED_TABLEGEN=ON \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066 -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050067 -G Ninja"
68
69EXTRA_OECMAKE_append_class-target = "\
70 -DCMAKE_CROSSCOMPILING:BOOL=ON \
71 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050073 "
74
75EXTRA_OECMAKE_append_class-nativesdk = "\
76 -DCMAKE_CROSSCOMPILING:BOOL=ON \
77 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080078 -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 "
80
81do_configure_prepend() {
82# Fix paths in llvm-config
83 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
84 sed -ri "s#/(bin|include|lib)(/?\")#/\1/${LLVM_DIR}\2#g" ${S}/tools/llvm-config/llvm-config.cpp
85 sed -ri "s#lib/${LLVM_DIR}#${baselib}/${LLVM_DIR}#g" ${S}/tools/llvm-config/llvm-config.cpp
86}
87
88do_compile() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040089 ninja -v ${PARALLEL_MAKE}
Brad Bishopd7bf8c12018-02-25 22:55:05 -050090}
91
92do_compile_class-native() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040093 ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen
Brad Bishopd7bf8c12018-02-25 22:55:05 -050094}
95
96do_install() {
Brad Bishop316dfdd2018-06-25 12:45:53 -040097 DESTDIR=${LLVM_INSTALL_DIR} ninja -v install
Brad Bishopd7bf8c12018-02-25 22:55:05 -050098 install -D -m 0755 ${B}/bin/llvm-config ${D}${libdir}/${LLVM_DIR}/llvm-config
99
100 install -d ${D}${bindir}/${LLVM_DIR}
101 cp -r ${LLVM_INSTALL_DIR}${bindir}/* ${D}${bindir}/${LLVM_DIR}/
102
103 install -d ${D}${includedir}/${LLVM_DIR}
104 cp -r ${LLVM_INSTALL_DIR}${includedir}/* ${D}${includedir}/${LLVM_DIR}/
105
106 install -d ${D}${libdir}/${LLVM_DIR}
107
108 # The LLVM sources have "/lib" embedded and so we cannot completely rely on the ${libdir} variable
109 if [ -d ${LLVM_INSTALL_DIR}${libdir}/ ]; then
110 cp -r ${LLVM_INSTALL_DIR}${libdir}/* ${D}${libdir}/${LLVM_DIR}/
111 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib ]; then
112 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib/* ${D}${libdir}/${LLVM_DIR}/
113 elif [ -d ${LLVM_INSTALL_DIR}${prefix}/lib64 ]; then
114 cp -r ${LLVM_INSTALL_DIR}${prefix}/lib64/* ${D}${libdir}/${LLVM_DIR}/
115 fi
116
117 # Remove unnecessary cmake files
118 rm -rf ${D}${libdir}/${LLVM_DIR}/cmake
119
120 ln -s ${LLVM_DIR}/libLLVM-${PV}${SOLIBSDEV} ${D}${libdir}/libLLVM-${PV}${SOLIBSDEV}
121
122 # We'll have to delete the libLLVM.so due to multiple reasons...
123 rm -rf ${D}${libdir}/${LLVM_DIR}/libLLVM.so
124 rm -rf ${D}${libdir}/${LLVM_DIR}/libLTO.so
125}
126do_install_class-native() {
127 install -D -m 0755 ${B}/bin/llvm-tblgen ${D}${bindir}/llvm-tblgen${PV}
128 install -D -m 0755 ${B}/bin/llvm-config ${D}${bindir}/llvm-config${PV}
129 install -D -m 0755 ${B}/lib/libLLVM-${PV}.so ${D}${libdir}/libLLVM-${PV}.so
130}
131
132PACKAGES += "${PN}-bugpointpasses ${PN}-llvmhello"
133ALLOW_EMPTY_${PN} = "1"
134ALLOW_EMPTY_${PN}-staticdev = "1"
135FILES_${PN} = ""
136FILES_${PN}-staticdev = ""
137FILES_${PN}-dbg = " \
138 ${bindir}/${LLVM_DIR}/.debug \
139 ${libdir}/${LLVM_DIR}/.debug/BugpointPasses.so \
140 ${libdir}/${LLVM_DIR}/.debug/LLVMHello.so \
141 ${libdir}/${LLVM_DIR}/.debug/libLTO.so* \
142 ${libdir}/${LLVM_DIR}/.debug/llvm-config \
143 /usr/src/debug \
144"
145
146FILES_${PN}-dev = " \
147 ${bindir}/${LLVM_DIR} \
148 ${includedir}/${LLVM_DIR} \
149 ${libdir}/${LLVM_DIR}/llvm-config \
150"
151
152RRECOMMENDS_${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello"
153
154FILES_${PN}-bugpointpasses = "\
155 ${libdir}/${LLVM_DIR}/BugpointPasses.so \
156"
157FILES_${PN} += "\
158 ${libdir}/${LLVM_DIR}/libLTO.so.* \
159"
160
161FILES_${PN}-llvmhello = "\
162 ${libdir}/${LLVM_DIR}/LLVMHello.so \
163"
164
165PACKAGES_DYNAMIC = "^libllvm${LLVM_RELEASE}-.*$"
166NOAUTOPACKAGEDEBUG = "1"
167
168INSANE_SKIP_${MLPREFIX}libllvm${LLVM_RELEASE}-llvm-${LLVM_RELEASE}.${PATCH_VERSION} += "dev-so"
169INSANE_SKIP_${MLPREFIX}libllvm${LLVM_RELEASE}-llvm-${LLVM_RELEASE} += "dev-so"
170INSANE_SKIP_${MLPREFIX}libllvm${LLVM_RELEASE}-llvm += "dev-so"
171
172python llvm_populate_packages() {
173 libdir = bb.data.expand('${libdir}', d)
174 libllvm_libdir = bb.data.expand('${libdir}/${LLVM_DIR}', d)
175 split_dbg_packages = do_split_packages(d, libllvm_libdir+'/.debug', '^lib(.*)\.so$', 'libllvm${LLVM_RELEASE}-%s-dbg', 'Split debug package for %s', allow_dirs=True)
176 split_packages = do_split_packages(d, libdir, '^lib(.*)\.so$', 'libllvm${LLVM_RELEASE}-%s', 'Split package for %s', allow_dirs=True, allow_links=True, recursive=True)
177 split_staticdev_packages = do_split_packages(d, libllvm_libdir, '^lib(.*)\.a$', 'libllvm${LLVM_RELEASE}-%s-staticdev', 'Split staticdev package for %s', allow_dirs=True)
178 if split_packages:
179 pn = d.getVar('PN')
180 d.appendVar('RDEPENDS_' + pn, ' '+' '.join(split_packages))
181 d.appendVar('RDEPENDS_' + pn + '-dbg', ' '+' '.join(split_dbg_packages))
182 d.appendVar('RDEPENDS_' + pn + '-staticdev', ' '+' '.join(split_staticdev_packages))
183}
184
185PACKAGESPLITFUNCS_prepend = "llvm_populate_packages "
186
187BBCLASSEXTEND = "native nativesdk"