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