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