-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_llvm.sh
executable file
·147 lines (137 loc) · 6.21 KB
/
install_llvm.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
#
# Install LLVM on Ubuntu20.04 platform
# Host linux is either x86_64 or aarch64
#
FORCE_PREBUILD=0
LLVM_VERSION="15.0.1"
LLVM_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/llvm-project-${LLVM_VERSION}.src.tar.xz"
LLVM_PREBUILD_AARCH64="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-aarch64-linux-gnu.tar.xz"
LLVM_PREBUILD_X86_64="https://github.com/llvm/llvm-project/releases/download/llvmorg-${LLVM_VERSION}/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz"
#
# Function hostarch()
# set $HOSTARCH
#
function hostarch () {
HOSTARCH=`uname -m`
if [ $HOSTARCH == "x86_64" ]; then
HOSTARCH="x86_64"
else
if [ $HOSTARCH == "aarch64" ]; then
HOSTARCH="aarch64"
else
HOSTARCH="unknown"
echo "My HOSTARCH=$HOSTARCH, Program exit"
exit
fi
fi
echo "My HOSTARCH=$HOSTARCH"
}
# identify host architecture
hostarch
#
# install CMAKE 3.22.1 if not new
#
sudo apt -y update && sudo apt -y install build-essential wget git cmake g++ aria2 sudo libncurses5 && sudo apt -y autoremove
CMAKE_VERSION=$(cmake --version | awk 'NR<2 { print $3 }' | awk -F. '{printf "%2d%02d%02d", $1,$2,$3}')
if [ "$CMAKE_VERSION" -lt 31200 ]; then
echo "upgrade cmake version"
mkdir -p ${HOME}/tmp && cd ${HOME}/tmp && \
aria2c -x10 https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1.tar.gz
tar -zxvf cmake-3.22.1.tar.gz
sudo apt -y install libssl-dev openssl
cd cmake-3.22.1 && cmake . && make -j`nproc`
sudo make install && make clean
export CMAKE_ROOT=/usr/local/share/cmake-3.22
echo "# CMAKE_ROOT setting" >> ${HOME}/.bashrc
echo "export CMAKE_ROOT=/usr/local/share/cmake-3.22" >> ${HOME}/.bashrc
sudo ldconfig -v
source ${HOME}/.bashrc
fi
#
# install LLVM ${LLVM_VERSION} if not available
#
which clang
ret=$?
if [ $ret == '0' ]; then
CLANG_VERSION=$(clang --version | awk 'NR<2 { print $3 }' | awk -F. '{printf "%2d%02d%02d", $1,$2,$3}')
else
CLANG_VERSION="0"
fi
if ( ( [ $HOSTARCH == "aarch64" ] && [ $FORCE_PREBUILD == "0" ] ) || ( [ $HOSTARCH == "x86_64" ] && [ $FORCE_PREBUILD == "0" ] ) ) && [ "$CLANG_VERSION" -lt 150000 ]; then
echo "Your clang is not new. Need to update."
echo `clang --version`
if [ ! -f ${HOME}/tmp/llvm-project-${LLVM_VERSION}.src.tar.xz ]; then
mkdir -p ${HOME}/tmp && cd ${HOME}/tmp && aria2c -x10 $LLVM_URL
fi
cd ${HOME}/tmp && unxz -k -T `nproc` -f llvm-project-${LLVM_VERSION}.src.tar.xz && \
tar xf llvm-project-${LLVM_VERSION}.src.tar && \
cd llvm-project-${LLVM_VERSION}.src && mkdir -p build && cd build
start_time=`date +%s`
cmake -G Ninja -G "Unix Makefiles"\
-DCMAKE_C_COMPILER=`which clang` \
-DCMAKE_CXX_COMPILER=`which clang++`\
-DLLVM_ENABLE_PROJECTS="clang;llvm;lld" \
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \
-DCMAKE_BUILD_TYPE=RELEASE \
-DLLVM_TARGETS_TO_BUILD="X86;AArch64;ARM"\
-DCMAKE_INSTALL_PREFIX="/usr/local/llvm_${LLVM_VERSION}" \
../llvm && cmake --build . -j`nproc`
end_time=`date +%s`
run_time=$((end_time - start_time))
sudo make install && make clean && cd ../ && rm -rf build && cd ${HOME}
fi
if ( [ $HOSTARCH == "x86_64" ] && [ $FORCE_PREBUILD == "1" ] ) && [ "$CLANG_VERSION" -lt 150000 ]; then
echo "Your clang is not new. Need to update from prebuild."
echo `clang --version`
if [ ! -f ${HOME}/tmp/clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz ]; then
mkdir -p ${HOME}/tmp && cd ${HOME}/tmp && aria2c -x10 $LLVM_PREBUILD_X86_64
fi
cd ${HOME}/tmp && unxz -k -T `nproc` -f clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar.xz
sudo mkdir -p /usr/local/llvm_${LLVM_VERSION}
cd ${HOME}/tmp && sudo tar xf clang+llvm-${LLVM_VERSION}-x86_64-linux-gnu-ubuntu-20.04.tar --strip-components 1 -C /usr/local/llvm_${LLVM_VERSION}
fi
if ( [ $HOSTARCH == "aarch64" ] && [ $FORCE_PREBUILD == "1" ] ) && [ "$CLANG_VERSION" -lt 150000 ]; then
echo "Your clang is not new. Need to update from prebuild."
echo `clang --version`
if [ ! -f ${HOME}/tmp/clang+llvm-${LLVM_VERSION}-aarch64-linux-gnu.tar.xz ]; then
mkdir -p ${HOME}/tmp && cd ${HOME}/tmp && aria2c -x10 $LLVM_PREBUILD_AARCH64
fi
cd ${HOME}/tmp && unxz -k -T `nproc` -f clang+llvm-${LLVM_VERSION}-aarch64-linux-gnu.tar.xz
sudo mkdir -p /usr/local/llvm_${LLVM_VERSION}
cd ${HOME}/tmp && sudo tar xf clang+llvm-${LLVM_VERSION}-aarch64-linux-gnu.tar --strip-components 1 -C /usr/local/llvm_${LLVM_VERSION}
fi
#
# Update ~/.bashrc if necesarry
#
grep LLVM_VERSION ${HOME}/.bashrc
ret=$?
if [ $ret == "1" ] && [ -d /usr/local/llvm_${LLVM_VERSION} ]; then
echo "# " >> ${HOME}/.bashrc
echo "# LLVM setting to \${LLVM_VERSION}" >> ${HOME}/.bashrc
echo "# " >> ${HOME}/.bashrc
echo "export LLVM_VERSION=${LLVM_VERSION}" >> ${HOME}/.bashrc
echo "export LLVM_DIR=/usr/local/llvm_\${LLVM_VERSION}">> ${HOME}/.bashrc
echo "export PATH=\$LLVM_DIR/bin:\$PATH" >> ${HOME}/.bashrc
echo "export LIBRARY_PATH=\$LLVM_DIR/lib:\$LIBRARY_PATH" >> ${HOME}/.bashrc
echo "export LD_LIBRARY_PATH=\$LLVM_DIR/lib:\$LD_LIBRARY_PATH" >> ${HOME}/.bashrc
echo "export LLVM_CONFIG=\$LLVM_DIR/bin/llvm-config" >> ${HOME}/.bashrc
# root /etc/skel
echo "# " | sudo tee -a /etc/skel/.bashrc
echo "# LLVM setting to \${LLVM_VERSION}" | sudo tee -a /etc/skel/.bashrc
echo "# " | sudo tee -a /etc/skel/.bashrc
echo "export LLVM_VERSION=${LLVM_VERSION}" | sudo tee -a /etc/skel/.bashrc
echo "export LLVM_DIR=/usr/local/llvm_\${LLVM_VERSION}"| sudo tee -a /etc/skel/.bashrc
echo "export PATH=\$LLVM_DIR/bin:\$PATH" | sudo tee -a /etc/skel/.bashrc
echo "export LIBRARY_PATH=\$LLVM_DIR/lib:\$LIBRARY_PATH" | sudo tee -a /etc/skel/.bashrc
echo "export LD_LIBRARY_PATH=\$LLVM_DIR/lib:\$LD_LIBRARY_PATH" | sudo tee -a /etc/skel/.bashrc
echo "export LLVM_CONFIG=\$LLVM_DIR/bin/llvm-config" | sudo tee -a /etc/skel/.bashrc
fi
echo "cat /proc/cpuinfo" > ${HOME}/tmp/run.log
cat /proc/cpuinfo >> ${HOME}/tmp/run.log
echo "nproc" >> ${HOME}/tmp/run.log
nproc >> ${HOME}/tmp/run.log
echo "/usr/bin/g++ version" >> ${HOME}/tmp/run.log
/usr/bin/g++ --version >> ${HOME}/tmp/run.log
echo "install_llvm.sh costs $run_time [sec]." >> ${HOME}/tmp/run.log
echo ""