-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
289 lines (252 loc) · 5.19 KB
/
build.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
#!/bin/bash
CMD=$1
BUILD=$2
VSCODE=$3
OPTIONS=$4
cwd=${PWD##*/}
export GCC_COLORS="error=01;31:warning=01;33:note=01;36:locus=00;34"
#==============================================================================
# Function declarations
display_styled_symbol() {
tput setaf $1
tput bold
echo "$2 $3"
tput sgr0
}
build_success() {
echo
display_styled_symbol 2 "✔" "Succeeded!"
echo
}
launch() {
display_styled_symbol 2 " " "Launching bin/$BUILD/$NAME"
echo
}
build_success_launch() {
echo
display_styled_symbol 2 "✔" "Succeeded!"
launch
}
build_fail() {
echo
display_styled_symbol 1 "✘" "Failed!"
display_styled_symbol 1 " " "Review the compile errors above."
echo
tput sgr0
exit 1
}
build_prod_error() {
echo
display_styled_symbol 1 "⭙" "Error: buildprod must be run on Release build."
tput sgr0
exit 1
}
profiler_done() {
echo
display_styled_symbol 2 "⯌" "Profiler Completed: View $PROF_ANALYSIS_FILE for details"
echo
}
profiler_error() {
echo
display_styled_symbol 1 "⭙" "Error: Profiler must be run on Debug build."
tput sgr0
exit 1
}
profiler_osx() {
display_styled_symbol 1 "⭙" "Error: Profiling (with gprof) is not supported on Mac OSX."
tput sgr0
exit 1
}
buildrun() {
display_styled_symbol 3 "⬤" "Build & Run: $BUILD (target: $NAME)"
echo
BLD=$BUILD
if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
BLD=Release
fi
if $MAKE_EXEC BUILD=$BLD; then
build_success_launch
if [[ $BUILD == 'Tests' ]]; then
bin/Release/$NAME $OPTIONS
else
bin/$BUILD/$NAME $OPTIONS
fi
else
build_fail
fi
}
build() {
display_styled_symbol 3 "⬤" "Build: $BUILD (target: $NAME)"
echo
BLD=$BUILD
if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
BLD=Release
fi
if $MAKE_EXEC BUILD=$BLD; then
build_success
else
build_fail
fi
}
rebuild() {
display_styled_symbol 3 "⬤" "Rebuild: $BUILD (target: $NAME)"
echo
BLD=$BUILD
if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
BLD=Release
fi
if $MAKE_EXEC BUILD=$BLD rebuild; then
build_success
else
build_fail
fi
}
run() {
display_styled_symbol 3 "⬤" "Run: $BUILD (target: $NAME)"
echo
launch
if [[ $BUILD == 'Tests' ]]; then
bin/Release/$NAME $OPTIONS
else
bin/$BUILD/$NAME $OPTIONS
fi
}
buildprod() {
display_styled_symbol 3 "⬤" "Production Build: $BUILD (target: $NAME)"
echo
if [[ $BUILD == 'Release' ]]; then
RECIPE=buildprod
if [[ $1 != 'main' ]]; then
RECIPE=
fi
if $MAKE_EXEC BUILD=$BUILD $RECIPE; then
build_success
else
build_fail
fi
else
build_prod_error
fi
}
profile() {
display_styled_symbol 3 "⬤" "Profile: $BUILD (target: $NAME)"
echo
if [[ $PLATFORM == 'osx' ]]; then
profiler_osx
elif [[ $BUILD == 'Debug' ]]; then
if $MAKE_EXEC BUILD=$BUILD; then
build_success_launch
tput sgr0
bin/$BUILD/$NAME
tput setaf 4
gprof bin/Debug/$NAME gmon.out > $PROF_ANALYSIS_FILE 2> /dev/null
profiler_done
else
build_fail
fi
else
profiler_error
fi
}
#==============================================================================
# Environment
if [[ $CMD == '' ]]; then
CMD=buildprod
fi
if [[ $BUILD == '' ]]; then
BUILD=Release
fi
if [[ $OSTYPE == 'linux-gnu'* || $OSTYPE == 'cygwin'* ]]; then
if [[ $OSTYPE == 'linux-gnueabihf' ]]; then
export PLATFORM=rpi
else
export PLATFORM=linux
fi
elif [[ $OSTYPE == 'darwin'* ]]; then
export PLATFORM=osx
elif [[ $OSTYPE == 'msys' || $OSTYPE == 'win32' ]]; then
export PLATFORM=windows
fi
if [[ $VSCODE != 'vscode' ]]; then
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
if [[ $PLATFORM == 'windows' ]]; then
export PATH="/c/SFML-2.5.1/bin:/c/mingw32/bin:$PATH"
else
if [[ $PLATFORM == 'rpi' ]]; then
export PATH="/usr/local/gcc-8.1.0/bin:$PATH"
fi
fi
echo
echo build.sh PATH=$PATH
echo
fi
export MAKE_EXEC=make
if [[ $PLATFORM == 'windows' ]]; then
if [ $(type -P "mingw32-make.exe") ]; then
export MAKE_EXEC=mingw32-make.exe
elif [ $(type -P "make.exe") ]; then
export MAKE_EXEC=make.exe
fi
fi
if [[ $BUILD != "Release" && $BUILD != 'Debug' && $BUILD != 'Tests' ]]; then
BUILD=Release
fi
PROF_EXEC=gprof
PROF_ANALYSIS_FILE=profiler_analysis.stats
#==============================================================================
# Main script
if [[ $BUILD_TARGETS == '' ]]; then
BUILD_TARGETS=main
NO_SRC_TARGET=1
fi
for target in $BUILD_TARGETS; do
if [[ $PLATFORM == 'windows' ]]; then
if [[ $target == 'main' ]]; then
export NAME=$cwd.exe
if [[ $BUILD == 'Tests' ]]; then
NAME=tests_$NAME
fi
else
if [[ $BUILD == 'Debug' ]]; then
export NAME=$target-d.dll
else
export NAME=$target.dll
fi
fi
else
if [[ $target == 'main' ]]; then
export NAME=$cwd
if [[ $BUILD == 'Tests' ]]; then
NAME=tests_$NAME
fi
else
if [[ $BUILD == 'Debug' ]]; then
export NAME=$target-d.so
else
export NAME=$target.so
fi
fi
fi
if [[ $NO_SRC_TARGET != 1 ]]; then
export SRC_TARGET=$target
fi
CHILD_CMD="$CMD $target"
if [[ $CMD == 'buildrun' && $target != 'main' ]]; then
CHILD_CMD=build
fi
tput setaf 4
if $CHILD_CMD ; then
tput sgr0
else
tput setaf 1
tput bold
echo $dec Error: Command \"$CHILD_CMD\" not recognized. $dec
tput sgr0
exit 1
fi
RESULT=$?
if [[ $RESULT != 0 ]]; then
break
fi
done
exit 0