This repository has been archived by the owner on Jul 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 44
/
setup
executable file
·298 lines (286 loc) · 9.93 KB
/
setup
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
#!/bin/sh
WHITE='\033[1;37m'
LCYAN='\033[1;36m'
CYAN='\033[0;36m'
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
echo "
:/${LCYAN}++${NC}+++++/-
-o+-. ${LCYAN}--${NC} .:o+.
o+ ${CYAN}ss${LCYAN}++${CYAN}ooooo${NC} .o+
s: ${CYAN}-+${BLUE}o-${LCYAN}///${BLUE}:::/-${CYAN}s:.${NC} +o ${WHITE}-::::- /. .::::- .::::: /- ./::::. ::::::${NC}
+o ${CYAN}/s${BLUE}-s ${LCYAN}--${BLUE} o+${CYAN}o:${NC} s- ${WHITE}.o. o.o. s. +: +-+- -+ -o +- ${NC}
o/ ${CYAN}+s${BLUE}-o ${LCYAN}-....${BLUE} o+${CYAN}o:${NC} o/ ${WHITE}/: o o .:/::- -+ +- +- -+ /: +/::::${NC}
++ ${CYAN}/s${BLUE}-o ${LCYAN}....${BLUE} o+${CYAN}o:${NC} s- ${WHITE}.o o:::::o o- o- //::::o- -+ .o +- ${NC}
s: ${CYAN}-+${BLUE}o:/::::${LCYAN}+${BLUE}::${CYAN}s/.${NC} +o ${WHITE}:::::: :. ./ -::::: -/:::: -: + ./::::- :/::::${NC}
.o/ ${CYAN}.sssoos${LCYAN}+${CYAN}oo${NC} .o+
:o/- ${LCYAN}.${NC} ++.
.:/+++++${LCYAN}+${NC}+/- VMware Cascade Build Setup Script
"
PROCESSORS="$(getconf _NPROCESSORS_ONLN)"
if [ -d "build" ]; then
echo "Build is already setup! Run:"
echo "${WHITE}cd build"
echo "make -j ${PROCESSORS}"
echo "make install${NC}"
echo
echo "To build and install. "
echo
echo "Or, to reconfigure, delete the build directory first:"
echo "${RED}rm -rf build${NC}"
echo "Then run this script again."
exit 1
fi
SILENT=0
COVERAGE=0
DO_BUILD=1
DO_TESTS=1
DO_INSTALL=1
BUILD_TYPE="Release"
WRAPPER=""
CMAKE_FLAGS=""
for i in "$@"; do
case $i in
--debug)
BUILD_TYPE="Debug"
;;
--coverage)
COVERAGE=1
WRAPPER="build-wrapper-linux-x86-64 --out-dir bw-output"
CMAKE_FLAGS="-DCOVERAGE=TRUE"
;;
--no-install)
DO_INSTALL=0
;;
--no-build)
DO_BUILD=0
;;
--no-test)
DO_TESTS=0
;;
--silent)
SILENT=1
;;
*)
;;
esac
done
check_homebrew() {
printf '%.20s %s' "$1..................................";
if brew ls --versions $1 > /dev/null; then
echo "${GREEN}present${NC}"
return 1
else
echo "${RED}missing${NC}"
if [ $1 == "gtest" ]; then
MISSING="share/cascade/script/gtest.rb $MISSING"
else
MISSING="$1 $MISSING"
fi
return 0
fi
}
check_dpkg() {
printf '%.20s %s' "$1..................................";
if dpkg-query -W -f='${Status}' $1 2>/dev/null | grep -c "ok installed"; then
echo "${GREEN}present${NC}"
return 1
else
echo "${RED}missing${NC}"
MISSING="$1 $MISSING"
return 0
fi
}
call_prompt() {
if [ $SILENT -eq 1 ]; then
return $2
else
echo $1
echo "1) Yes"
echo "2) No"
read -p "#? " yn
case $yn in
[yY]* ) return 1
;;
[nN]* ) return 0
;;
"1" ) return 1
;;
"0" ) return 0
;;
* ) echo "Please enter yes or no"
;;
esac
fi
}
build_cascade() {
echo "Creating build directory..."
mkdir -p build
cd build
echo "Running cmake..."
cmake $1 $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=$BUILD_TYPE ..
echo "Build directory configured and makefiles generated."
call_prompt "Would you like us to build Cascade for you?" $DO_BUILD
if [ $? -eq 1 ]; then
$WRAPPER make -j ${PROCESSORS};
else
echo "When you are ready, to build cascade run:";
echo "${WHITE}cd build${NC}";
echo "${WHITE}make -j ${PROCESSORS}${NC}";
echo "Then to run the tests:";
echo "${WHITE}make test${NC}";
echo "Finally, to install cascade to your system:";
echo "${WHITE}sudo make install${NC}";
cd ..;
exit 0;
fi
call_prompt "Would you like us to run the tests to make sure Cascade was built correctly?" $DO_TESTS
if [ $? -eq 1 ]; then
if [ $COVERAGE -eq 0 ]; then
make test
else
make cascade_coverage
fi
if [ $? -ne 0 ]; then
return 1
fi
else
echo "Skipping the tests. If you want to run the tests run:"
echo "${WHITE}cd build${NC}"
echo "${WHITE}make test${NC}"
fi
call_prompt "Would you like us to install Cascade to your system (requires admin rights)?" $DO_INSTALL
if [ $? -eq 1 ]; then
sudo make install
echo "Cascade installed. You can run cascade by typing ${WHITE}cascade${NC} from your terminal."
echo "If you would like to develop Cascade, the appropriate Makefiles have been generated in the ${WHITE}build${NC} directory."
else
echo "Skipping installation. You can manually run Cascade from ${WHITE}build/bin/cascade${NC}"
echo "Or to install,"
echo "${WHITE}cd build${NC}"
echo "${WHITE}sudo make install${NC}"
fi
cd ..
}
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*)
echo "Detected Linux."
if ! [ -x "$(command -v dpkg-query)" ]; then
echo "This is not a dpkg/apt managed system."
echo "If your build fails, please check for the following packages: "
echo " g++ git cmake flex libfl-dev bison python3-venv python3-dev libncurses5-dev libbenchmark-dev libgtest-dev verilator"
else
echo "dpkg is ${GREEN}installed${NC}."
echo "Checking for required dpkg packages..."
MISSING=""
check_dpkg g++
check_dpkg git
check_dpkg cmake
check_dpkg flex
check_dpkg libfl-dev
check_dpkg bison
check_dpkg python3-venv
check_dpkg python3-dev
check_dpkg libncurses5-dev
check_dpkg libbenchmark-dev
check_dpkg libgtest-dev
check_dpkg verilator
if [ "$MISSING" != "" ]; then
if [ $SILENT -eq 0 ]; then
echo "You are missing the following packages: $MISSING"
call_prompt "Would you like us to install these packages using apt for you?" 1
case $? in
1 ) ;;
0 ) echo "Please install these packages manually, then run this script again."
exit 1
;;
esac
fi
sudo apt-get install -y --no-install-recommends $MISSING
cd /usr/src/gtest; \
sudo cmake CMakeLists.txt; \
sudo make; \
sudo make install; \
cd -; \
sudo rm /usr/local/lib/libgtest_main.a && sudo ln -n /usr/src/gtest/libgtest_main.a /usr/local/lib/libgtest_main.a; \
sudo rm /usr/local/lib/libgtest.a && sudo ln -n /usr/src/gtest/libgtest.a /usr/local/lib/libgtest.a;
fi
fi
build_cascade "-DFLEX_EXECUTABLE=/usr/bin/flex -DBISON_EXECUTABLE=/usr/bin/bison -DFLEX_INCLUDE_DIR=/usr/include"
;;
Darwin*)
echo "Detected macOS."
if ! [ -x "$(command -v brew)" ]; then
echo "This is not a homebrew managed system."
call_prompt "Would you like us to install homebrew for you?" 1
case $? in
1 ) ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
;;
0 ) ;;
esac
echo "If your build fails, please check for the following packages: "
echo " cmake flex bison python3 ncurses google-benchmark gtest verilator"
fi
if [ -x "$(command -v brew)" ]; then
echo "Homebrew is ${GREEN}installed${NC}."
echo "Checking for required Homebrew packages..."
MISSING=""
check_homebrew cmake
check_homebrew flex
check_homebrew bison
check_homebrew python3
check_homebrew ncurses
check_homebrew google-benchmark
check_homebrew gtest
check_homebrew verilator
if [ "$MISSING" != "" ]; then
if [ $SILENT -eq 0 ]; then
echo "You are missing the following packages: $MISSING"
call_prompt "Would you like us to install these packages using homebrew for you?" 1
case $? in
1 ) ;;
0 ) echo "Please install these packages manually, then run this script again."
exit 1
;;
esac
fi
brew install $MISSING
brew link --overwrite gtest
fi
fi
if type xcode-select >&- && xpath=$( xcode-select --print-path ) && test -d "${xpath}" && test -x "${xpath}" ; then
echo "xcode is ${GREEN}installed${NC}."
else
echo "xcode is ${RED}not installed${NC}."
echo "xcode must be installed in order to build Cascade"
call_prompt "Would you like us to install xcode for you?" 1
case $yn in
1 ) xcode-select --install
;;
0 ) echo "Please install xcode manually, then run this script again."
exit 1
;;
esac
fi
export CPP="g++ -E"
if [ ! -d "/usr/include" ]; then
if [ $SILENT -eq 1 ]; then
echo "Your /usr/include directly does not seem to be configured correctly (CI ignored)."
else
echo "Your /usr/include directly does not seem to be configured correctly."
OS_VERSION=$(sw_vers -productVersion | sed "s:.[[:digit:]]*.$::g")
HEADERS_INSTALL_PATH="/Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_${OS_VERSION}.pkg"
echo "Try installing the package manually by running:"
echo "${WHITE}open ${HEADERS_INSTALL_PATH}${NC}"
exit 1
fi
fi
build_cascade "-DFLEX_EXECUTABLE=/usr/local/opt/flex/bin/flex -DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison -DFLEX_INCLUDE_DIR=/usr/local/opt/flex/include"
;;
*)
echo "Sorry, your machine type ${unameOut} is not yet supported. Please setup the cmake project manually."
;;
esac