blob: bce30bab3a652b62443e6719edf2c6a1db611f6e [file] [log] [blame]
Jerome Forissierc3cd9f52020-05-25 18:47:00 +02001#!/bin/bash
2#
3# Download and extract Clang from the GitHub release page.
4# We want a x86_64 cross-compiler capable of generating aarch64 and armv7a code
5# *and* we want the compiler-rt libraries for these architectures
6# (libclang_rt.*.a).
7# Clang is configured to be able to cross-compile to all the supported
8# architectures by default (see <clang path>/bin/llc --version) which is great,
9# but compiler-rt is included only for the host architecture. Therefore we need
10# to combine several packages into one, which is the purpose of this script.
11#
12# Usage: get_clang.sh [path]
13
14DEST=${1:-./clang-9.0.1}
15
16VER=9.0.1
17X86_64=clang+llvm-${VER}-x86_64-linux-gnu-ubuntu-16.04
18AARCH64=clang+llvm-${VER}-aarch64-linux-gnu
19ARMV7A=clang+llvm-${VER}-armv7a-linux-gnueabihf
20
21set -x
22
23TMPDEST=${DEST}_tmp${RANDOM}
24
25if [ -e ${TMPDEST} ]; then
26 echo Error: ${TMPDEST} exists
27 exit 1
28fi
29
30function cleanup() {
31 rm -f ${X86_64}.tar.xz ${AARCH64}.tar.xz ${ARMV7A}.tar.xz
32 rm -rf ${AARCH64} ${ARMV7A}
33}
34
35trap "{ exit 2; }" INT
36trap cleanup EXIT
37
38(wget -nv https://github.com/llvm/llvm-project/releases/download/llvmorg-${VER}/${X86_64}.tar.xz && tar xf ${X86_64}.tar.xz) &
39pids=$!
40(wget -nv https://github.com/llvm/llvm-project/releases/download/llvmorg-${VER}/${AARCH64}.tar.xz && tar xf ${AARCH64}.tar.xz) &
41pids="$pids $!"
42(wget -nv https://github.com/llvm/llvm-project/releases/download/llvmorg-${VER}/${ARMV7A}.tar.xz && tar xf ${ARMV7A}.tar.xz) &
43pids="$pids $!"
44
45wait $pids || exit 1
46
47mv ${X86_64} ${TMPDEST} || exit 1
48cp ${AARCH64}/lib/clang/${VER}/lib/linux/* ${TMPDEST}/lib/clang/${VER}/lib/linux || exit 1
49cp ${ARMV7A}/lib/clang/${VER}/lib/linux/* ${TMPDEST}/lib/clang/${VER}/lib/linux || exit 1
50mv ${TMPDEST} ${DEST}