-
Notifications
You must be signed in to change notification settings - Fork 3
/
install.sh
executable file
·319 lines (280 loc) · 10.6 KB
/
install.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/env bash
# Copyright (c) 2015 - 2021 Hassan Salehe Matar
# All rights reserved.
#
# This file is part of TaskSanitizer. For details, see
# https://github.com/hassansalehe/TaskSanitizer. Please also see the
# LICENSE file for additional BSD notice
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
taskSanHomeDir=`pwd`
ThirdPartyDir=${taskSanHomeDir}/thirdparty
mkdir -p ${ThirdPartyDir}
buildsDir=${taskSanHomeDir}/.builds
mkdir -p ${buildsDir}
LLVMversion=5.0.0
procNo=`cat /proc/cpuinfo | grep processor | wc -l`
# Check if previous command was successful, exit script otherwise.
reportIfSuccessful() {
if [ $? -eq 0 ]; then
echo -e "\033[1;32mSUCCESS: $1.\033[m"
return 0
else
echo -e "\033[1;31mFAILURE: $1.\033[m"
exit 1
fi
}
CheckAndInstallPython() {
which python > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mFAILURE: No Python found.\033[m"
sudo apt-get install -y python python-matplotlib
return 1
else
echo -e "\033[1;32mSUCCESS: Python found.\033[m"
dpkg -l python-matplotlib | grep "python-matplotlib" > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mFAILURE: No Python found.\033[m"
sudo apt-get install -y python-matplotlib
return 1
else
echo -e "\033[1;32mSUCCESS: Python matplotlib found.\033[m"
return 0
fi
fi
return 0
}
## This function checks version of installed CMake.
## It succeeds if Cmake version is >= 3.8.1
checkCmakeVersion() {
version=`cmake --version | grep -i -m 1 version | egrep -o "[0-9]+\.[0-9]+\.[0-9]+" `
first=`echo ${version} | sed 's/\./ /g' | awk '{print $1}' `
second=`echo ${version} | sed 's/\./ /g' | awk '{print $2}' `
if [ "${first}" -gt "3" ]; then
echo -e "\033[1;32mSUCCESS: CMake (version ${version}) found.\033[m"
return 0
elif [ "${first}" -eq "3" ] && [ "${second}" -gt "7" ]; then
echo -e "\033[1;32mSUCCESS: CMake (version ${version}) found.\033[m"
return 0
fi
echo -e "\033[1;31mFAILURE: No CMake version >= 3.8.0 found.\033[m"
exit 1
}
BuildInstallCMake() {
cd ${ThirdPartyDir}
wget https://cmake.org/files/v3.10/cmake-3.10.3.tar.gz
tar -xvzf cmake-3.10.3.tar.gz
cd cmake-3.10.3
./bootstrap
make -j $procNo
sudo make install
cd $taskSanHomeDir
}
## This function checks version of installed Ninja-build system.
## It succeeds if Ninja-build version is >= 1.8.0
checkNinjaVersion() {
version=`ninja --version | egrep -o "[0-9]+\.[0-9]+\.[0-9]+" `
first=`echo ${version} | sed 's/\./ /g' | awk '{print $1}' `
second=`echo ${version} | sed 's/\./ /g' | awk '{print $2}' `
if [ "${first}" -gt "1" ]; then
echo -e "\033[1;32mSUCCESS: Ninja build (version ${version}) found.\033[m"
return 0
elif [ "${first}" -eq "1" ] && [ "${second}" -gt "7" ]; then
echo -e "\033[1;32mSUCCESS: Ninja build (version ${version}) found.\033[m"
return 0
fi
echo -e "\033[1;31mFAILURE: No Ninja build version >= 1.8.0 found.\033[m"
exit 1
}
BuildInstallNinjaBuildSystem() {
cd ${ThirdPartyDir}
git clone git://github.com/ninja-build/ninja.git && cd ninja
git checkout release
./configure.py --bootstrap
sudo mv ninja /usr/bin/
cd $taskSanHomeDir
}
CheckLLVMClang() {
which clang++ > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mFAILURE: LLVM/Clang compiler missing\033[m"
return 1
else
find /usr/include/ -name "Instrumentation.h" > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mFAILURE: LLVM/Clang compiler missing\033[m"
return 1
fi
fi
echo -e "\033[1;32mSUCCESS: LLVM/Clang compiler found\033[m"
return 0
}
BuildInstallLLVMClang() {
llvmDir=${ThirdPartyDir}/llvm
mkdir -p ${llvmDir} && cd ${llvmDir}
wget -c http://releases.llvm.org/${LLVMversion}/llvm-${LLVMversion}.src.tar.xz
tar xf llvm-${LLVMversion}.src.tar.xz --strip-components 1
rm llvm-${LLVMversion}.src.tar.xz
cd ${llvmDir}
mkdir -p tools/clang && cd tools/clang
wget -c http://releases.llvm.org/${LLVMversion}/cfe-${LLVMversion}.src.tar.xz
tar xf cfe-${LLVMversion}.src.tar.xz --strip-components 1
rm cfe-${LLVMversion}.src.tar.xz
mkdir -p tools/extra && cd tools/extra
wget -c http://releases.llvm.org/${LLVMversion}/clang-tools-extra-${LLVMversion}.src.tar.xz
tar xf clang-tools-extra-${LLVMversion}.src.tar.xz --strip-components 1
rm clang-tools-extra-${LLVMversion}.src.tar.xz
cd ${llvmDir}
mkdir -p projects/compiler-rt && cd projects/compiler-rt
wget -c http://releases.llvm.org/${LLVMversion}/compiler-rt-${LLVMversion}.src.tar.xz
tar xf compiler-rt-${LLVMversion}.src.tar.xz --strip-components 1
rm compiler-rt-${LLVMversion}.src.tar.xz
cd ${llvmDir}
mkdir -p projects/libcxx && cd projects/libcxx
wget -c http://releases.llvm.org/${LLVMversion}/libcxx-${LLVMversion}.src.tar.xz
tar xf libcxx-${LLVMversion}.src.tar.xz --strip-components 1
rm libcxx-${LLVMversion}.src.tar.xz
cd ${llvmDir}
mkdir -p projects/libcxxabi && cd projects/libcxxabi
wget -c http://releases.llvm.org/${LLVMversion}/libcxxabi-${LLVMversion}.src.tar.xz
tar xf libcxxabi-${LLVMversion}.src.tar.xz --strip-components 1
rm libcxxabi-${LLVMversion}.src.tar.xz
cd ${llvmDir}
mkdir -p projects/libunwind && cd projects/libunwind
wget -c http://releases.llvm.org/${LLVMversion}/libunwind-${LLVMversion}.src.tar.xz
tar xf libunwind-${LLVMversion}.src.tar.xz --strip-components 1
rm libunwind-${LLVMversion}.src.tar.xz
echo "Building LLVM"
mkdir -p ${llvmDir}/build && cd ${llvmDir}/build
sudo cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr ${llvmDir}
procNo=`cat /proc/cpuinfo | grep processor | wc -l`
sudo make -j ${procNo}
sudo make install
# Report if everything is OK so far
reportIfSuccessful "Building LLVM/Clang"
}
# Checks if necessary packages are installed in the machine
# Installs the packages if user approves.
CheckPrerequisites() {
which wget > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mERROR! wget missing\033[m"
read -p "Do you want to install wget (root password is needed)? [N/y] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then sudo apt-get install -y wget; fi
fi
which tar > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mERROR! tar missing\033[m"
read -p "Do you want to install tar (root password is needed)? [N/y]" -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then sudo apt-get install -y tar; fi
fi
# check if cmake is installed
which cmake > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mERROR! cmake missing\033[m"
read -p "Do you want to install cmake (root password is needed)? [N/y] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sudo apt-get install -y cmake
which cmake > /dev/null
if [ $? -eq 0 ]; then
checkCmakeVersion
if [ $? -ne 0 ]; then
BuildInstallCMake
fi
fi
fi
fi
checkCmakeVersion
# check if Clang compiler is installed
CheckLLVMClang
if [ $? -ne 0 ]; then
read -p "Do you want to install LLVM/Clang (root password is needed)? [N/y] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
BuildInstallLLVMClang
fi
fi
# check if Ninja build system is installed
which ninja > /dev/null
if [ $? -ne 0 ]; then
echo -e "\033[1;31mERROR! Ninja build system missing\033[m"
read -p "Do you want to install Ninja (root password is needed)? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
BuildInstallNinjaBuildSystem
fi
fi
checkNinjaVersion
CheckAndInstallPython
}
# Step 0: Check for prerequisites and install necessary packages
CheckPrerequisites
# Step 1: Download the OpenMP runtime
if [ ! -e "${ThirdPartyDir}/openmp" ]; then
cd ${ThirdPartyDir}
git clone https://github.com/hassansalehe/openmp.git openmp
fi
export OPENMP_INSTALL=${taskSanHomeDir}/bin
mkdir -p $OPENMP_INSTALL
openmpsrc=${ThirdPartyDir}/openmp
mkdir -p ${buildsDir}/openmp-build && cd ${buildsDir}/openmp-build
cmake -G Ninja -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ \
-D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX:PATH=$OPENMP_INSTALL \
-D LIBOMP_OMPT_SUPPORT=on -D LIBOMP_OMPT_BLAME=on -D LIBOMP_OMPT_TRACE=on ${openmpsrc}
ninja -j8 -l8
ninja install
reportIfSuccessful "Compiling OpenMP runtime"
# Step 2: Download Archer tool
if [ ! -e "${ThirdPartyDir}/archer" ]; then
cd ${ThirdPartyDir}
git clone https://github.com/hassansalehe/archer.git archer
cd archer
git checkout update_to_60
fi
export ARCHER_INSTALL=${taskSanHomeDir}/bin
archersrc=${ThirdPartyDir}/archer
mkdir -p ${buildsDir}/archer-build && cd ${buildsDir}/archer-build
cmake -G Ninja -D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++ \
-D OMP_PREFIX:PATH=$OPENMP_INSTALL -D CMAKE_INSTALL_PREFIX:PATH=${ARCHER_INSTALL} ${archersrc}
ninja -j8 -l8
ninja install
reportIfSuccessful "Compiling Archer race detection tool"
# Step 4: Build TaskSanitizer instrumentation module
mkdir -p ${buildsDir}/libLogger-build && cd ${buildsDir}/libLogger-build
rm -rf libLogger.a
CXX=clang++ cmake -G Ninja ${taskSanHomeDir}/src/instrumentor
ninja
reportIfSuccessful "Compiling TaskSanitizer runtime"
mkdir -p ${buildsDir}/tasksan-build && cd ${buildsDir}/tasksan-build
rm -rf libTaskSanitizer.so
CXX=clang++ cmake -G Ninja ${taskSanHomeDir}/src/instrumentor/pass/
ninja
reportIfSuccessful "Compiling TaskSanitizer instrumentation"