Eric Fiselier | 9c97ca1 | 2018-11-19 18:43:31 +0000 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | #===- libcxx/utils/docker/scripts/install_clang_package.sh -----------------===// |
| 3 | # |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 4 | # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | # See https://llvm.org/LICENSE.txt for license information. |
| 6 | # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Eric Fiselier | 9c97ca1 | 2018-11-19 18:43:31 +0000 | [diff] [blame] | 7 | # |
| 8 | #===-----------------------------------------------------------------------===// |
| 9 | |
| 10 | set -e |
| 11 | |
| 12 | function show_usage() { |
| 13 | cat << EOF |
| 14 | Usage: install_clang_package.sh [options] |
| 15 | |
| 16 | Install |
| 17 | Available options: |
| 18 | -h|--help show this help message |
| 19 | --version the numeric version of the package to use. |
| 20 | EOF |
| 21 | } |
| 22 | |
Eric Fiselier | b0f1013 | 2019-01-19 23:36:06 +0000 | [diff] [blame] | 23 | VERSION="9" |
Eric Fiselier | 9c97ca1 | 2018-11-19 18:43:31 +0000 | [diff] [blame] | 24 | |
| 25 | while [[ $# -gt 0 ]]; do |
| 26 | case "$1" in |
| 27 | --version) |
| 28 | shift |
| 29 | VERSION="$1" |
| 30 | shift |
| 31 | ;; |
| 32 | -h|--help) |
| 33 | show_usage |
| 34 | exit 0 |
| 35 | ;; |
| 36 | *) |
| 37 | echo "Unknown option: $1" |
| 38 | exit 1 |
| 39 | esac |
| 40 | done |
| 41 | |
Eric Fiselier | b0f1013 | 2019-01-19 23:36:06 +0000 | [diff] [blame] | 42 | set -x |
Eric Fiselier | 9c97ca1 | 2018-11-19 18:43:31 +0000 | [diff] [blame] | 43 | |
| 44 | curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - |
| 45 | add-apt-repository -s "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs) main" |
| 46 | apt-get update |
Eric Fiselier | b0f1013 | 2019-01-19 23:36:06 +0000 | [diff] [blame] | 47 | apt-get upgrade -y |
| 48 | apt-get install -y --no-install-recommends "clang-$VERSION" |
| 49 | |
| 50 | # FIXME(EricWF): Remove this once the clang packages are no longer broken. |
| 51 | if [ -f "/usr/local/bin/clang" ]; then |
| 52 | echo "clang already exists" |
| 53 | exit 1 |
| 54 | else |
| 55 | CC_BINARY="$(which clang-$VERSION)" |
| 56 | ln -s "$CC_BINARY" "/usr/local/bin/clang" |
| 57 | fi |
| 58 | if [ -f "/usr/local/bin/clang++" ]; then |
| 59 | echo "clang++ already exists" |
| 60 | exit 1 |
| 61 | else |
| 62 | CXX_BINARY="$(which clang++-$VERSION)" |
| 63 | ln -s "$CXX_BINARY" "/usr/local/bin/clang++" |
| 64 | fi |
Eric Fiselier | 9c97ca1 | 2018-11-19 18:43:31 +0000 | [diff] [blame] | 65 | |
| 66 | echo "Testing clang version..." |
| 67 | clang --version |
| 68 | |
| 69 | echo "Testing clang++ version..." |
| 70 | clang++ --version |
| 71 | |
| 72 | # Figure out the libc++ and libc++abi package versions that we want. |
| 73 | if [ "$VERSION" == "" ]; then |
| 74 | VERSION="$(apt-cache search 'libc\+\+-[0-9]-dev' | awk '{print $1}' | awk -F- '{print $2}')" |
| 75 | echo "Installing version '$VERSION'" |
| 76 | fi |
| 77 | |
Eric Fiselier | b0f1013 | 2019-01-19 23:36:06 +0000 | [diff] [blame] | 78 | apt-get purge -y "libc++-$VERSION-dev" "libc++abi-$VERSION-dev" |
Eric Fiselier | 9c97ca1 | 2018-11-19 18:43:31 +0000 | [diff] [blame] | 79 | apt-get install -y --no-install-recommends "libc++-$VERSION-dev" "libc++abi-$VERSION-dev" |
| 80 | |
| 81 | echo "Done" |