refactor model things
[carveJwlIkooP6JGAAIwe30JlM.git] / build.sh
1 #!/bin/bash
2 #
3 # Copyright (C) 2021-2022 Mt.ZERO Software, Harry Godden - All Rights Reserved
4 #
5 # Main cross-compiling build script for Skate Rift
6 # Supports Linux and Windows building from a Linux Host
7 #
8 # vg must be "ln -s"'d into this src folder as the only dependency
9 #
10 # Compiler Presets
11 # ==============================================================================
12
13 _linux_compiler="clang -std=c99 -D_REENTRANT"
14 _linux_linkgraphics="-lGL -lglfw3 -lX11 -lXxf86vm -lXrandr -lm -pthread -lXi -ldl"
15 _linux_asan="-fsanitize=address"
16 _linux_linksteam="-lsteam_api"
17 _linux_folder="bin/linux"
18 _linux_server_folder="bin/linux_server"
19
20 _windows_compiler="i686-w64-mingw32-gcc"
21 _windows_linkgraphics="-lglfw3dll -lopengl32 -lm -pthread -static -mwindows"
22 _windows_asan=""
23 _windows_linksteam="vg/dep/steam/steam_api.dll"
24 _windows_folder="bin/win32"
25
26 _options_debugmode="-O0 -ggdb3 -fno-omit-frame-pointer -rdynamic"
27 _options_release="-O3 -DVG_RELEASE"
28
29 # Compiler lines
30 # ==============================================================================
31
32 _warnings="-Wall -Wno-unused-function -Wno-unused-variable -Wno-unused-command-line-argument -Wno-unused-but-set-variable"
33 _include="-I. -I./vg/dep -I./vg/src"
34 _library="-L. -L./vg/dep/glfw -L./vg/dep/steam"
35 _epilogue="-Wl,-rpath=./"
36 _ext=""
37
38 # Compile scripts
39 # ==============================================================================
40
41 compile_miniaudio(){
42
43 temp_options=$_options
44 _options="-O3"
45
46 _link="-lm"
47 _folder="."
48 _src="-c vg/dep/dr_soft/miniaudio_impl.c"
49 _dst="vg/dep/dr_soft/miniaudio_$1"
50 _ext=".o"
51 compile_x
52
53 _options=$temp_options
54 }
55
56 # Again, these are not cross platform currently
57 # TODO
58 run_game(){
59 cd $_linux_folder
60 ./skaterift --samples=4
61 cd ./../
62 }
63
64 run_server(){
65 cd $_linux_server_folder
66 ./skaterift_server
67 cd ./../
68 }
69
70 delay_run_game(){
71 sleep 2
72 run_game
73 }
74
75 link_content(){
76 unlink $1/textures
77 unlink $1/models
78 unlink $1/sound
79
80 ln -srf bin/content/textures $1/textures
81 ln -srf bin/content/models $1/models
82 ln -srf bin/content/sound $1/sound
83 }
84
85 TIMESTAMP=`date +%Y-%m-%d_%H-%M-%S`
86
87 vg_command(){
88 case "$1" in
89 release)
90 _linux_options=$_options_release
91 _windows_options=$_options_release
92 ;;
93 debug)
94 _linux_options="$_linux_asan $_options_debugmode"
95 _windows_options="$_windows_asan $_options_debugmode"
96 ;;
97 ltools)
98 _compiler=$_linux_compiler
99 _options=$_linux_options
100 _folder=$_linux_folder
101 _ext=""
102 vg_compile_tools
103
104 ;;
105 game)
106 titleit "Creating Linux build"
107 mkdir -p $_linux_folder/cfg
108
109 # Dependencies
110 cp vg/dep/steam/libsteam_api.so $_linux_folder
111 link_content $_linux_folder
112
113 _compiler=$_linux_compiler
114 _options=$_linux_options
115
116 compile_miniaudio linux
117
118 # Game tools
119 _folder=$_linux_folder
120 _ext=""
121 vg_compile_tools
122
123 # Main build
124 _link="$_linux_linkgraphics $_linux_linksteam"
125 _src="main.c vg/dep/glad/glad.c vg/dep/dr_soft/miniaudio_linux.o"
126 _dst="skaterift"
127 compile_x
128 ;;
129 game_win)
130 titleit "Creating Windows build"
131 mkdir -p $_windows_folder/cfg
132
133 # Dependencies
134 cp vg/dep/steam/steam_api.dll $_windows_folder
135 link_content $_windows_folder
136
137 _compiler=$_windows_compiler
138 _options=$_windows_options
139
140 compile_miniaudio windows
141
142 # Game tools
143 _ext=".exe"
144 _folder=$_windows_folder
145 vg_compile_tools
146
147 # Main build
148 _link="$_windows_linkgraphics $_windows_linksteam"
149 _src="main.c vg/dep/glad/glad.c vg/dep/dr_soft/miniaudio_windows.o"
150 _dst="skaterift"
151 compile_x
152 ;;
153 server)
154 titleit "Creating Server build"
155 mkdir -p $_linux_server_folder/cfg
156
157 # Dependencies
158 cp vg/dep/steam/steamclient.so bin/linux_server/
159 cp vg/dep/steam/libsteam_api.so bin/linux_server/
160 cp vg/dep/steam/libsdkencryptedappticket.so bin/linux_server/
161
162 _compiler=$_linux_compiler
163 _options=$_linux_options
164 _link="-pthread -lm -lsdkencryptedappticket $_linux_linksteam"
165 _src="server.c"
166 _folder=$_linux_server_folder
167 _dst="skaterift_server"
168 _ext=""
169
170 compile_x
171 ;;
172 testaa)
173 titleit "Dev"
174 mkdir -p bin/aatest/cfg
175
176 _compiler=$_linux_compiler
177 _options=$_linux_options
178 _link="-lm"
179 _src="testaa.c"
180 _folder=bin/aatest
181 _dst="testaa"
182 _ext=""
183
184 compile_x
185 ;;
186
187 #TODO: These are not cross platform in the build script, a full build
188 # from source is therefore not possible on windows, only a linux
189 # host can do that.
190 textures)
191 titleit "Compiling textures"
192 mkdir -p ./bin/content/textures
193 for f in ./textures_src/*.png;
194 do logit " qoiconv: $f";
195 dest=./bin/content/textures/"$(basename "$f" .png).qoi"
196 ./bin/linux/tools/qoiconv $f $dest
197 done
198 ;;
199 sounds)
200 titleit "Compiling sounds"
201 mkdir -p ./bin/content/textures
202
203 for f in ./sound_src/*.wav
204 do
205 dest=./bin/content/sounds/"$(basename "$f" .wav).44100.ima_adpcm"
206 ./bin/linux/tools/audcomp $f $dest
207 done
208 ;;
209
210 content)
211 logit "Copying content"
212 mkdir -p ./bin/content/models
213 mkdir -p ./bin/content/sound
214
215 cp ./models_src/* ./bin/content/models/
216 #cp ./sound_src/* ./bin/content/sound/
217 ;;
218
219 all)
220 run_command tools
221 run_command game
222 run_command server
223 ;;
224 disb)
225 mkdir -p ./dist
226 run_command release
227 run_command tools
228 run_command game
229 run_command game_win
230 run_command content
231 run_command textures
232 run_command server
233 ;;
234
235 distribution)
236 titleit "Compressing distributions"
237 logit "Linux"
238 tar -chzvf dist/skaterift_linux__$TIMESTAMP.tar.gz bin/linux/
239 logit "Server"
240 tar -chzvf dist/skaterift_server__$TIMESTAMP.tar.gz bin/linux_server
241 logit "Windows"
242 tar -chzvf dist/skaterift_win32__$TIMESTAMP.tar.gz bin/win32/
243 zip -r9 dist/skaterift_win32__$TIMESTAMP.zip bin/win32/
244 ;;
245 # Runners
246 # ========================================================================
247 test)
248 run_game
249 ;;
250 gdb)
251 cd $_linux_folder
252 gdb -tui ./skaterift
253 cd ./../
254 ;;
255 testserver)
256 run_server
257 ;;
258 testnet)
259 delay_run_game &
260 run_server
261 wait
262 ;;
263 aa)
264 run_command testaa
265 cd bin/aatest
266 ./testaa
267 cd ./../
268 ;;
269 *)
270 echo "Unrecognised command $1"
271 esac
272 }
273
274 lsan_file=$(realpath ".lsan_suppress.txt")
275 export LSAN_OPTIONS="suppressions=$lsan_file"
276
277 vg_command debug
278 source vg/vg_build.sh