Notices & clean
[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="gcc -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 -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"
27 _options_release="-O3 -DVG_RELEASE"
28
29 # Compiler lines
30 # ==============================================================================
31
32 _warnings="-Wall -Wno-unused-function -Wno-unused-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
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 ln -sr bin/content/textures/ $1/textures
77 ln -sr bin/content/models/ $1/models
78 ln -sr bin/content/sound/ $1/sound
79 }
80
81 TIMESTAMP=`date +%Y-%m-%d_%H-%M-%S`
82
83 vg_command(){
84 case "$1" in
85 release)
86 _linux_options=$_options_release
87 _windows_options=$_options_release
88 ;;
89 debug)
90 _linux_options="$_linux_asan $_options_debugmode"
91 _windows_options="$_windows_asan $_options_debugmode"
92 ;;
93 game)
94 titleit "Creating Linux build"
95 mkdir -p $_linux_folder/cfg
96
97 # Dependencies
98 cp vg/dep/steam/libsteam_api.so $_linux_folder
99 link_content $_linux_folder
100
101 _compiler=$_linux_compiler
102 _options=$_linux_options
103
104 compile_miniaudio linux
105
106 # Game tools
107 _folder=$_linux_folder
108 _ext=""
109 vg_compile_tools
110
111 # Main build
112 _link="$_linux_linkgraphics $_linux_linksteam"
113 _src="main.c vg/dep/glad/glad.c vg/dep/dr_soft/miniaudio_linux.o"
114 _dst="skaterift"
115 compile_x
116 ;;
117 game_win)
118 titleit "Creating Windows build"
119 mkdir -p $_windows_folder/cfg
120
121 # Dependencies
122 cp vg/dep/steam/steam_api.dll $_windows_folder
123 link_content $_windows_folder
124
125 _compiler=$_windows_compiler
126 _options=$_windows_options
127
128 compile_miniaudio windows
129
130 # Game tools
131 _ext=".exe"
132 _folder=$_windows_folder
133 vg_compile_tools
134
135 # Main build
136 _link="$_windows_linkgraphics $_windows_linksteam"
137 _src="main.c vg/dep/glad/glad.c vg/dep/dr_soft/miniaudio_windows.o"
138 _dst="skaterift"
139 compile_x
140 ;;
141 server)
142 titleit "Creating Server build"
143 mkdir -p $_linux_server_folder/cfg
144
145 # Dependencies
146 cp vg/dep/steam/steamclient.so bin/linux_server/
147 cp vg/dep/steam/libsteam_api.so bin/linux_server/
148 cp vg/dep/steam/libsdkencryptedappticket.so bin/linux_server/
149
150 _compiler=$_linux_compiler
151 _options=$_linux_options
152 _link="-pthread -lm -lsdkencryptedappticket $_linux_linksteam"
153 _src="server.c"
154 _folder=$_linux_server_folder
155 _dst="skaterift_server"
156 _ext=""
157
158 compile_x
159 ;;
160 testaa)
161 titleit "Dev"
162 mkdir -p bin/aatest/cfg
163
164 _compiler=$_linux_compiler
165 _options=$_linux_options
166 _link="-lm"
167 _src="testaa.c"
168 _folder=bin/aatest
169 _dst="testaa"
170 _ext=""
171
172 compile_x
173 ;;
174
175 #TODO: These are not cross platform in the build script, a full build
176 # from source is therefore not possible on windows, only a linux
177 # host can do that.
178 textures)
179 titleit "Compiling textures"
180 mkdir -p ./bin/content/textures
181 for f in ./textures_src/*.png;
182 do logit " qoiconv: $f";
183 dest=./bin/content/textures/"$(basename "$f" .png).qoi"
184 ./bin/linux/tools/qoiconv $f $dest
185 done
186 ;;
187 content)
188 logit "Copying content"
189 mkdir -p ./bin/content/models
190 mkdir -p ./bin/content/sound
191
192 cp ./models_src/* ./bin/content/models/
193 cp ./sound_src/* ./bin/content/sound/
194 ;;
195
196 all)
197 run_command tools
198 run_command game
199 run_command server
200 ;;
201 distribution)
202 mkdir -p ./dist
203 run_command release
204 run_command tools
205 run_command game
206 run_command game_win
207 run_command content
208 run_command textures
209 run_command server
210
211 titleit "Compressing distributions"
212 logit "Linux"
213 tar -chzvf dist/skaterift_linux__$TIMESTAMP.tar.gz bin/linux/
214 logit "Server"
215 tar -chzvf dist/skaterift_server__$TIMESTAMP.tar.gz bin/linux_server
216 logit "Windows"
217 tar -chzvf dist/skaterift_win32__$TIMESTAMP.tar.gz bin/win32/
218 ;;
219 # Runners
220 # ========================================================================
221 test)
222 run_game
223 ;;
224 testserver)
225 run_server
226 ;;
227 testnet)
228 delay_run_game &
229 run_server
230 wait
231 ;;
232 aa)
233 run_command testaa
234 cd bin/aatest
235 ./testaa
236 cd ./../
237 ;;
238 *)
239 echo "Unrecognised command $1"
240 esac
241 }
242
243 lsan_file=$(realpath ".lsan_suppress.txt")
244 export LSAN_OPTIONS="suppressions=$lsan_file"
245
246 vg_command debug
247 source vg/vg_build.sh