blob: cb3bba6fabdf7676b8fc9ec6b107dd44068285c7 [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 Bishop316dfdd2018-06-25 12:45:53 -040022SRCREV = "089d4c0c490687db6c75f1d074e99c4d42936a50"
23PV = "6.0"
24BRANCH = "release_60"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050025PATCH_VERSION = "0"
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 \
Brad Bishop316dfdd2018-06-25 12:45:53 -040029 file://0001-Disable-generating-a-native-llvm-config.patch \
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030 "
Brad Bishop316dfdd2018-06-25 12:45:53 -040031UPSTREAM_CHECK_COMMITS = "1"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050032S = "${WORKDIR}/git"
33
34LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install"
35def get_llvm_arch(bb, d, arch_var):
36 import re
37 a = d.getVar(arch_var)
38 if re.match('(i.86|athlon|x86.64)$', a): return 'X86'
39 elif re.match('arm$', a): return 'ARM'
40 elif re.match('armeb$', a): return 'ARM'
41 elif re.match('aarch64$', a): return 'AArch64'
42 elif re.match('aarch64_be$', a): return 'AArch64'
43 elif re.match('mips(isa|)(32|64|)(r6|)(el|)$', a): return 'Mips'
44 elif re.match('p(pc|owerpc)(|64)', a): return 'PowerPC'
45 else:
46 raise bb.parse.SkipRecipe("Cannot map '%s' to a supported LLVM architecture" % a)
47
48def get_llvm_target_arch(bb, d):
49 return get_llvm_arch(bb, d, 'TARGET_ARCH')
50#
51# Default to build all OE-Core supported target arches (user overridable).
52#
53LLVM_TARGETS ?= "${@get_llvm_target_arch(bb, d)}"
54LLVM_TARGETS_prepend_x86 = "AMDGPU;"
55LLVM_TARGETS_prepend_x86-64 = "AMDGPU;"
56
57ARM_INSTRUCTION_SET_armv5 = "arm"
58ARM_INSTRUCTION_SET_armv4t = "arm"
59
60EXTRA_OECMAKE += "-DLLVM_ENABLE_ASSERTIONS=OFF \
61 -DLLVM_ENABLE_EXPENSIVE_CHECKS=OFF \
62 -DLLVM_ENABLE_PIC=ON \
63 -DLLVM_BINDINGS_LIST='' \
64 -DLLVM_LINK_LLVM_DYLIB=ON \
65 -DLLVM_ENABLE_FFI=ON \
66 -DFFI_INCLUDE_DIR=$(pkg-config --variable=includedir libffi) \
67 -DLLVM_OPTIMIZED_TABLEGEN=ON \
68 -DLLVM_TARGETS_TO_BUILD="${LLVM_TARGETS}" \
69 -G Ninja"
70
71EXTRA_OECMAKE_append_class-target = "\
72 -DCMAKE_CROSSCOMPILING:BOOL=ON \
73 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
74 "
75
76EXTRA_OECMAKE_append_class-nativesdk = "\
77 -DCMAKE_CROSSCOMPILING:BOOL=ON \
78 -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \
79 "
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"