blob: 06329da839d2378c3de8dce569bd85750da6742c [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.
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020011
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020012[ "$1" ] || { echo "Usage: get_clang.sh version [path]"; exit 1; }
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020013
Jerome Forissier0ae3f0a2021-04-15 17:09:44 +020014VER=${1}
15DEST=${2:-./clang-${VER}}
Jerome Forissierc3cd9f52020-05-25 18:47:00 +020016X86_64=clang+llvm-${VER}-x86_64-linux-gnu-ubuntu-16.04
17AARCH64=clang+llvm-${VER}-aarch64-linux-gnu
18ARMV7A=clang+llvm-${VER}-armv7a-linux-gnueabihf
19
20set -x
21
22TMPDEST=${DEST}_tmp${RANDOM}
23
24if [ -e ${TMPDEST} ]; then
25 echo Error: ${TMPDEST} exists
26 exit 1
27fi
28
29function cleanup() {
30 rm -f ${X86_64}.tar.xz ${AARCH64}.tar.xz ${ARMV7A}.tar.xz
31 rm -rf ${AARCH64} ${ARMV7A}
32}
33
34trap "{ exit 2; }" INT
35trap cleanup EXIT
36
37(wget -nv https://github.com/llvm/llvm-project/releases/download/llvmorg-${VER}/${X86_64}.tar.xz && tar xf ${X86_64}.tar.xz) &
38pids=$!
39(wget -nv https://github.com/llvm/llvm-project/releases/download/llvmorg-${VER}/${AARCH64}.tar.xz && tar xf ${AARCH64}.tar.xz) &
40pids="$pids $!"
41(wget -nv https://github.com/llvm/llvm-project/releases/download/llvmorg-${VER}/${ARMV7A}.tar.xz && tar xf ${ARMV7A}.tar.xz) &
42pids="$pids $!"
43
44wait $pids || exit 1
45
46mv ${X86_64} ${TMPDEST} || exit 1
47cp ${AARCH64}/lib/clang/${VER}/lib/linux/* ${TMPDEST}/lib/clang/${VER}/lib/linux || exit 1
48cp ${ARMV7A}/lib/clang/${VER}/lib/linux/* ${TMPDEST}/lib/clang/${VER}/lib/linux || exit 1
49mv ${TMPDEST} ${DEST}