forked from vmware-archive/cascade
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·318 lines (306 loc) · 13.2 KB
/
setup
File metadata and controls
executable file
·318 lines (306 loc) · 13.2 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
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
#!/bin/bash
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 -e "
:/${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"
echo -e
PROCESSORS="$(getconf _NPROCESSORS_ONLN)"
if [ -d "build" ]; then
echo -e "Build is already setup! Run:
${WHITE}cd build
make -j ${PROCESSORS}
make install${NC}
To build and install.
Or, to reconfigure, delete the build directory first:
${RED}rm -rf build${NC}
Then run this script again.
"
exit 1
fi
SILENT=0
DO_BUILD=1
DO_TESTS=0
DO_INSTALL=1
BUILD_TYPE="Release"
CMAKE_EXTRA=""
WRAPPER=""
COVERAGE=0
for i in "$@"
do
case $i in
--debug)
BUILD_TYPE="Debug"
;;
--pre-ci)
SILENT=1
DO_INSTALL=0
DO_BUILD=0
;;
--ci)
SILENT=1
;;
-c=*|--coverage=*)
if [ "${i#*=}" -eq "1" ]; then
BUILD_TYPE="Debug"
COVERAGE=1
WRAPPER="build-wrapper-linux-x86-64 --out-dir bw-output"
CMAKE_EXTRA="-DCOVERAGE=TRUE -DBUILD_TESTS=ON"
DO_TESTS=1
fi
;;
--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 -e "${GREEN}present${NC}"
return 1
else
echo -e "${RED}missing${NC}"
MISSING=$2[@]
if [ $1 == "gtest" ]; then
MISSING+=("data/script/gtest.rb")
else
MISSING+=($1)
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 -e "${GREEN}present${NC}"
return 1
else
echo -e "${RED}missing${NC}"
MISSING=$2[@]
MISSING+=($1)
return 0
fi
}
function call_prompt() {
if [ $SILENT -eq 1 ]; then
return $2
else
echo $1
select yn in "Yes" "No"; do
case $yn in
Yes ) return 1; break;;
No ) return 0; break;;
esac
done
return 0
fi
}
build_cascade() {
echo -en "Creating build directory..."
mkdir -p build
echo -e "${GREEN}ok${NC}"
cd build
echo "Running cmake..."
cmake $1 $CMAKE_EXTRA -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 -e "${WHITE}cd build${NC}";
echo -e "${WHITE}make -j ${PROCESSORS}${NC}";
echo "Then to run the tests:";
echo -e "${WHITE}make test${NC}";
echo "Finally, to install cascade to your system:";
echo -e "${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 1 ]; then
make cascade_coverage
else
make test
fi
else
echo "Skipping the tests. If you want to run the tests run:"
echo -e "${WHITE}cd build${NC}"
echo -e "${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 -e "Cascade installed. You can run cascade by typing ${WHITE}cascade${NC} from your terminal."
echo -e "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 -e "${WHITE}cd build${NC}"
echo -e "${WHITE}sudo make install${NC}"
fi
cd ..
}
unameOut="$(uname -s)"
case "${unameOut}" in
Linux*) echo -e "Detected Linux.";
if ! [ -x "$(command -v dpkg-query)" ]; then
echo -e "This is not a dpkg/apt managed system."
echo -e "We can't check if packages are installed for you."
echo -e "If building fails, you should make sure you have the packages"
echo -e "g++ cmake flex bison python3-venv"
echo -e "installed."
else
echo -e "dpkg is ${GREEN}installed${NC}."
echo -e "Checking for required dpkg packages..."
MISSING=()
check_dpkg g++ MISSING
check_dpkg git MISSING
check_dpkg cmake MISSING
check_dpkg flex MISSING
check_dpkg bison MISSING
check_dpkg python3-venv MISSING
check_dpkg python3-dev MISSING
check_dpkg libncurses5-dev MISSING
check_dpkg libbenchmark-dev MISSING
check_dpkg libgtest-dev MISSING
check_dpkg verilator MISSING
MISSING_LIST=$(printf " %s" "${MISSING[@]:1}")
MISSING_LIST=${MISSING_LIST:1}
if [ $SILENT -eq 1 ]; then
sudo apt-get install -y --no-install-recommends ${MISSING_LIST}; \
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;
else
if [ ${#MISSING[@]} -gt 0 ]; then
echo "You are missing the following packages: ${MISSING_LIST}"
echo "Would you like us to install these packages using apt for you?"
select yn in "Yes" "No"; do
case $yn in
Yes ) sudo apt-get install -y --no-install-recommends ${MISSING_LIST}; \
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; \
break;;
No ) echo "Please install these packages manually, then run this script again.";
exit 1;;
esac
done
fi
fi
fi
build_cascade LOCAL_FLAGS
;;
Darwin*) echo -e "Detected macOS."
# check for homebrew
if ! [ -x "$(command -v brew)" ]; then
echo -e "Homebrew is ${RED}not installed${NC}."
echo -e "Homebrew is a package manager for macOS."
echo -e "We need it to check and configure dependencies."
echo -e "We can try to install it for you, or you can install it yourself by visiting"
echo -e "${WHITE}https://brew.sh/${NC}"
echo -e "Without homebrew, you will have to configure and build the cmake project manually."
echo -e "Would you like us to install homebrew for you?"
select yn in "Yes" "No"; do
case $yn in
Yes ) ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"; break;;
No ) exit 1;;
esac
done
fi
echo -e "Homebrew is ${GREEN}installed${NC}."
echo -e "Checking for required Homebrew packages..."
MISSING=()
check_homebrew cmake MISSING
check_homebrew flex MISSING
check_homebrew bison MISSING
check_homebrew python3 MISSING
check_homebrew ncurses MISSING
check_homebrew google-benchmark MISSING
check_homebrew gtest MISSING
check_homebrew verilator MISSING
MISSING_LIST=$(printf " %s" "${MISSING[@]:1}")
MISSING_LIST=${MISSING_LIST:1}
if [ ${#MISSING[@]} -gt 0 ]; then
if [ $SILENT -eq 1 ]; then
brew install ${MISSING_LIST};
else
echo "You are missing the following packages: ${MISSING_LIST}"
echo "Would you like us to install these packages using homebrew for you?"
select yn in "Yes" "No"; do
case $yn in
Yes ) brew install ${MISSING_LIST}; break;;
No ) echo "Please install these packages manually, then run this script again.";
exit 1;;
esac
done
fi
fi
if type xcode-select >&- && xpath=$( xcode-select --print-path ) && test -d "${xpath}" && test -x "${xpath}" ; then
echo -e "xcode is ${GREEN}installed${NC}."
else
echo -e "xcode is ${RED}not installed${NC}."
echo "xcode must be installed in order to build Cascade"
echo "Would you like us to install xcode for you?"
select yn in "Yes" "No"; do
case $yn in
Yes ) xcode-select --install; break;;
No ) echo "Please install xcode manually, then run this script again.";
exit 1;;
esac
done
fi
export CPP="g++ -E"
if [ ! -d "/usr/include" ]; then
if [ $SILENT -eq 1 ]; then
echo -e "Your /usr/include directly does not seem to be configured correctly (CI ignored)."
else
echo -e "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 -e "${WHITE}open ${HEADERS_INSTALL_PATH}${NC}"
exit 1
fi
fi
LOCAL_FLAGS="-DFLEX_EXECUTABLE=/usr/local/opt/flex/bin/flex -DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison -DFLEX_INCLUDE_DIR=/usr/local/opt/flex/include"
build_cascade "$LOCAL_FLAGS"
;;
*) echo -e "Sorry, your machine type ${unameOut} is not yet supported. Please setup the cmake project manually."
esac