-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.sh
executable file
·156 lines (142 loc) · 2.37 KB
/
setup.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
#!/bin/bash
# Init checking
function print_options {
printf "Use:\n -m or --make: runs cmake from build folder.\n -b or --build: builds program.\n -e or --execute: executes target.\n -c or --clean: cleans build directory. If added as a second option the it will also clean the build directory before executing the action.\n"
}
if [[ $# > 2 ]]; then
printf "You cannot have that many options."
exit 1
elif [[ $# == 0 ]]; then
print_options
exit 1
fi
# Variables
BUILD_DIR="build"
TARGET_DIR="examples"
TARGET="game"
OPT1=$1
OPT2=$2
# Functions
function cmake_func {
if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi
cd $BUILD_DIR
cmake ..
}
function make_func {
if [ ! -d "$BUILD_DIR" ]; then
mkdir $BUILD_DIR
cd $BUILD_DIR
cmake ..
elif [ ! -f "$BUILD_DIR"/Makefile ]; then
cd $BUILD_DIR
cmake ..
else
cd $BUILD_DIR
fi
make
}
function exec_func {
if [ ! -d "$BUILD_DIR" ]; then
mkdir $BUILD_DIR
cd $BUILD_DIR
cmake ..
make
elif [ ! -f "$BUILD_DIR"/Makefile ]; then
cd $BUILD_DIR
cmake ..
make
elif [ ! -f "$BUILD_DIR"/"$TARGET_DIR"/"$TARGET" ]; then
cd $BUILD_DIR
make
else
cd $BUILD_DIR
fi
cd $TARGET_DIR
./"$TARGET"
}
function clean_func {
case $1 in
-c|--clean)
if [ -d "$BUILD_DIR/$TARGET_DIR" ]; then
rm -rf "$BUILD_DIR/$TARGET_DIR"
fi
shift
;;
-ca|--clean-all)
if [ -d "$BUILD_DIR" ]; then
rm -rf $BUILD_DIR
fi
shift
;;
*)
printf "Invalid clean option.\n"
print_options
exit 1
;;
esac
}
# Args evalutation
case $OPT1 in
-m|--make)
MODE=CMAKE # Invoke cmake
shift
;;
-b|--build)
MODE=MAKE # Invoke make
shift
;;
-e|--execute)
MODE=EXEC # Execute program
shift
;;
-be)
MODE=ME # Make and Exec
shift
;;
-c|--clean|-ca|--clean-all)
MODE=CLEAN # Clean build directory
shift
;;
*)
printf "Invalid option.\n"
print_options
exit 1
;;
esac
if [[ -n $OPT2 ]] && [[ $OPT1 != $OPT2 ]]; then
case $OPT2 in
-c|--clean)
clean_func
shift
;;
*)
printf "Invalid second option. Ignoring...\n"
;;
esac
fi
case $MODE in
CMAKE)
cmake_func
shift
;;
MAKE)
make_func
shift
;;
EXEC)
exec_func
shift
;;
ME)
make_func
cd ..
exec_func
shift
;;
CLEAN)
clean_func $OPT1
shift
;;
esac