summaryrefslogtreecommitdiff
path: root/code/build.sh
blob: e3aa269f37cec09cd3027452d707f140a7bb02eb (plain) (blame)
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
#!/bin/sh

ThisDir="$(dirname "$(readlink -f "$0")")"
cd "$ThisDir"

mkdir -p ../build

Mode="$1"
if [ "$Mode" != "release" ]
then
 Mode="debug" 
fi
>&2 printf 'Mode: %s\n' "$Mode"

CompilerFlags="
-fdiagnostics-absolute-paths
"
  
WarningFlags="
-Wall
-Wextra
-Wno-unused-variable
-Wno-unused-but-set-variable
-Wno-write-strings
-Wno-pointer-arith
-Wno-unused-parameter
-Wno-unused-function
-Wno-null-dereference
-Wno-missing-braces
"

WasmCompilerFlags="
-nostdlib
-mbulk-memory
--target=wasm32
"
WasmLinkerFlags="
-Wl,--allow-undefined
-Wl,--no-entry
-Wl,--export-all
-Wl,--export=LogMessage
-Wl,-z,stack-size=$((64 * 1024))
"

if [ "$Mode" = "debug" ]
then
 CompilerFlags="$CompilerFlags
 -O0
 -g -g3 -ggdb
 "
elif [ "$Mode" = "release" ]
then
 CompilerFlags="$CompilerFlags
 -O3
 "
 WasmCompilerFlags="$WasmCompilerFlags
 -flto
 "
 WasmLinkerFlags="$WasmLinkerFlags
 -Wl,--lto-O3
 "
fi

printf 'game.cpp\n'
clang \
    $CompilerFlags \
    $WasmCompilerFlags $WasmLinkerFlags \
    $WarningFlags \
    -o ../build/game.wasm \
    game.cpp
printf 'index.html platform.js favicon.ico\n'
ln -f index.html platform.js ../build
cp ../data/favicon.ico ../build

if [ ! -s "../build/ws" ]
then
 cd ../ws
 printf 'ws.c\n'
 clang \
  -I./libs/wsServer/include -I./libs/wsServer/src \
  $CompilerFlags \
  $WarningFlags \
  -o ../build/ws \
  ws.c
fi

if [ -s "../build/font.c" ]
then
 printf 'font.ttf\n'
 xxd -i -n "data_font_ttf" ../data/font.ttf > ../build/font.c
fi

printf '%s\n' "update" | websocat 'ws://localhost:1234/'