blob: 94c98d6ad742a44a24d4561bdca17dcb149807de [file] [log] [blame]
Eric Fiselier9c97ca12018-11-19 18:43:31 +00001#!/usr/bin/env bash
2#===- libcxx/utils/docker/scripts/install_clang_package.sh -----------------===//
3#
Chandler Carruth2946cd72019-01-19 08:50:56 +00004# 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 Fiselier9c97ca12018-11-19 18:43:31 +00007#
8#===-----------------------------------------------------------------------===//
9
10set -e
11
12function show_usage() {
13 cat << EOF
14Usage: install_clang_package.sh [options]
15
16Install
17Available options:
18 -h|--help show this help message
19 --version the numeric version of the package to use.
20EOF
21}
22
Eric Fiselierb0f10132019-01-19 23:36:06 +000023VERSION="9"
Eric Fiselier9c97ca12018-11-19 18:43:31 +000024
25while [[ $# -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
40done
41
Eric Fiselierb0f10132019-01-19 23:36:06 +000042set -x
Eric Fiselier9c97ca12018-11-19 18:43:31 +000043
44curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
45add-apt-repository -s "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs) main"
46apt-get update
Eric Fiselierb0f10132019-01-19 23:36:06 +000047apt-get upgrade -y
48apt-get install -y --no-install-recommends "clang-$VERSION"
49
50# FIXME(EricWF): Remove this once the clang packages are no longer broken.
51if [ -f "/usr/local/bin/clang" ]; then
52 echo "clang already exists"
53 exit 1
54else
55 CC_BINARY="$(which clang-$VERSION)"
56 ln -s "$CC_BINARY" "/usr/local/bin/clang"
57fi
58if [ -f "/usr/local/bin/clang++" ]; then
59 echo "clang++ already exists"
60 exit 1
61else
62 CXX_BINARY="$(which clang++-$VERSION)"
63 ln -s "$CXX_BINARY" "/usr/local/bin/clang++"
64fi
Eric Fiselier9c97ca12018-11-19 18:43:31 +000065
66echo "Testing clang version..."
67clang --version
68
69echo "Testing clang++ version..."
70clang++ --version
71
72# Figure out the libc++ and libc++abi package versions that we want.
73if [ "$VERSION" == "" ]; then
74 VERSION="$(apt-cache search 'libc\+\+-[0-9]-dev' | awk '{print $1}' | awk -F- '{print $2}')"
75 echo "Installing version '$VERSION'"
76fi
77
Eric Fiselierb0f10132019-01-19 23:36:06 +000078apt-get purge -y "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
Eric Fiselier9c97ca12018-11-19 18:43:31 +000079apt-get install -y --no-install-recommends "libc++-$VERSION-dev" "libc++abi-$VERSION-dev"
80
81echo "Done"