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