forked from gnmartins/assert-p4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·276 lines (222 loc) · 9.22 KB
/
setup.sh
File metadata and controls
executable file
·276 lines (222 loc) · 9.22 KB
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
#!/bin/bash
# Setup script for assert-p4
# author: Gabriel Martins <gabrielnmartins@gmail.com>
MAIN_INSTALL_DIR=$(pwd)
sudo apt-get update
sudo apt-get install -y git vim
#========================================================================================
#=== Installing p4c =====================================================================
# adapted from https://github.com/jafingerhut/p4-guide/blob/master/bin/install-p4dev.sh
#========================================================================================
echo "#==============================================================================="
echo "#=== Installing p4c ============================================================"
echo "# adapted from https://github.com/jafingerhut/p4-guide/blob/master/bin/install-p4dev.sh"
echo "#==============================================================================="
MAX_PARALLEL_JOBS=3
INSTALL_DIR="${PWD}"
THIS_SCRIPT_FILE_MAYBE_RELATIVE="$0"
THIS_SCRIPT_DIR_MAYBE_RELATIVE="${THIS_SCRIPT_FILE_MAYBE_RELATIVE%/*}"
THIS_SCRIPT_DIR_ABSOLUTE=`readlink -f "${THIS_SCRIPT_DIR_MAYBE_RELATIVE}"`
# protobuf dependencies
sudo apt-get install -y autoconf automake libtool curl make unzip
# p4c dependencies
sudo apt-get install -y git automake libtool libgc-dev bison flex libfl-dev \
libgmp-dev libboost-dev libboost-iostreams-dev libboost-graph-dev pkg-config \
python python-scapy python-ipaddr python-ply tcpdump cmake
# behavioral model
echo "Installing p4lang/behavioral-model..."
cd "${INSTALL_DIR}"
git clone https://github.com/p4lang/behavioral-model.git
cd behavioral-model
./install_deps.sh
./autogen.sh
./configure 'CXXFLAGS=-O0 -g'
make
sudo make install
# protobuf
echo "Installing google/protobuf..."
cd "${INSTALL_DIR}"
git clone https://github.com/google/protobuf
cd protobuf
git checkout v3.2.0
./autogen.sh
./configure
make
sudo make install
sudo ldconfig
make clean
# p4c => forked p4c:0.1.0, p4c-bm2-ss:0.0.5
echo "Installing p4c..."
cd "${INSTALL_DIR}"
git clone --recursive https://github.com/gnmartins/p4c.git
cd p4c
mkdir build
cd build
# Configure for a debug build
cmake .. -DCMAKE_BUILD_TYPE=DEBUG $*
make -j${MAX_PARALLEL_JOBS}
cd "${INSTALL_DIR}"
#========================================================================================
#=== Installing p4pktgen ================================================================
#========================================================================================
echo "#==============================================================================="
echo "#=== Installing p4pktgen ======================================================="
echo "#==============================================================================="
git clone https://github.com/p4pktgen/p4pktgen.git
cd p4pktgen
./tools/install.sh
cd "${INSTALL_DIR}"
#========================================================================================
#=== Installing klee ====================================================================
# adapted from https://github.com/tum-i22/klee-install/blob/master/README.md
#========================================================================================
echo "#==============================================================================="
echo "#=== Installing klee ==========================================================="
echo "# adapted from https://github.com/tum-i22/klee-install/blob/master/README.md"
echo "#==============================================================================="
mkdir klee-build
BUILDDIR="klee-build"
cd "$BUILDDIR"
# dependencies
sudo apt-get install -y bc bison build-essential cmake curl flex git libboost-all-dev \
libcap-dev libncurses5-dev python-minimal python-pip subversion unzip zlib1g-dev
#=== LLVM ===========================
echo "Building LLVM..."
# https://releases.llvm.org/download.html#3.4.2
wget https://releases.llvm.org/3.4.2/llvm-3.4.2.src.tar.gz
wget https://releases.llvm.org/3.4.2/cfe-3.4.2.src.tar.gz
wget https://releases.llvm.org/3.4/compiler-rt-3.4.src.tar.gz
wget https://releases.llvm.org/3.4.2/libcxx-3.4.2.src.tar.gz
wget https://releases.llvm.org/3.4/test-suite-3.4.src.tar.gz
tar xvzf llvm-3.4.2.src.tar.gz
tar xvzf cfe-3.4.2.src.tar.gz
tar xvzf compiler-rt-3.4.src.tar.gz
tar xvzf libcxx-3.4.2.src.tar.gz
tar xvzf test-suite-3.4.src.tar.gz
mv llvm-3.4.2.src llvm
mv cfe-3.4.2.src llvm/tools/clang
mv compiler-rt-3.4 llvm/projects/compiler-rt
mv libcxx-3.4.2.src llvm/projects/libcxx
mv test-suite-3.4 llvm/projects/test-suite
# svn repo no longer accesible
# svn co https://llvm.org/svn/llvm-project/llvm/tags/RELEASE_342/final llvm
# svn co https://llvm.org/svn/llvm-project/cfe/tags/RELEASE_342/final llvm/tools/clang
# svn co https://llvm.org/svn/llvm-project/compiler-rt/tags/RELEASE_342/final llvm/projects/compiler-rt
# svn co https://llvm.org/svn/llvm-project/libcxx/tags/RELEASE_342/final llvm/projects/libcxx
# svn co https://llvm.org/svn/llvm-project/test-suite/tags/RELEASE_342/final/ llvm/projects/test-suite
# rm -rf llvm/.svn
# rm -rf llvm/tools/clang/.svn
# rm -rf llvm/projects/compiler-rt/.svn
# rm -rf llvm/projects/libcxx/.svn
# rm -rf llvm/projects/test-suite/.svn
cd llvm
./configure --enable-optimized --disable-assertions --enable-targets=host --with-python="/usr/bin/python2"
make -j `nproc`
make -j `nproc` check-all
cd ..
#====================================
#=== Minisat ========================
echo "Building Minisat..."
git clone --depth 1 https://github.com/stp/minisat.git
rm -rf minisat/.git
cd minisat
make
cd ..
#====================================
#=== STP ============================
echo "Building STP..."
git clone --depth 1 --branch stp-2.2.0 https://github.com/stp/stp.git
rm -rf stp/.git
cd stp
mkdir build
cd build
cmake \
-DBUILD_STATIC_BIN=ON \
-DBUILD_SHARED_LIBS:BOOL=OFF \
-DENABLE_PYTHON_INTERFACE:BOOL=OFF \
-DMINISAT_INCLUDE_DIR="../../minisat/" \
-DMINISAT_LIBRARY="../../minisat/build/release/lib/libminisat.a" \
-DCMAKE_BUILD_TYPE="Release" \
-DTUNE_NATIVE:BOOL=ON ..
make -j `nproc`
cd ../..
#====================================
#=== uclibc =========================
echo "Building uclibc and the POSIX environment model..."
git clone --depth 1 --branch klee_uclibc_v1.0.0 https://github.com/klee/klee-uclibc.git
rm -rf klee-uclibc/.git
cd klee-uclibc
./configure \
--make-llvm-lib \
--with-llvm-config="../llvm/Release/bin/llvm-config" \
--with-cc="../llvm/Release/bin/clang"
make -j `nproc`
cd ..
#====================================
#=== Z3 =============================
echo "Building Z3..."
git clone --depth 1 --branch z3-4.5.0 https://github.com/Z3Prover/z3.git
rm -rf z3/.git
cd z3
python scripts/mk_make.py
cd build
make -j `nproc`
# partialy copied from make install target
mkdir -p ./include
mkdir -p ./lib
cp ../src/api/z3.h ./include/z3.h
cp ../src/api/z3_v1.h ./include/z3_v1.h
cp ../src/api/z3_macros.h ./include/z3_macros.h
cp ../src/api/z3_api.h ./include/z3_api.h
cp ../src/api/z3_ast_containers.h ./include/z3_ast_containers.h
cp ../src/api/z3_algebraic.h ./include/z3_algebraic.h
cp ../src/api/z3_polynomial.h ./include/z3_polynomial.h
cp ../src/api/z3_rcf.h ./include/z3_rcf.h
cp ../src/api/z3_fixedpoint.h ./include/z3_fixedpoint.h
cp ../src/api/z3_optimization.h ./include/z3_optimization.h
cp ../src/api/z3_interp.h ./include/z3_interp.h
cp ../src/api/z3_fpa.h ./include/z3_fpa.h
cp libz3.so ./lib/libz3.so
cp ../src/api/c++/z3++.h ./include/z3++.h
cd ../..
#====================================
#=== KLEE ===========================
echo "Building KLEE..."
git clone --depth 1 --branch 1.3.x https://github.com/gnmartins/klee.git
rm -rf klee/.git
BUILDDIR=`pwd`
cd klee
./configure \
LDFLAGS="-L$BUILDDIR/minisat/build/release/lib/" \
--with-llvm=$BUILDDIR/llvm/ \
--with-llvmcc=$BUILDDIR/llvm/Release/bin/clang \
--with-llvmcxx=$BUILDDIR/llvm/Release/bin/clang++ \
--with-stp=$BUILDDIR/stp/build/ \
--with-uclibc=$BUILDDIR/klee-uclibc \
--with-z3=$BUILDDIR/z3/build/ \
--enable-cxx11 \
--enable-posix-runtime
make -j `nproc` ENABLE_OPTIMIZED=1
# Copy Z3 libraries to a place, where klee can find them
cp ../z3/build/lib/libz3.so ./Release+Asserts/lib/
make -j `nproc` check
cd ..
#========================================================================================
echo "#==============================================================================="
echo -e "\n" >> ~/.profile
echo "# assert-p4:" >> ~/.profile
echo "# p4c binaries" >> ~/.profile
echo "P4C_BUILD_DIR="$MAIN_INSTALL_DIR/p4c/build"" >> ~/.profile
echo "" >> ~/.profile
echo "# klee binaries" >> ~/.profile
echo "KLEE_BIN_DIR="$MAIN_INSTALL_DIR/klee-build/klee/Release+Asserts/bin"" >> ~/.profile
echo "LLVM_BIN_DIR="$MAIN_INSTALL_DIR/klee-build/llvm/Release/bin"" >> ~/.profile
echo "" >> ~/.profile
echo "PATH="\$P4C_BUILD_DIR:\$KLEE_BIN_DIR:\$LLVM_BIN_DIR:\$HOME/bin:\$HOME/.local/bin:\$PATH"" >> ~/.profile
echo "All assert-p4 dependencies have been compiled."
echo "The build directories have been added to your PATH in ~/.profile"
echo -e "\tP4C_BUILD_DIR=\"$MAIN_INSTALL_DIR/p4c/build\""
echo -e "\tKLEE_BIN_DIR=\"$MAIN_INSTALL_DIR/klee-build/klee/Release+Asserts/bin\""
echo -e "\tLLVM_BIN_DIR=\"$MAIN_INSTALL_DIR/klee-build/llvm/Release/bin\""
echo "For any suggestions, please contact <gabrielnmartins@gmail.com>."
echo "#==============================================================================="