Windows libraries for getaddrinfo
[carveJwlIkooP6JGAAIwe30JlM.git] / build.c
1 #include "vg/vg_tool.h"
2 #include "vg/vg_platform.h"
3 #include "vg/vg_log.h"
4 #include "vg/vg_opt.h"
5 #include "vg/vg_build.h"
6 #include "vg/vg_build_utils_shader.h"
7 #include "vg/vg_msg.h"
8 #include "addon_types.h"
9
10 #define C0_STOPGAP
11 #include "vg/vg_m.h"
12 #include "model.h"
13 #include "model.c"
14 #include "c0_stopgap.c"
15
16 /*
17 * Addon metadata utilities
18 * -------------------------------------------------------------------------- */
19
20 void write_msg( vg_msg *msg, const char *path ){
21 FILE *fp = fopen( path, "wb" );
22 if( !fp ){
23 vg_error( "Cannot open %s for writing.\n", path );
24 exit(0);
25 }
26
27 fwrite( msg->buf, msg->cur.co, 1, fp );
28 fclose( fp );
29 vg_success( "Written %s (%ub)\n", path, msg->cur );
30 }
31
32 void write_generic_addon_inf( u32 type, const char *title,
33 const char *content, const char *dest )
34 {
35 u8 descriptor_buf[ 512 ];
36 vg_msg descriptor = {0};
37 descriptor.buf = descriptor_buf;
38 descriptor.max = sizeof(descriptor_buf);
39 vg_msg_frame( &descriptor, "workshop" );
40 vg_msg_wkvstr( &descriptor, "title", title );
41 vg_msg_wkvstr( &descriptor, "author", "Skaterift" );
42 vg_msg_wkvnum( &descriptor, "type", k_vg_msg_u32, 1, &type );
43 vg_msg_end_frame( &descriptor );
44 vg_msg_wkvstr( &descriptor, "content", content );
45 write_msg( &descriptor, dest );
46 }
47
48 /*
49 * Compilation specifications
50 * -------------------------------------------------------------------------- */
51
52 /* operates in the local files, not in the bin folders */
53 void build_game_metadata(void)
54 {
55 vg_info( "Building game metadata\n" );
56 write_generic_addon_inf( k_addon_type_board,
57 "Longboard", "board.mdl",
58 "boards_src/skaterift_long/addon.inf");
59 write_generic_addon_inf( k_addon_type_board,
60 "Fractal", "board.mdl",
61 "boards_src/skaterift_fract/addon.inf");
62 write_generic_addon_inf( k_addon_type_board,
63 "Striped", "board.mdl",
64 "boards_src/skaterift_striped/addon.inf");
65 write_generic_addon_inf( k_addon_type_board,
66 "Licco", "board.mdl",
67 "boards_src/skaterift_licco/addon.inf");
68 write_generic_addon_inf( k_addon_type_board,
69 "Hypno", "board.mdl",
70 "boards_src/skaterift_spiral/addon.inf");
71 write_generic_addon_inf( k_addon_type_board,
72 "Shark", "board.mdl",
73 "boards_src/skaterift_shark/addon.inf");
74
75 write_generic_addon_inf( k_addon_type_player,
76 "De'folde", "ch_new.mdl",
77 "playermodels_src/skaterift_new/addon.inf" );
78 write_generic_addon_inf( k_addon_type_player,
79 "Jordan", "ch_jordan.mdl",
80 "playermodels_src/skaterift_jordan/addon.inf" );
81 write_generic_addon_inf( k_addon_type_player,
82 "Outlaw", "ch_outlaw.mdl",
83 "playermodels_src/skaterift_outlaw/addon.inf" );
84 write_generic_addon_inf( k_addon_type_player,
85 "Chip", "ch_chip.mdl",
86 "playermodels_src/skaterift_chip/addon.inf" );
87 write_generic_addon_inf( k_addon_type_player,
88 "Aaron", "ch_aaron.mdl",
89 "playermodels_src/skaterift_aaron/addon.inf" );
90 }
91
92 #define _S( NAME, VS, FS ) \
93 vg_build_shader( "shaders/" VS, "shaders/" FS, NULL, "shaders", NAME )
94
95 void build_shaders(void){
96 vg_info( "Compiling shader headers\n" );
97 vg_shader_set_include_dir( "shaders" );
98
99 /* Scene */
100 _S( "scene_standard", "scene.vs", "scene_standard.fs" );
101 _S( "scene_standard_alphatest", "scene.vs", "scene_standard_alphatest.fs" );
102 _S( "scene_foliage", "scene_foliage.vs", "scene_foliage.fs" );
103 _S( "scene_override", "scene_override.vs", "scene_override.fs" );
104 _S( "scene_fxglow", "scene_fxglow.vs", "scene_fxglow.fs" );
105 _S( "scene_vertex_blend", "scene.vs", "scene_vertex_blend.fs" );
106 _S( "scene_terrain", "scene.vs", "scene_terrain.fs" );
107 _S( "scene_route", "scene_override.vs", "scene_route.fs" );
108 _S( "scene_depth", "scene.vs", "scene_depth.fs" );
109 _S( "scene_position", "scene.vs", "scene_position.fs" );
110 _S( "scene_cubemapped", "scene.vs", "scene_cubemapped.fs" );
111 _S( "scene_water", "scene.vs", "scene_water.fs" );
112 _S( "scene_water_fast", "scene.vs", "scene_water_fast.fs" );
113 _S( "scene_scoretext", "scene_sfd.vs", "scene_standard.fs" );
114 _S( "scene_font", "model_font.vs","scene_font.fs" );
115
116 /* Models */
117 _S( "model_sky", "model.vs", "model_sky.fs" );
118 _S( "model_sky_space", "model.vs", "model_sky_space.fs" );
119 _S( "model_menu", "model.vs", "model_menu.fs" );
120 _S( "model_character_view", "model_skinned.vs", "model_character_view.fs" );
121 _S( "model_board_view", "model.vs", "model_character_view.fs" );
122 _S( "model_entity", "model.vs", "model_entity.fs" );
123 _S( "model_gate", "model.vs", "model_gate_lq.fs" );
124 _S( "model_gate_unlinked", "model.vs", "model_gate_unlinked.fs" );
125 _S( "model_font", "model_font.vs", "model_font.fs" );
126
127 _S( "particle", "particle.vs", "particle.fs" );
128 _S( "trail", "trail.vs", "trail.fs" );
129
130 /* 2D */
131 _S( "blit", "blit.vs", "blit.fs" );
132 _S( "blitblur", "blit.vs", "blitblur.fs" );
133 _S( "blitcolour","blit.vs", "colour.fs" );
134 _S( "blit_transition", "blit.vs", "blit_transition.fs" );
135 _S( "routeui", "routeui.vs", "routeui.fs" );
136
137 vg_build_shader_impl( "shaders/impl.c" );
138 }
139
140 void build_game_content( struct vg_project *proj )
141 {
142 vg_project_new_target( proj, "Content files", k_obj_type_none );
143
144 vg_symlink( proj, "textures_src", "textures" );
145 vg_symlink( proj, "models_src", "models" );
146 vg_symlink( proj, "boards_src", "boards" );
147 vg_symlink( proj, "maps_src", "maps" );
148 vg_symlink( proj, "sound_src", "sound" );
149 vg_symlink( proj, "playermodels_src", "playermodels" );
150 vg_syscall( "mkdir -p bin/%s/cfg", proj->uid.buffer );
151 vg_syscall( "mkdir -p bin/%s/savedata", proj->uid.buffer );
152 vg_syscall( "mkdir -p bin/%s/tools", proj->uid.buffer );
153 vg_syscall( "cp bin/skaterift_blender.zip bin/%s/tools/", proj->uid.buffer );
154 }
155
156 void build_game_bin( struct vg_project *proj )
157 {
158 static int meta = 0;
159 if( !meta )
160 {
161 meta = 1;
162 build_shaders();
163 build_game_metadata();
164 vg_low( "\n\n" );
165 }
166
167 #include "control_overlay.h"
168
169 vg_project_new_target( proj, "skaterift", k_obj_type_exe );
170 vg_add_engine( proj, &(struct vg_engine_config )
171 {
172 .fixed_update_hz = 60,
173 .legacy_support_vg_msg1 = 1,
174 .log_source_info = 1,
175 .steam_api = 1,
176 .use_3d = 1,
177 .custom_game_settings = 0,
178 .custom_shaders = 1
179 });
180
181 if( proj->env->platform == k_platform_windows )
182 {
183 vg_link( proj, "-lws2_32 " );
184 }
185
186 vg_add_source( proj, "skaterift.c " );
187 vg_add_controller_database( proj );
188 vg_compile_project( proj );
189 }
190
191 void build_sqlite_for_env( struct vg_env *env, struct vg_project *out_proj )
192 {
193 struct vg_env sqlite_env = *env;
194 sqlite_env.optimization = 3; /* force optimization always */
195 sqlite_env.debug_asan = 0;
196
197 vg_project_init( out_proj, env, "sqlite3" );
198 vg_project_new_target( out_proj, "sqlite3", k_obj_type_obj );
199
200 vg_add_source( out_proj, "-c dep/sqlite3/sqlite3.c " );
201 vg_link( out_proj, "-ldl " );
202 vg_compile_project( out_proj );
203 }
204
205 void compile_server( struct vg_project *proj )
206 {
207 struct vg_project sqlite_project;
208 build_sqlite_for_env( proj->env, &sqlite_project );
209
210 vg_project_new_target( proj, "server", k_obj_type_exe );
211 vg_add_source( proj, "gameserver.c vg/vg_tool.c vg/vg_steam.c \\\n " );
212 vg_add_source( proj, sqlite_project.compiled_objects.buffer );
213 vg_include_dir( proj, "-I./dep " );
214 vg_library_dir( proj, "-L./vg/dep/steam " );
215 vg_link( proj, "-ldl -lpthread -lm -lsdkencryptedappticket -lsteam_api " );
216 vg_add_blob( proj, "vg/dep/steam/libsteam_api.so", "" );
217 vg_add_blob( proj, "vg/dep/steam/libsdkencryptedappticket.so", "" );
218
219 vg_compile_project( proj );
220 }
221
222 void compile_tools( struct vg_project *proj )
223 {
224 vg_project_new_target( proj, "skaterift", k_obj_type_shared );
225 vg_add_source( proj, "skaterift_lib.c " );
226 vg_compile_project( proj );
227 }
228
229 /*
230 * Scripts
231 * -------------------------------------------------------------------------- */
232
233 void s_compile_tools(void)
234 {
235 vg_info( "running script: s_compile_tools(void)\n" );
236 struct vg_env env = vg_release_env;
237 env.platform = k_platform_linux;
238
239 struct vg_project windows_proj, linux_proj;
240 vg_project_init( &linux_proj, &env, "skaterift-tools" );
241 compile_tools( &linux_proj );
242
243 env.platform = k_platform_windows;
244 vg_project_init( &windows_proj, &env, "skaterift-tools" );
245 compile_tools( &windows_proj );
246
247 vg_syscall("cp %s skaterift_blender/", linux_proj.compiled_objects.buffer );
248 vg_syscall("cp %s skaterift_blender/", windows_proj.compiled_objects.buffer);
249 vg_syscall( "zip -r bin/skaterift_blender.zip skaterift_blender/ "
250 "-x skaterift_blender/__pycache__/\\*");
251 }
252
253 void s_release_all(void)
254 {
255 vg_info( "running script: s_release_all(void)\n" );
256
257 struct vg_project content_proj, windows_proj, linux_proj;
258
259 struct vg_env env = vg_release_env;
260 env.platform = k_platform_anyplatform;
261 vg_project_init( &content_proj, &env, "skaterift" );
262 build_game_content( &content_proj );
263
264 /* binaries for windows */
265 env = vg_release_env;
266 env.platform = k_platform_windows;
267 vg_project_init( &windows_proj, &env, "skaterift" );
268 build_game_bin( &windows_proj );
269
270 /* binaries for linux */
271 env = vg_release_env;
272 env.platform = k_platform_linux;
273 vg_project_init( &linux_proj, &env, "skaterift" );
274 build_game_bin( &linux_proj );
275
276 /* package them up for storage */
277 vg_tarball_project( &content_proj );
278 vg_tarball_project( &linux_proj );
279 vg_tarball_project( &windows_proj );
280
281 /* extreme DRM solutions */
282 FILE *fp = fopen( "dist/bin/DRM", "w" );
283 fputs( "blibby!", fp );
284 fclose( fp );
285 }
286
287 void s_testing_build(void)
288 {
289 vg_info( "running script: s_testing_build(void)\n" );
290
291 struct vg_project test_proj;
292 vg_project_init( &test_proj, &vg_test_env, "skaterift-test" );
293
294 build_game_bin( &test_proj );
295 build_game_content( &test_proj );
296 vg_add_blob( &test_proj, "steam_appid.txt", "" );
297 }
298
299 void s_testing_server(void)
300 {
301 vg_info( "running script: s_testing_server(void)\n" );
302
303 struct vg_project test_proj;
304 vg_project_init( &test_proj, &vg_test_env, "skaterift-test-server" );
305 compile_server( &test_proj );
306 }
307
308 int main( int argc, char *argv[] )
309 {
310 char *arg;
311 while( vg_argp( argc, argv ) ){
312 if( vg_long_opt( "release-all" ) )
313 s_release_all();
314
315 if( vg_long_opt( "testing-build" ) )
316 s_testing_build();
317
318 if( vg_long_opt( "testing-server" ) )
319 s_testing_server();
320
321 if( vg_long_opt( "tools" ) )
322 s_compile_tools();
323
324 if( vg_opt('r') )
325 vg_test_env.optimization = 3;
326 }
327
328 vg_success( "All scripts completed\n" );
329 }