begin network integration
[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
159 #TODO: These are not cross platform in the build script, a full build
160 # from source is therefore not possible on windows, only a linux
161 # host can do that.
162 textures)
163 titleit "Compiling textures"
164 mkdir -p ./bin/content/textures
165 for f in ./textures_src/*.png;
166 do logit " qoiconv: $f";
167 dest=./bin/content/textures/"$(basename "$f" .png).qoi"
168 ./bin/linux/tools/qoiconv $f $dest
169 done
170 ;;
171 content)
172 logit "Copying content"
173 mkdir -p ./bin/content/models
174 mkdir -p ./bin/content/sound
175
176 cp ./models_src/* ./bin/content/models/
177 cp ./sound_src/* ./bin/content/sound/
178 ;;
179
180 all)
181 run_command tools
182 run_command game
183 run_command server
184 ;;
185 distribution)
186 mkdir -p ./dist
187 run_command release
188 run_command tools
189 run_command game
190 run_command game_win
191 run_command content
192 run_command textures
193 run_command server
194
195 titleit "Compressing distributions"
196 logit "Linux"
197 tar -chzvf dist/skaterift_linux__$TIMESTAMP.tar.gz bin/linux/
198 logit "Server"
199 tar -chzvf dist/skaterift_server__$TIMESTAMP.tar.gz bin/linux_server
200 logit "Windows"
201 tar -chzvf dist/skaterift_win32__$TIMESTAMP.tar.gz bin/win32/
202 ;;
203 # Runners
204 # ========================================================================
205 test)
206 run_game
207 ;;
208 testserver)
209 run_server
210 ;;
211 testnet)
212 delay_run_game &
213 run_server
214 wait
215 ;;
216 *)
217 echo "Unrecognised command $1"
218 esac
219 }
220
221 vg_command debug
222 source vg/vg_build.sh