-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·81 lines (67 loc) · 2.48 KB
/
build
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
#!/bin/bash
# Tetris written in C for GNU/Linux terminal
# Copyright (C) 2022 efindus
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
available_actions=( "help" "run-debug" "run-release" "debug" "release" )
action_description=( "prints this message" "\033[35m[DEFAULT]\033[39m compiles and runs the application with debug flags" "compiles and runs the application with optimization flags" "compiles the application with debug flags" "compiles the application with optimization flags" )
array_contains () {
local array="$1[@]"
local seeking=$2
local res=1
for element in "${!array}"; do
if [[ $element == "$seeking" ]]; then
res=0
break
fi
done
return $res
}
if ! [[ -v 1 ]]; then
action="run-debug"
else
action=$1
fi
if ! array_contains "available_actions" "$action"; then
echo -e "\033[31mInvalid option! Try 'help' to get an overview of the options.\033[39m"
exit
fi
if [[ $action == "help" ]]; then
i=0
echo -e "\033[35mefmake\033[36m - yet another make-like utility written in bash\033[32m\n\nOptions:\033[39m"
for element in "${available_actions[@]}"; do
echo -e "\033[36m$element\033[39m - ${action_description[$i]}"
let i++
done
exit
fi
echo -e "\033[33mBUILDING APPLICATION...\033[39m"
if [[ $action == "release" || $action == "run-release" ]]; then
flags="-O2 -pthread -lm"
build_dir="bin/release"
elif [[ $action == "debug" || $action == "run-debug" ]]; then
flags="-Wall -Wextra -Wshadow -Wconversion -Wno-sign-conversion -Wfloat-equal -fsanitize=address,undefined -D_GLIBCXX_DEBUG -ggdb3"
build_dir="bin/debug"
fi
mkdir -p $build_dir
clang tetris.c -o $build_dir/tetris $flags
if [[ $? == 1 ]]; then
echo -e "\033[31mBUILD FAILED!\033[39m"
exit
fi
echo -e "\033[32mBUILD SUCCESSFUL!\033[39m"
if [[ $action != "run-release" && $action != "run-debug" ]]; then
exit
fi
echo -e "\033[35mRunning the application...\033[39m"
./$build_dir/tetris