-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildProject.sh
executable file
·345 lines (315 loc) · 10.4 KB
/
buildProject.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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/bin/bash
# Path: buildProject.sh
# Author : Albert VALENTIN - OnsagerHe
ROOT_DIR=$PWD
_start=1
_end=100
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color
BOLD=$(tput bold)
REGULAR=$(tput sgr0)
BLINK=$(tput blink)
END='\e[27m'
CYAN='\033[0;36m'
declare -i MAKE=0
trap "echo ' Trapped Ctrl-C'" SIGINT
function ProgressBar {
let _progress=(${1}*100/${2}*100)/100
let _done=(${_progress}*4)/10
let _left=40-$_done
_fill=$(printf "%${_done}s")
_empty=$(printf "%${_left}s")
printf "\rProgress : [${_fill// /#}${_empty// /-}] ${_progress}%%"
}
function removedBin {
if [[ -f ${ROOT_DIR}/arcade ]]
then
rm -f ${ROOT_DIR}/arcade
else
echo -e "${RED}arcade binary doesn't exist${NC}"
echo -e "${RED}${BOLD}Did you execute ./buildProject ?${NC}${REGULAR}"
fi
rm -f ${ROOT_DIR}/*.bak || true
rm -f ${ROOT_DIR}/lib/*.so || true
}
function removedBuild {
if [[ -d ${ROOT_DIR}/build ]]
then
rm -rf ${ROOT_DIR}/build
else
echo -e "${RED}Build folder doesn't exist${NC}"
fi
}
function usage {
echo -e "${CYAN}${BOLD}Usage:${NC}${REGULAR}"
echo -e "${GREEN} --- buildProject.sh${NC}"
echo -e "${GREEN} --- buildProject.sh --help || -h${NC}"
echo -e "${GREEN} --- buildProject.sh --documentation || -d${NC}"
echo -e "${GREEN} --- buildProject.sh --clean || -c${NC}"
echo -e "${GREEN} --- buildProject.sh --version || -v${NC}"
echo -e "${GREEN} --- buildProject.sh --moulinette || -m${NC}"
}
function mandatoryFunction {
arr=("$@")
if [[ ${arr} =~ "arcade_ncurses.so" ]]
then
echo -e "${RED}${BOLD}[-]${NC} ./lib/arcade_ncurses.so folder not found"
else
echo -e "${GREEN}${BOLD}[+]${NC} ./lib/arcade_ncurses.so folder found"
fi
if [[ ${arr} =~ "arcade_sdl2.so" ]]
then
echo -e "${RED}${BOLD}[-]${NC} ./lib/arcade_sdl2.so folder not found"
else
echo -e "${GREEN}${BOLD}[+]${NC} ./lib/arcade_sdl2.so folder found"
fi
}
function lenCounterGraphical {
name=$1[@]
counter=$2
notFound=("${!name}")
if [ $counter -lt 3 ]
then
echo -e "${RED}${BOLD}[-]${NC} You must have at least 3 libraries"
echo -e "${RED}${BOLD}[-]${NC} You have only $counter libraries"
echo -e "${RED}${BOLD}[-]${NC} Choose another graphic library in this list :"
echo -e "${RED}${BOLD}[-]${NC} ${notFound[@]}"
exit 1
fi
notFound=""
}
function lenCounterGame {
name=$1[@]
counter=$2
notFountGame=("${!name}")
if [ $counter -lt 2 ]
then
echo -e "${RED}${BOLD}[-]${NC} You must have at least 2 libraries game."
echo -e "${RED}${BOLD}[-]${NC} You have only $counter libraries game."
echo -e "${RED}${BOLD}[-]${NC} Choose another game library in this list :"
echo -e "${RED}${BOLD}[-]${NC} ${notFountGame[@]}"
exit 1
fi
}
function checkLibGame {
notFountGame=()
array=(arcade_nibbler.so arcade_pacman.so arcade_qix.so arcade_centipede.so arcade_solarfox.so)
declare -i counter=0
declare -i count=0
declare -i size=$(( ${#array[@]} ))
echo -e "${CYAN}${BOLD}--- Checking libraries game ---${NC}${REGULAR}"
echo
if [[ -d ./lib ]]
then
for i in "${array[@]}"
do
if [[ -f ${ROOT_DIR}/lib/$i ]]
then
counter+=1
else
notFountGame+=($i)
fi
count+=1
sleep 0.2
ProgressBar ${count} $size
done
else
echo -e "${RED}${BOLD}Library files game not found.${NC}"
echo -e "${RED}${BOLD}Please, run the script from the project root directory${NC}"
exit 1
fi
echo
lenCounterGame notFountGame "${counter}"
echo -e "${GREEN}${BOLD}[+]${NC} ${counter}/$size libraries game found."
}
function debugProgram {
if [ -f ${ROOT_DIR}/CMakeLists.txt ]
then
mkdir -p ${ROOT_DIR}/build/
cd ${ROOT_DIR}/build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Wall -std=c++11 -Werror -g"
-DCMAKE_INSTALL_PREFIX=${ROOT_DIR}/build -G "Unix Makefiles"
make -j4
else
echo -e "${RED}${BOLD}[-]${NC} CMakeLists.txt only for debug mode"
exit 1
fi
}
function checkLibGraphic {
notFound=()
array=(arcade_ncurses.so arcade_sdl2.so arcade_ndk++.so arcade_aalib.so arcade_libcaca.so
arcade_allegro5.so arcade_xlib.so arcade_gtk+.so arcade_sfml.so arcade_irrlicht.so
arcade_opengl.so arcade_vulkan.so arcade_qt5.so)
declare -i counter=0
declare -i count=0
declare -i size=$(( ${#array[@]} ))
echo -e "${CYAN}${BOLD}--- Checking libraries graphical ---${NC}${REGULAR}"
echo
if [[ -d ./lib ]]
then
for i in "${array[@]}"
do
if [[ -f ${ROOT_DIR}/lib/$i ]]
then
counter+=1
else
notFound+=($i)
fi
count+=1
sleep 0.2
ProgressBar ${count} $size
done
else
echo -e "${RED}${BOLD}Library files graphical not found.${NC}"
echo -e "${RED}${BOLD}Please, run the script from the project root directory${NC}"
exit 1
fi
echo
lenCounterGraphical notFound "${counter}"
mandatoryFunction "${notFound[@]}"
echo -e "${GREEN}${BOLD}[+]${NC} ${counter}/$size libraries graphical found."
}
function checkCompil {
echo -e "${CYAN}${BOLD}--- Checking compilation ---${NC}${REGULAR}"
if [ -f ./CMakeLists.txt ]
then
echo -e "${GREEN}${BOLD}[+]${NC} CMakeLists.txt found"
MAKE=0
elif [ -f ./Makefile ]
then
echo -e "${GREEN}${BOLD}[+]${NC} Makefile found"
MAKE=1
else
echo -e "${RED}${BOLD}[-]${NC} CMakeLists.txt or Makefile not found"
echo -e "${RED}${BOLD}Please, run the script from the project root directory${NC}"
exit 1
fi
}
function doCompilation {
checkCompil
mkdir -p build
if [ $MAKE -eq 0 ]
then
echo -e "${CYAN}${BOLD}--- Compilation with CMake ---${NC}${REGULAR}"
echo
if [[ -d ./build ]]
then
cd ./build
cmake ..
make
else
echo -e "${RED}${BOLD}Build directory not found${NC}"
echo -e "${RED}${BOLD}Please, run the script from the project root directory${NC}"
exit 1
fi
else
echo -e "${CYAN}${BOLD}--- Compilation with Makefile ---${NC}${REGULAR}"
echo
make re
fi
}
function checkArgument {
${ROOT_DIR}/arcade > /dev/null 2>&1
returnValue=$?
defaultValue=84
echo
echo -e "${CYAN}${BOLD}--- Checking arguments ---${NC}${REGULAR}"
if [[ $returnValue -eq $defaultValue ]]
then
echo -e "${GREEN}${BOLD}[+]${NC} Arcade with no arguments"
else
echo -e "${RED}${BOLD}[-]${NC} Arcade with no arguments"
fi
${ROOT_DIR}/arcade ${ROOT_DIR}/lib/arcade_libcaca.so > /dev/null 2>&1
returnValue=$?
if [[ $returnValue -eq $defaultValue ]]
then
echo -e "${GREEN}${BOLD}[+]${NC} Arcade with wrong arguments"
else
echo -e "${RED}${BOLD}[-]${NC} Arcade with wrong arguments"
fi
${ROOT_DIR}/arcade ${ROOT_DIR}/lib/arcade_sfml.so Hello > /dev/null 2>&1
returnValue=$?
if [[ $returnValue -eq $defaultValue ]]
then
echo -e "${GREEN}${BOLD}[+]${NC} Arcade length arguments different than 1"
else
echo -e "${RED}${BOLD}[-]${NC} Arcade length arguments different than 1"
fi
}
function moulinette {
echo -e "${CYAN}${BOLD}--- {Moulinette} ---${NC}${REGULAR}"
checkCompil
if [ $MAKE -eq 0 ]
then
mkdir ./build/ && cd ./build/
cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release
cmake --build .
cd ..
else
make re
fi
checkArgument
checkLibGraphic
checkLibGame
removedBin
removedBuild
}
function createDocumentation {
if [ -f Doxyfile ]
then
doxygen Doxyfile
make -C ./doc/latex
mv ./doc/latex/refman.pdf ./doc/documenation.pdf
rm -rf ./doc/latex
rm -rf ./doc/html
else
echo -e "${RED}${BOLD}Doxyfile not found${NC}"
echo -e "${RED}${BOLD}Please, run the script from the project root directory${NC}"
exit 1
fi
}
if [ $# -eq 0 ]
then
doCompilation
elif [ $# -eq 1 ]
then
if [ $1 == "--help" ] || [ $1 == "-h" ]
then
usage
elif [ $1 == "--clean" ] || [ $1 == "-c" ]
then
removedBuild
removedBin
elif [ $1 == "--documentation" ] || [ $1 == "-d" ]
then
echo -e "${CYAN}${BOLD}--- {Documentation} ---${NC}${REGULAR}"
createDocumentation
elif [ $1 == "--version" ] || [ $1 == "-v" ]
then
echo -e "${CYAN}${BOLD}--- {Version} ---${NC}${REGULAR}"
echo -e " arcade-build-script v0.1.5"
elif [ $1 == "--moulinette" ] || [ $1 == "-m" ]
then
moulinette
elif [ $1 == "--update" ] || [ $1 == "-u" ]
then
echo -e "${CYAN}${BOLD}--- {Update} ---${NC}${REGULAR}"
git clone [email protected]:OnsagerHe/MoulinetteArcade.git
mv buildProject.sh buildProject_old.sh
cp -f MoulinetteArcade/buildProject.sh .
rm -rf MoulinetteArcade
elif [ $1 == "--debug" ] || [ $1 == "-g" ]
then
echo -e "${CYAN}${BOLD}--- {Debug} ---${NC}${REGULAR}"
debugProgram
else
echo -e "${RED}${BOLD}Invalid argument${NC}${REGULAR}"
usage
fi
else
echo -e "${RED}${BOLD}Invalid argument${NC}${REGULAR}"
usage
fi
# mainProgram