-
Notifications
You must be signed in to change notification settings - Fork 13
/
make.sh
executable file
·506 lines (403 loc) · 13.6 KB
/
make.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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
#!/usr/bin/env bash
# TODO(Jesse)(build): Revisit this blog and see if there are some tidbits we can use.
# http://ptspts.blogspot.com/2013/12/how-to-make-smaller-c-and-c-binaries.html
# SANITIZER="-fsanitize=undefined"
# SANITIZER="-fsanitize=address"
BUILD_EVERYTHING=0
RunPoof=0
BuildExecutables=0
BuildExamples=0
BuildTests=0
BuildDebugOnlyTests=0
RunTests=0
stdlib_build_scripts='external/bonsai_stdlib/scripts'
source $stdlib_build_scripts/preamble.sh
source $stdlib_build_scripts/setup_for_cxx.sh
OPTIMIZATION_LEVEL=""
EMCC=0
# NOTE(Jesse): Can't do this cause it fucks with the paths poof outputs
# ROOT="$(pwd)"
ROOT="."
SRC="$ROOT/src"
INCLUDE="$ROOT/external"
EXAMPLES="$ROOT/examples"
TESTS="$SRC/tests"
BIN="$ROOT/bin"
BIN_TEST="$BIN/tests"
BIN_GAME_LIBS="$BIN/game_libs"
BONSAI_INTERNAL='-D BONSAI_INTERNAL=1'
# $EXAMPLES/tile_gen
EXAMPLES_TO_BUILD=""
BUNDLED_EXAMPLES="
$EXAMPLES/blank_project
$EXAMPLES/turn_based
$EXAMPLES/the_wanderer
$EXAMPLES/terrain_gen
$EXAMPLES/transparency
$EXAMPLES/tools/voxel_synthesis_rule_baker
$EXAMPLES/project_and_level_picker
"
EXECUTABLES_TO_BUILD="
$SRC/game_loader.cpp
$SRC/font/ttf.cpp
"
# $SRC/tools/asset_packer.cpp
# $SRC/net/server.cpp
# TODO(Jesse, tags: tests, release): The allocation tests crash in release mode because of some
# ultra-jank-tastic segfault recovery code. Find another less janky way?
DEBUG_TESTS_TO_BUILD="
$TESTS/allocation.cpp
"
function BuildExecutables
{
echo ""
ColorizeTitle "Executables"
for executable in $EXECUTABLES_TO_BUILD; do
SetOutputBinaryPathBasename "$executable" "$BIN"
echo -e "$Building $executable"
clang++ \
$SANITIZER \
$OPTIMIZATION_LEVEL \
$CXX_OPTIONS \
$BONSAI_INTERNAL \
$PLATFORM_CXX_OPTIONS \
$PLATFORM_LINKER_OPTIONS \
$PLATFORM_DEFINES \
$PLATFORM_INCLUDE_DIRS \
-I "$ROOT" \
-I "$SRC" \
-I "$INCLUDE" \
-o "$output_basename""$PLATFORM_EXE_EXTENSION" \
$executable &
TrackPid "$executable" $!
done
}
function BuildDebugOnlyTests
{
echo ""
ColorizeTitle "Debug Tests"
for executable in $DEBUG_TESTS_TO_BUILD; do
SetOutputBinaryPathBasename "$executable" "$BIN_TEST"
echo -e "$Building $executable"
clang++ \
$CXX_OPTIONS \
$BONSAI_INTERNAL \
$PLATFORM_CXX_OPTIONS \
$PLATFORM_LINKER_OPTIONS \
$PLATFORM_DEFINES \
$PLATFORM_INCLUDE_DIRS \
-I "$ROOT" \
-I "$SRC" \
-I "$INCLUDE" \
-o "$output_basename""$PLATFORM_EXE_EXTENSION" \
$executable &
TrackPid "$executable" $!
done
}
function BuildTests
{
echo ""
ColorizeTitle "Tests"
for executable in $TESTS_TO_BUILD; do
SetOutputBinaryPathBasename "$executable" "$BIN_TEST"
echo -e "$Building $executable"
clang++ \
$OPTIMIZATION_LEVEL \
$CXX_OPTIONS \
$BONSAI_INTERNAL \
$PLATFORM_CXX_OPTIONS \
$PLATFORM_LINKER_OPTIONS \
$PLATFORM_DEFINES \
$PLATFORM_INCLUDE_DIRS \
-I "$ROOT" \
-I "$SRC" \
-I "$INCLUDE" \
-o "$output_basename""$PLATFORM_EXE_EXTENSION" \
$executable &
TrackPid "$executable" $!
done
}
function BuildExamples
{
echo ""
ColorizeTitle "Examples"
for executable in $EXAMPLES_TO_BUILD; do
echo -e "$Building $executable"
SetOutputBinaryPathBasename "$executable" "$BIN_GAME_LIBS"
clang++ \
$SANITIZER \
-D BONSAI_DEBUG_SYSTEM_API=1 \
$OPTIMIZATION_LEVEL \
$CXX_OPTIONS \
$BONSAI_INTERNAL \
$PLATFORM_CXX_OPTIONS \
$PLATFORM_LINKER_OPTIONS \
$PLATFORM_DEFINES \
$PLATFORM_INCLUDE_DIRS \
$SHARED_LIBRARY_FLAGS \
-I "$ROOT" \
-I "$INCLUDE" \
-I "$SRC" \
-I "$executable" \
-o "$output_basename" \
"$executable/game.cpp" && \
mv "$output_basename" "$output_basename""_loadable""$PLATFORM_LIB_EXTENSION" &
TrackPid "$executable" $!
done
}
function BuildWithClang
{
which clang++ > /dev/null
[ $? -ne 0 ] && echo -e "Please install clang++" && exit 1
echo -e ""
echo -e "$Delimeter"
[[ $BuildExecutables == 1 || $BUILD_EVERYTHING == 1 ]] && BuildExecutables
[[ $BuildDebugOnlyTests == 1 || $BUILD_EVERYTHING == 1 ]] && BuildDebugOnlyTests
[[ $BuildTests == 1 || $BUILD_EVERYTHING == 1 ]] && BuildTests
[[ $BuildExamples == 1 || $BUILD_EVERYTHING == 1 ]] && BuildExamples
echo -e ""
echo -e "$Delimeter"
echo -e ""
ColorizeTitle "Complete"
WaitForTrackedPids
sync
echo -e ""
echo -e "$Delimeter"
echo -e ""
echo -e ""
}
function BuildWithEMCC {
which emcc > /dev/null 2&> 1
[ $? -ne 0 ] && echo -e "$Error Please install emcc" && exit 1
emcc \
-s WASM=1 \
-s LLD_REPORT_UNDEFINED \
-s FULL_ES3=1 \
-s ALLOW_MEMORY_GROWTH=1 \
-s ASSERTIONS=1 \
-s DEMANGLE_SUPPORT=1 \
-std=c++17 \
-Wno-c99-designator \
-Wno-reorder-init-list \
-ferror-limit=2000 \
-fno-exceptions \
-O2 \
-g4 \
--source-map-base / \
--emrun \
-msse \
-msimd128 \
-DEMCC=1 \
-DWASM=1 \
$BONSAI_INTERNAL \
-I src \
-I examples \
src/game_loader.cpp \
-o bin/wasm/platform.html
# --embed-file shaders \
# --embed-file models \
}
if [ ! -d "$BIN" ]; then
mkdir "$BIN"
fi
if [ ! -d "$BIN/wasm" ]; then
mkdir "$BIN/wasm"
fi
if [ ! -d "$BIN_GAME_LIBS" ]; then
mkdir "$BIN_GAME_LIBS"
fi
if [ ! -d "$BIN_TEST" ]; then
mkdir "$BIN_TEST"
fi
if [ ! -d "$BIN_TEST" ]; then
mkdir "$BIN_TEST"
fi
function RunEntireBuild {
if [ $RunPoof == 1 ]; then
RunPoof
[ $? -ne 0 ] && exit 1
fi
if [ $EMCC == 1 ]; then
BuildWithEMCC
[ $? -ne 0 ] && exit 1
else
BuildWithClang
[ $? -ne 0 ] && exit 1
fi
if [ $RunTests == 1 ]; then
$stdlib_build_scripts/run_tests.sh
[ $? -ne 0 ] && exit 1
fi
}
# --log-level LogLevel_Debug -I src/ -I external/ -I "C:/Program Files/LLVM/lib/clang/11.0.0/include" -I "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/include" -I "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/atlmfc/include" -I "C:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/ucrt" -I "C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/shared" -I "C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/um" -I "C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/winrt" -D BONSAI_WIN32 -D BONSAI_INTERNAL -o generated src/game_loader.cpp
function RunPoofHelper {
# -D _M_CEE_PURE \
# -I "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/include" \
# -I "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/atlmfc/include" \
# -I "C:/Program Files/LLVM/lib/clang/11.0.0/include" \
# -I "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/include" \
# -I "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.28.29333/atlmfc/include" \
# -I "C:/Program Files (x86)/Windows Kits/10/Include/10.0.18362.0/ucrt" \
# -I "C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/shared" \
# -I "C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/um" \
# -I "C:/Program Files (x86)/Windows Kits/10/include/10.0.18362.0/winrt" \
# --log-level LogLevel_Debug \
poof \
$COLOR_FLAG \
-D POOF_PREPROCESSOR \
-D BONSAI_PREPROCESSOR \
-I src/ \
-I external/ \
$PLATFORM_DEFINES \
$BONSAI_INTERNAL \
-o generated \
$1
}
function RunPoof
{
echo -e ""
echo -e "$Delimeter"
echo -e ""
ColorizeTitle "Poofing"
# [ -d src/generated ] && rm -Rf src/generated
# [ -d generated ] && rm -Rf generated
RunPoofHelper src/game_loader.cpp && echo -e "$Success poofed src/game_loader.cpp" &
TrackPid "" $!
# RunPoofHelper examples/turn_based/game.cpp && echo -e "$Success poofed examples/turn_based/game.cpp" &
# TrackPid "" $!
# RunPoofHelper examples/terrain_gen/game.cpp && echo -e "$Success poofed examples/terrain_gen/game.cpp" &
# TrackPid "" $!
# RunPoofHelper examples/the_wanderer/game.cpp && echo -e "$Success poofed examples/the_wanderer/game.cpp" &
# TrackPid "" $!
# RunPoofHelper examples/tools/voxel_synthesis_rule_baker/game.cpp && echo -e "$Success poofed examples/tools/voxel_synthesis_rule_baker/game.cpp" &
# TrackPid "" $!
# RunPoofHelper src/tools/asset_packer.cpp && echo -e "$Success poofed src/tools/asset_packer.cpp" &
# TrackPid "" $!
WaitForTrackedPids
sync
[ -d tmp ] && rmdir tmp
}
TESTS_TO_BUILD="
$TESTS/chunk.cpp
$TESTS/ui_command_buffer.cpp
$TESTS/m4.cpp
$TESTS/colladaloader.cpp
$TESTS/test_bitmap.cpp
$TESTS/bonsai_string.cpp
$TESTS/objloader.cpp
$TESTS/callgraph.cpp
$TESTS/heap_allocation.cpp
$TESTS/rng.cpp
$TESTS/file.cpp
$TESTS/sort.cpp
$TESTS/containers/block_array.cpp
"
BuildAll() {
BuildExamples=1
BuildExecutables=1
BuildTests=1
# NOTE(Jesse): These only build on linux. I'm honestly not sure if it's
# worth getting them to build on Windows
if [ $Platform == "Linux" ]; then
BuildDebugOnlyTests=1
fi
for ex in $BUNDLED_EXAMPLES; do
EXAMPLES_TO_BUILD="$EXAMPLES_TO_BUILD $ex"
done
}
if [ $# -eq 0 ]; then
OPTIMIZATION_LEVEL="-O2"
BuildAll
fi
BundleRelease=0
while (( "$#" )); do
CliArg=$1
echo $CliArg
case $CliArg in
"BuildAll")
BuildAll
;;
"BuildExecutables")
BuildExecutables=1
;;
"BuildDebugSystem")
echo "BuildDebugSystem has been deprecated and will be removed in a future version."
;;
"BuildBundledExamples")
BuildExamples=1
for ex in $BUNDLED_EXAMPLES; do
EXAMPLES_TO_BUILD="$EXAMPLES_TO_BUILD $ex"
done
;;
"BuildTests")
BuildTests=1
;;
"BuildDebugOnlyTests")
BuildDebugOnlyTests=1
;;
"RunTests")
RunTests=1
;;
"RunPoof")
RunPoof=1
;;
"BuildWithEMCC")
BuildWithEMCC=1
;;
"BuildSingleExample")
BuildExamples=1
EXAMPLES_TO_BUILD="$EXAMPLES_TO_BUILD $2"
shift
;;
"BundleRelease")
BundleRelease=1
OPTIMIZATION_LEVEL="-O2"
BONSAI_INTERNAL="-D BONSAI_INTERNAL=0"
# BuildAll
;;
"-Od")
OPTIMIZATION_LEVEL="-Od"
;;
"-O0")
OPTIMIZATION_LEVEL="-O0"
;;
"-O1")
OPTIMIZATION_LEVEL="-O1"
;;
"-O2")
OPTIMIZATION_LEVEL="-O2"
;;
"-O3")
OPTIMIZATION_LEVEL="-O3"
;;
*)
echo "Unrecognized Build Option ($CliArg), exiting." && exit 1
;;
esac
shift
done
time RunEntireBuild
if [ $BundleRelease -eq 1 ]; then
echo -e ""
echo -e "$Delimeter"
echo -e ""
ColorizeTitle "Bundling"
tar -cz \
bin/game_loader$PLATFORM_EXE_EXTENSION \
bin/game_libs/blank_project_loadable$PLATFORM_LIB_EXTENSION \
bin/game_libs/turn_based_loadable$PLATFORM_LIB_EXTENSION \
bin/game_libs/the_wanderer_loadable$PLATFORM_LIB_EXTENSION \
bin/game_libs/terrain_gen_loadable$PLATFORM_LIB_EXTENSION \
bin/game_libs/transparency_loadable$PLATFORM_LIB_EXTENSION \
bin/game_libs/project_and_level_picker_loadable$PLATFORM_LIB_EXTENSION \
\
shaders/* \
external/bonsai_stdlib/shaders/* \
assets/* \
models/* \
brushes/* \
\
.root_marker \
settings.init \
texture_atlas_0.bmp > "$Platform""_x86_64_release.tar.gz"
fi