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