Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1 | # Copyright (C) 2017 Khem Raj <raj.khem@gmail.com> |
| 2 | # Released under the MIT license (see COPYING.MIT for the terms) |
| 3 | |
| 4 | DESCRIPTION = "The LLVM Compiler Infrastructure" |
| 5 | HOMEPAGE = "http://llvm.org" |
| 6 | LICENSE = "NCSA" |
| 7 | SECTION = "devel" |
| 8 | |
| 9 | LIC_FILES_CHKSUM = "file://LICENSE.TXT;md5=e825e017edc35cfd58e26116e5251771" |
| 10 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 11 | DEPENDS = "libffi libxml2 zlib ninja-native llvm-native" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | |
| 13 | RDEPENDS_${PN}_append_class-target = " ncurses-terminfo" |
| 14 | |
| 15 | inherit perlnative pythonnative cmake pkgconfig |
| 16 | |
| 17 | PROVIDES += "llvm${PV}" |
| 18 | |
| 19 | LLVM_RELEASE = "${PV}" |
| 20 | LLVM_DIR = "llvm${LLVM_RELEASE}" |
| 21 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 22 | SRCREV = "5136df4d089a086b70d452160ad5451861269498" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 23 | PV = "6.0" |
| 24 | BRANCH = "release_60" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 25 | PATCH_VERSION = "1" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 26 | SRC_URI = "git://github.com/llvm-mirror/llvm.git;branch=${BRANCH};protocol=http \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 27 | file://0001-llvm-TargetLibraryInfo-Undefine-libc-functions-if-th.patch \ |
| 28 | file://0002-llvm-allow-env-override-of-exe-path.patch \ |
| 29 | " |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 30 | UPSTREAM_CHECK_COMMITS = "1" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 31 | S = "${WORKDIR}/git" |
| 32 | |
| 33 | LLVM_INSTALL_DIR = "${WORKDIR}/llvm-install" |
| 34 | def 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 47 | def get_llvm_host_arch(bb, d): |
| 48 | return get_llvm_arch(bb, d, 'HOST_ARCH') |
| 49 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 50 | # |
| 51 | # Default to build all OE-Core supported target arches (user overridable). |
| 52 | # |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 53 | LLVM_TARGETS ?= "AMDGPU;${@get_llvm_host_arch(bb, d)}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 54 | |
| 55 | ARM_INSTRUCTION_SET_armv5 = "arm" |
| 56 | ARM_INSTRUCTION_SET_armv4t = "arm" |
| 57 | |
| 58 | EXTRA_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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 66 | -DLLVM_TARGETS_TO_BUILD='${LLVM_TARGETS}' \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 67 | -G Ninja" |
| 68 | |
| 69 | EXTRA_OECMAKE_append_class-target = "\ |
| 70 | -DCMAKE_CROSSCOMPILING:BOOL=ON \ |
| 71 | -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 72 | -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 73 | " |
| 74 | |
| 75 | EXTRA_OECMAKE_append_class-nativesdk = "\ |
| 76 | -DCMAKE_CROSSCOMPILING:BOOL=ON \ |
| 77 | -DLLVM_TABLEGEN=${STAGING_BINDIR_NATIVE}/llvm-tblgen${PV} \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 78 | -DLLVM_CONFIG_PATH=${STAGING_BINDIR_NATIVE}/llvm-config${PV} \ |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 79 | " |
| 80 | |
| 81 | do_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 | |
| 88 | do_compile() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 89 | ninja -v ${PARALLEL_MAKE} |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | do_compile_class-native() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 93 | ninja -v ${PARALLEL_MAKE} llvm-config llvm-tblgen |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | do_install() { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 97 | DESTDIR=${LLVM_INSTALL_DIR} ninja -v install |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 98 | 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 | } |
| 126 | do_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 | |
| 132 | PACKAGES += "${PN}-bugpointpasses ${PN}-llvmhello" |
| 133 | ALLOW_EMPTY_${PN} = "1" |
| 134 | ALLOW_EMPTY_${PN}-staticdev = "1" |
| 135 | FILES_${PN} = "" |
| 136 | FILES_${PN}-staticdev = "" |
| 137 | FILES_${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 | |
| 146 | FILES_${PN}-dev = " \ |
| 147 | ${bindir}/${LLVM_DIR} \ |
| 148 | ${includedir}/${LLVM_DIR} \ |
| 149 | ${libdir}/${LLVM_DIR}/llvm-config \ |
| 150 | " |
| 151 | |
| 152 | RRECOMMENDS_${PN}-dev += "${PN}-bugpointpasses ${PN}-llvmhello" |
| 153 | |
| 154 | FILES_${PN}-bugpointpasses = "\ |
| 155 | ${libdir}/${LLVM_DIR}/BugpointPasses.so \ |
| 156 | " |
| 157 | FILES_${PN} += "\ |
| 158 | ${libdir}/${LLVM_DIR}/libLTO.so.* \ |
| 159 | " |
| 160 | |
| 161 | FILES_${PN}-llvmhello = "\ |
| 162 | ${libdir}/${LLVM_DIR}/LLVMHello.so \ |
| 163 | " |
| 164 | |
| 165 | PACKAGES_DYNAMIC = "^libllvm${LLVM_RELEASE}-.*$" |
| 166 | NOAUTOPACKAGEDEBUG = "1" |
| 167 | |
| 168 | INSANE_SKIP_${MLPREFIX}libllvm${LLVM_RELEASE}-llvm-${LLVM_RELEASE}.${PATCH_VERSION} += "dev-so" |
| 169 | INSANE_SKIP_${MLPREFIX}libllvm${LLVM_RELEASE}-llvm-${LLVM_RELEASE} += "dev-so" |
| 170 | INSANE_SKIP_${MLPREFIX}libllvm${LLVM_RELEASE}-llvm += "dev-so" |
| 171 | |
| 172 | python 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 | |
| 185 | PACKAGESPLITFUNCS_prepend = "llvm_populate_packages " |
| 186 | |
| 187 | BBCLASSEXTEND = "native nativesdk" |