vg2 port: build script and resource loading
[fishladder.git] / build.c
1 #include "vg/vg.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
9 u32 optimize_test_compile = 0;
10
11 /*
12 * Compilation specifications
13 * -------------------------------------------------------------------------- */
14
15 void build_game_content(void){
16 const char *project_name = vg_build.project_name.buffer;
17 vg_low( "Building game content structure\n" );
18 vg_symlink( "textures", "textures" );
19 vg_syscall( "mkdir -p bin/%s/cfg", project_name );
20 }
21
22 void build_shaders(void);
23 void compile_game( int binaries, int content ){
24 static int meta = 0;
25 if( !meta ){
26 meta = 1;
27 build_shaders();
28 vg_low( "\n\n" );
29 }
30
31 vg_build_new( "marblecomp" );
32
33 if( binaries ){
34 vg_add_source( "marblecomp.c" );
35 vg_add_graphics();
36 vg_add_game_stuff();
37 vg_compile( "marblecomp" );
38 }
39
40 if( content )
41 build_game_content();
42 }
43
44 /*
45 * Scripts
46 * -------------------------------------------------------------------------- */
47
48 void s_release_all(void){
49 vg_info( "running script: s_release_all(void)\n" );
50
51 vg_build.optimization = 3;
52 vg_build.fresh = 1;
53 vg_build.arch = k_architecture_x86_64;
54 vg_build.compiler = k_compiler_zigcc;
55 vg_build.libc = k_libc_version_2_23;
56
57 /* binaries for windows and linux */
58 vg_build.platform = k_platform_windows;
59 compile_game( 1, 0 );
60 vg_tarball_last_project();
61 vg_success( "Completed 1/3\n" );
62
63 vg_build.platform = k_platform_linux;
64 compile_game( 1, 0 );
65 vg_tarball_last_project();
66 vg_success( "Completed 2/3\n" );
67
68 /* content files for any platform */
69 vg_build.platform = k_platform_anyplatform;
70 vg_build.compiler = k_compiler_blob;
71 vg_build.arch = k_architecture_anyarch;
72 vg_build.libc = k_libc_version_native;
73 compile_game( 0, 1 );
74 vg_tarball_last_project();
75 vg_success( "Completed 3/3\n" );
76 }
77
78 void s_testing_build(void){
79 vg_info( "running script: s_testing_build(void)\n" );
80
81 vg_build.optimization = optimize_test_compile;
82 vg_build.fresh = 0;
83 vg_build.platform = k_platform_linux;
84 vg_build.arch = k_architecture_x86_64;
85 vg_build.compiler = k_compiler_clang;
86 vg_build.libc = k_libc_version_native;
87
88 compile_game( 1, 1 );
89
90 vg_success( "Completed 1/1\n" );
91 }
92
93 int main( int argc, char *argv[] ){
94 char *arg;
95 while( vg_argp( argc, argv ) ){
96 if( vg_long_opt( "release-all" ) )
97 s_release_all();
98
99 if( vg_long_opt( "testing-build" ) )
100 s_testing_build();
101
102 if( vg_opt('r') )
103 optimize_test_compile = 3;
104 }
105
106 if( vg_build.warnings )
107 vg_warn( "Finished with %u warnings\n", vg_build.warnings );
108 else
109 vg_success( "All scripts ran successfully\n" );
110 }
111
112 #define _S( NAME, VS, FS ) \
113 vg_build_shader( "shaders/" VS, "shaders/" FS, NULL, "shaders", NAME )
114
115 void build_shaders(void){
116 vg_info( "Compiling shader headers\n" );
117 vg_shader_set_include_dir( "shaders" );
118
119 /* Scene */
120 //_S( "scene_standard", "scene.vs", "scene_standard.fs" );
121 }