-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlink.sh
executable file
·79 lines (64 loc) · 2.44 KB
/
link.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd "$DIR"
nonverbose=$1
GCC_SUPPORTED_VERSIONS=( 7 8 9 10 11 )
CLANG_SUPPORTED_VERSIONS=( 6.0 7 8 9 10 11 12 )
if which gcc > /dev/null 2>&1; then
if ! which g++ > /dev/null 2>&1; then
[[ -z "$nonverbose" ]] && >&2 echo "[Warning] gcc was found but not g++"
else
gcc_ver=`gcc -dM -E -x c /dev/null | grep -E -o '__GNUC__ [[:digit:]]+' | awk '{ print $2 }'`
gpp_ver=`g++ -dM -E -x c /dev/null | grep -E -o '__GNUC__ [[:digit:]]+' | awk '{ print $2 }'`
if [ "$gcc_ver" -eq "$gpp_ver" ]; then
if [ "$1" != "--nodefaults" ]; then
echo $gcc_ver > gcc-default && echo gcc
fi
fi
fi
fi
for version in "${GCC_SUPPORTED_VERSIONS[@]}"; do
rm -rf gcc-$version
if which gcc-$version > /dev/null 2>&1; then
if ! which g++-$version > /dev/null 2>&1; then
[[ -z "$nonverbose" ]] && >&2 echo "[Warning] gcc-$version was found but not g++-$version"
continue
fi
echo gcc-$version
mkdir -p gcc-$version
cd gcc-$version
ln -s `which gcc-$version` gcc
ln -s `which g++-$version` g++
cd ..
fi
done
if which clang > /dev/null 2>&1; then
if ! which clang++ > /dev/null 2>&1; then
[[ -z "$nonverbose" ]] && >&2 echo "[Warning] clang was found but not clang++"
else
clang_ver=`clang -dM -E -x c /dev/null | grep -E -o '__clang_major__ [[:digit:]]+' | awk '{ print $2 }'`
clangpp_ver=`clang++ -dM -E -x c /dev/null | grep -E -o '__clang_major__ [[:digit:]]+' | awk '{ print $2 }'`
if [ "$clang_ver" -eq "$clangpp_ver" ]; then
if [ "$1" != "--nodefaults" ]; then
echo $clang_ver > clang-default && echo clang
fi
fi
fi
fi
for version in "${CLANG_SUPPORTED_VERSIONS[@]}"; do
# Remove `.0`
stripped_version="${version%.*}"
rm -rf clang-$stripped_version
if which clang-$version > /dev/null 2>&1; then
if ! which clang++-$version > /dev/null 2>&1; then
[[ -z "$nonverbose" ]] && >&2 echo "[Warning] clang-$version was found but not clang++-$version"
continue
fi
echo clang-$stripped_version
mkdir -p clang-$stripped_version
cd clang-$stripped_version
ln -s `which clang-$version` clang
ln -s `which clang++-$version` clang++
cd ..
fi
done