This repository has been archived by the owner on Sep 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·245 lines (219 loc) · 6.65 KB
/
build.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
#!/usr/bin/env bash
# type './build.sh' for release build
# type './build.sh debug' for debug build
# if the LLVM_DIR variable is not set, LLVM will be downloaded.
#
# Dependencies include: build-essential libncurses5 libncurses-dev cmake zlib1g-dev
set -e # exit on first error
jobs=4
#########
# VARs and Links
########
SVFHOME=$(pwd)
sysOS=$(uname -s)
arch=$(uname -m)
MacLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-apple-darwin.tar.xz"
UbuntuLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-x86_64-linux-gnu-ubuntu-16.04.tar.xz"
UbuntuArmLLVM="https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.0/clang+llvm-13.0.0-aarch64-linux-gnu.tar.xz"
SourceLLVM="https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-13.0.0.zip"
MacZ3="https://github.com/Z3Prover/z3/releases/download/z3-4.8.8/z3-4.8.8-x64-osx-10.14.6.zip"
MacArmZ3="https://github.com/Z3Prover/z3/releases/download/z3-4.9.1/z3-4.9.1-arm64-osx-11.0.zip"
UbuntuZ3="https://github.com/Z3Prover/z3/releases/download/z3-4.8.8/z3-4.8.8-x64-ubuntu-16.04.zip"
SourceZ3="https://github.com/Z3Prover/z3/archive/refs/tags/z3-4.8.8.zip"
# Keep LLVM version suffix for version checking and better debugging
# keep the version consistent with LLVM_DIR in setup.sh and llvm_version in Dockerfile
LLVMHome="llvm-13.0.0.obj"
Z3Home="z3.obj"
# Downloads $1 (URL) to $2 (target destination) using wget or curl,
# depending on OS.
# E.g. generic_download_file www.url.com/my.zip loc/my.zip
function generic_download_file {
if [ $# -ne 2 ]
then
echo "$0: bad args to generic_download_file!"
exit 1
fi
if [ -f "$2" ]; then
echo "File $2 exists, skip download..."
return
fi
local download_failed=false
if type curl &> /dev/null; then
if ! curl -L "$1" -o "$2"; then
download_failed=true
fi
elif type wget &> /dev/null; then
if ! wget -c "$1" -O "$2"; then
download_failed=true
fi
else
echo "Cannot find download tool. Please install curl or wget."
exit 1
fi
if $download_failed; then
echo "Failed to download $1"
rm -f "$2"
exit 1
fi
}
# check if unzip is missing (Z3)
function check_unzip {
if ! type unzip &> /dev/null; then
echo "Cannot find unzip. Please install unzip."
exit 1
fi
}
# check if xz is missing (LLVM)
function check_xz {
if ! type xz &> /dev/null; then
echo "Cannot find xz. Please install xz-utils."
exit 1
fi
}
function build_z3_from_source {
mkdir "$Z3Home"
echo "Downloading Z3 source..."
generic_download_file "$SourceZ3" z3.zip
check_zip
echo "Unzipping Z3 source..."
mkdir z3-source
unzip z3.zip -d z3-source
echo "Building Z3..."
mkdir z3-build
cd z3-build
# /* is a dirty hack to get z3-version...
cmake -DCMAKE_INSTALL_PREFIX="$SVFHOME/$Z3Home" -DZ3_BUILD_LIBZ3_SHARED=false ../z3-source/*
make -j${jobs}
make install
cd ..
rm -r z3-source z3-build z3.zip
}
function build_llvm_from_source {
mkdir "$LLVMHome"
echo "Downloading LLVM source..."
generic_download_file "$SourceLLVM" llvm.zip
check_unzip
echo "Unzipping LLVM source..."
mkdir llvm-source
unzip llvm.zip -d llvm-source
echo "Building LLVM..."
mkdir llvm-build
cd llvm-build
# /*/ is a dirty hack to get llvm-project-llvmorg-version...
cmake -DCMAKE_INSTALL_PREFIX="$SVFHOME/$LLVMHome" ../llvm-source/*/llvm
make -j${jobs}
make install
cd ..
rm -r llvm-source llvm-build llvm.zip
}
# OS-specific values.
urlLLVM=""
urlZ3=""
OSDisplayName=""
########
# Set OS-specific values, mainly URLs to download binaries from.
# M1 Macs give back arm64, some Linuxes can give aarch64 for arm architecture
#######
if [[ $sysOS == "Darwin" ]]
then
if [[ "$arch" == "arm64" ]]
then
urlZ3="$MacArmZ3"
urlLLVM="llvm does not have osx arm pre-built libs"
OSDisplayName="macOS arm64"
else
urlZ3="$MacZ3"
urlLLVM="$MacLLVM"
OSDisplayName="macOS x86"
fi
elif [[ $sysOS == "Linux" ]]
then
if [[ "$arch" == "aarch64" ]]
then
urlLLVM="$UbuntuArmLLVM"
urlZ3="z3 does not have x86 arm pre-built libs"
OSDisplayName="Ubuntu arm64"
else
urlLLVM="$UbuntuLLVM"
urlZ3="$UbuntuZ3"
OSDisplayName="Ubuntu x86"
fi
else
echo "Builds outside Ubuntu and macOS are not supported."
fi
########
# Download LLVM if need be.
#######
if [ ! -d "$LLVM_DIR" ]
then
if [ ! -d "$LLVMHome" ]
then
if [ "$sysOS" = "Darwin" ] && [ "$arch" = "arm64" ] # only mac arm build from source
then
build_llvm_from_source
else # everything else downloads pre-built lib includ osx "arm64"
echo "Downloading LLVM binary for $OSDisplayName"
generic_download_file "$urlLLVM" llvm.tar.xz
check_xz
echo "Unzipping llvm package..."
mkdir -p "./$LLVMHome" && tar -xf llvm.tar.xz -C "./$LLVMHome" --strip-components 1
rm llvm.tar.xz
fi
fi
export LLVM_DIR="$SVFHOME/$LLVMHome"
fi
########
# Download Z3 if need be.
#######
if [ ! -d "$Z3_DIR" ]
then
if [ ! -d "$Z3Home" ]
then
# M1 Macs give back arm64, some Linuxes can give aarch64.
if [ "$sysOS" = "Linux" ] && [ "$arch" = "aarch64" ] # only linux arm build from source
then
build_z3_from_source
else # everything else downloads pre-built lib includ osx "arm64"
echo "Downloading Z3 binary for $OSDisplayName"
generic_download_file "$urlZ3" z3.zip
check_unzip
echo "Unzipping z3 package..."
unzip -q "z3.zip" && mv ./z3-* ./$Z3Home
rm z3.zip
fi
fi
export Z3_DIR="$SVFHOME/$Z3Home"
fi
export PATH=$LLVM_DIR/bin:$PATH
echo "LLVM_DIR=$LLVM_DIR"
echo "Z3_DIR=$Z3_DIR"
########
# Build SVF
########
if [[ $1 == 'debug' ]]
then
rm -rf ./'Debug-build'
mkdir ./'Debug-build'
cd ./'Debug-build'
cmake -D CMAKE_BUILD_TYPE:STRING=Debug ../
else
rm -rf ./'Release-build'
mkdir ./'Release-build'
cd ./'Release-build'
cmake ../
fi
make -j ${jobs}
########
# Set up environment variables of SVF
########
cd ../
if [[ $1 == 'debug' ]]
then
. ./setup.sh debug
else
. ./setup.sh
fi
#########
# Optionally, you can also specify a CXX_COMPILER and your $LLVM_HOME for your build
# cmake -DCMAKE_CXX_COMPILER=$LLVM_DIR/bin/clang++ -DLLVM_DIR=$LLVM_DIR
#########