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