-
Notifications
You must be signed in to change notification settings - Fork 0
/
lang_update_alternatives.sh
66 lines (52 loc) · 1.81 KB
/
lang_update_alternatives.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#! bash
checkfail() {
if [ $1 -gt 0 ]; then
echo $2
exit 1
fi
return
}
if [ -f /usr/local/bin/gcc ]; then
sudo mv /usr/local/bin/gcc /usr/local/bin/gcc-dev
checkfail $? "Rename /usr/local/bin/gcc failed"
fi
if [ -f /usr/local/bin/g++ ]; then
sudo mv /usr/local/bin/g++ /usr/local/bin/g++-dev
checkfail $? "Rename /usr/local/bin/g++ failed"
fi
if [ -f /usr/local/bin/clang ]; then
sudo mv /usr/local/bin/clang /usr/local/bin/clang-dev
checkfail $? "Rename /usr/local/bin/clang failed"
fi
# clang++ is typically a link to clang:
if [ -f /usr/local/bin/clang++ ]; then
sudo unlink /usr/local/bin/clang++
checkfail $? "Unlink /usr/local/bin/clang++ failed"
sudo ln -s /usr/local/bin/clang-dev /usr/local/bin/clang++-dev
checkfail $? "Link /usr/local/bin/clang++ failed"
fi
update_alternatives() {
# 1: alias
# 2: target file
# 3: priority
if [ -f $2 ]; then
sudo update-alternatives --install /usr/bin/$1 $1 $2 $3
checkfail $? "Failed: sudo update-alternatives --install /usr/bin/$1 $1 $2 $3"
return
fi
echo "update-alternatives skipped because '$2' doesn't exist"
}
update_alternatives gcc /usr/bin/gcc-9 10
update_alternatives gcc /usr/bin/gcc-10 20
update_alternatives gcc /usr/local/bin/gcc-dev 30
update_alternatives g++ /usr/bin/g++-9 10
update_alternatives g++ /usr/bin/g++-10 20
update_alternatives g++ /usr/local/bin/g++-dev 30
update_alternatives clang /usr/lib/llvm-10/bin/clang 10
update_alternatives clang /usr/local/bin/clang-dev 20
update_alternatives clang++ /usr/lib/llvm-10/bin/clang++ 10
update_alternatives clang++ /usr/local/bin/clang++-dev 20
update_alternatives cc /usr/bin/clang 10
update_alternatives cc /usr/bin/gcc 20
update_alternatives c++ /usr/bin/clang++ 10
update_alternatives c++ /usr/bin/g++ 20