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