loadsa work
[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
148 _compiler=$_linux_compiler
149 _options=$_linux_options
150 _link="-lm $_linux_linksteam"
151 _src="server.c"
152 _folder=$_linux_server_folder
153 _dst="skaterift_server"
154 _ext=""
155
156 compile_x
157 ;;
158 testaa)
159 titleit "Dev"
160 mkdir -p bin/aatest/cfg
161
162 _compiler=$_linux_compiler
163 _options=$_linux_options
164 _link="-lm"
165 _src="testaa.c"
166 _folder=bin/aatest
167 _dst="testaa"
168 _ext=""
169
170 compile_x
171 ;;
172
173 #TODO: These are not cross platform in the build script, a full build
174 # from source is therefore not possible on windows, only a linux
175 # host can do that.
176 textures)
177 titleit "Compiling textures"
178 mkdir -p ./bin/content/textures
179 for f in ./textures_src/*.png;
180 do logit " qoiconv: $f";
181 dest=./bin/content/textures/"$(basename "$f" .png).qoi"
182 ./bin/linux/tools/qoiconv $f $dest
183 done
184 ;;
185 content)
186 logit "Copying content"
187 mkdir -p ./bin/content/models
188 mkdir -p ./bin/content/sound
189
190 cp ./models_src/* ./bin/content/models/
191 cp ./sound_src/* ./bin/content/sound/
192 ;;
193
194 all)
195 run_command tools
196 run_command game
197 run_command server
198 ;;
199 distribution)
200 mkdir -p ./dist
201 run_command release
202 run_command tools
203 run_command game
204 run_command game_win
205 run_command content
206 run_command textures
207 run_command server
208
209 titleit "Compressing distributions"
210 logit "Linux"
211 tar -chzvf dist/skaterift_linux__$TIMESTAMP.tar.gz bin/linux/
212 logit "Server"
213 tar -chzvf dist/skaterift_server__$TIMESTAMP.tar.gz bin/linux_server
214 logit "Windows"
215 tar -chzvf dist/skaterift_win32__$TIMESTAMP.tar.gz bin/win32/
216 ;;
217 # Runners
218 # ========================================================================
219 test)
220 run_game
221 ;;
222 testserver)
223 run_server
224 ;;
225 testnet)
226 delay_run_game &
227 run_server
228 wait
229 ;;
230 aa)
231 run_command testaa
232 cd bin/aatest
233 ./testaa
234 cd ./../
235 ;;
236 *)
237 echo "Unrecognised command $1"
238 esac
239 }
240
241 vg_command debug
242 source vg/vg_build.sh