forked from Leodau/sfml-vscode-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·302 lines (263 loc) · 5.79 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
290
291
292
293
294
295
296
297
298
299
300
301
302
#!/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() {
printf "\033[1;$1m$2 $3\033[0m\n"
}
build_success() {
printf '\n'
display_styled_symbol 32 "✔" "Succeeded!"
printf '\n'
}
launch() {
display_styled_symbol 32 " " "Launching bin/$BUILD/$NAME"
printf '\n'
}
build_success_launch() {
printf '\n'
display_styled_symbol 32 "✔" "Succeeded!"
launch
}
build_fail() {
printf '\n'
display_styled_symbol 31 "✘" "Failed!"
display_styled_symbol 31 " " "Review the compile errors above."
printf '\n'
printf '\033[0m'
exit 1
}
build_prod_error() {
printf '\n'
display_styled_symbol 31 "⭙" "Error: buildprod must be run on Release build."
printf '\033[0m'
exit 1
}
profiler_done() {
printf '\n'
display_styled_symbol 35 "⯌" "Profiler Completed: View $PROF_ANALYSIS_FILE for details"
printf '\n'
}
profiler_error() {
printf '\n'
display_styled_symbol 31 "⭙" "Error: Profiler must be run on Debug build."
printf '\033[0m'
exit 1
}
profiler_osx() {
display_styled_symbol 31 "⭙" "Error: Profiling (with gprof) is not supported on Mac OSX."
printf '\033[0m'
exit 1
}
cmd_buildrun() {
display_styled_symbol 33 "⬤" "Build & Run: $BUILD (target: $NAME)"
printf '\n'
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
}
cmd_build() {
display_styled_symbol 33 "⬤" "Build: $BUILD (target: $NAME)"
printf '\n'
BLD=$BUILD
if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
BLD=Release
fi
if $MAKE_EXEC BUILD=$BLD; then
build_success
else
build_fail
fi
}
cmd_rebuild() {
display_styled_symbol 33 "⬤" "Rebuild: $BUILD (target: $NAME)"
printf '\n'
BLD=$BUILD
if [[ $BUILD == 'Tests' && $1 != 'main' ]]; then
BLD=Release
fi
if $MAKE_EXEC BUILD=$BLD rebuild; then
build_success
else
build_fail
fi
}
cmd_run() {
display_styled_symbol 33 "⬤" "Run: $BUILD (target: $NAME)"
printf '\n'
launch
if [[ $BUILD == 'Tests' ]]; then
bin/Release/$NAME $OPTIONS
else
bin/$BUILD/$NAME $OPTIONS
fi
}
cmd_buildprod() {
display_styled_symbol 33 "⬤" "Production Build: $BUILD (target: $NAME)"
printf '\n'
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
}
cmd_profile() {
display_styled_symbol 33 "⬤" "Profile: $BUILD (target: $NAME)"
printf '\n'
if [[ $PLATFORM == 'osx' ]]; then
profiler_osx
elif [[ $BUILD == 'Debug' ]]; then
if $MAKE_EXEC BUILD=$BUILD; then
build_success_launch
printf '\033[0m'
bin/$BUILD/$NAME
printf '\033[0;34m'
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
printf "\nbuild.sh PATH=$PATH\n"
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=lib$target-d.dll
else
export NAME=lib$target.dll
fi
fi
else
if [[ $PLATFORM == 'osx' ]]; then
if [[ $target == 'main' ]]; then
export NAME=$cwd
if [[ $BUILD == 'Tests' ]]; then
NAME=tests_$NAME
fi
else
if [[ $BUILD == 'Debug' ]]; then
export NAME=lib$target-d.dylib
else
export NAME=lib$target.dylib
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=lib$target-d.so
else
export NAME=lib$target.so
fi
fi
fi
fi
if [[ $NO_SRC_TARGET != 1 ]]; then
export SRC_TARGET=$target
fi
if [[ ($CMD == 'run' || $CMD == 'profile') && $target != 'main' ]]; then
continue
fi
CHILD_CMD="cmd_$CMD $target"
if [[ $CMD == 'buildrun' && $target != 'main' ]]; then
CHILD_CMD="cmd_build"
fi
printf '\033[0;34m'
if $CHILD_CMD ; then
printf '\033[0m'
else
printf "\033[1;31mError: Command \"$CHILD_CMD\" not recognized.\033[0m"
exit 1
fi
RESULT=$?
if [[ $RESULT != 0 ]]; then
break
fi
done
printf '\033[0m\n'
exit 0