17 enum optimization_profile
19 k_optimization_profile_debug
,
20 k_optimization_profile_release
42 void vg_build_syscall(const char *fmt
, ...)
45 va_start( args
, fmt
);
48 vsnprintf( call
, vg_list_size( call
), fmt
, args
);
58 void vg_build_object( const char *file
)
60 strcat( vg_compiler
.file
, file
);
63 void vg_build_library_dir( const char *ldir
)
65 strcat( vg_compiler
.library
, ldir
);
68 void vg_build_link( const char *link
)
70 strcat( vg_compiler
.link
, link
);
73 void vg_build_include( const char *inc
)
75 strcat( vg_compiler
.include
, inc
);
78 const char *vg_compiler_str(void)
80 return (const char *[]){ "clang", "gcc", "i686-w64-mingw32-gcc" }
81 [vg_compiler
.compiler
];
84 void vg_build_start( const char *name
, enum compiler compiler
)
86 vg_compiler
.file
[0] = '\0';
87 vg_compiler
.link
[0] = '\0';
88 vg_compiler
.include
[0] = '\0';
89 vg_compiler
.library
[0] = '\0';
90 vg_compiler
.compiler
= compiler
;
92 strcpy( vg_compiler
.name
, name
);
94 snprintf( vg_compiler
.build_dir
, 512,
99 vg_build_syscall( "mkdir -p %s", vg_compiler
.build_dir
);
100 vg_build_include( "-I. -I./vg/src " );
101 vg_build_library_dir( "-L. " );
104 void vg_build_add_link_for_graphics(void)
106 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
107 (vg_compiler
.compiler
== k_compiler_clang
) )
109 vg_build_link( "-lGL -lglfw3 -lX11 -lXxf86vm -lXrandr -lXi -ldl " );
113 vg_build_link( "-lglfw3dll -lopengl32 -static -mwindows " );
116 vg_build_object( "vg/dep/glad/glad.c " );
117 vg_build_link( "-lm -pthread " );
118 vg_build_library_dir( "-L./vg/dep/glfw " );
121 void vg_build_add_link_for_game(void)
123 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
124 (vg_compiler
.compiler
== k_compiler_clang
) )
126 vg_build_link( "-lsteam_api " );
127 vg_build_object( "vg/dep/dr_soft/miniaudio." );
131 vg_build_link( "vg/dep/steam/steam_api.dll " );
132 vg_build_object( "vg/dep/dr_soft/miniaudio." );
135 vg_build_object( vg_compiler_str() );
136 vg_build_object( ".o " );
138 vg_build_include( "-I./vg/dep " );
139 vg_build_library_dir( "-L./vg/dep/steam " );
142 void vg_build_bin_dependency_file( const char *src
)
144 vg_build_syscall( "cp %s %s", src
, vg_compiler
.build_dir
);
147 void vg_build_symbolic_link( const char *folder
, const char *bin_name
)
150 snprintf( dest
, 512, "%s/%s", vg_compiler
.build_dir
, bin_name
);
152 if( !access( dest
, F_OK
) )
153 vg_build_syscall( "unlink %s", dest
);
155 vg_build_syscall( "ln -srf %s %s", folder
, dest
);
158 void vg_build_copy_graphics_dependencies(void)
160 if( vg_compiler
.compiler
== k_compiler_mingw
)
162 vg_build_bin_dependency_file( "vg/dep/glfw/glfw3.dll" );
166 void vg_build_copy_game_dependencies(void)
168 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
169 (vg_compiler
.compiler
== k_compiler_clang
) )
171 vg_build_bin_dependency_file( "vg/dep/steam/libsteam_api.so" );
175 vg_build_bin_dependency_file( "vg/dep/steam/steam_api.dll" );
179 void vg_build_mode_release(void)
181 vg_compiler
.optimization_profile
= k_optimization_profile_release
;
184 void vg_build_mode_debug(void)
186 vg_compiler
.optimization_profile
= k_optimization_profile_debug
;
189 void vg_build_miniaudio(void)
191 vg_build_syscall( "ccache %s -O3\\\n"
192 " -c vg/dep/dr_soft/miniaudio_impl.c\\\n"
193 " -o vg/dep/dr_soft/miniaudio.%s.o",
194 vg_compiler_str(), vg_compiler_str() );
203 strcat( cmd
, "ccache " );
204 strcat( cmd
, vg_compiler_str() );
205 strcat( cmd
, " -std=gnu99 -D_REENTRANT \\\n" );
207 /* Debugging information */
208 if( vg_compiler
.optimization_profile
== k_optimization_profile_debug
)
210 strcat( cmd
, " -O0 -ggdb3 -fno-omit-frame-pointer " );
212 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
213 (vg_compiler
.compiler
== k_compiler_clang
) )
215 strcat( cmd
, "-rdynamic -fsanitize=address " );
218 strcat( cmd
, "\\\n" );
222 strcat( cmd
, " -O3 -DVG_RELEASE\\\n" );
228 " -Wno-unused-function -Wno-unused-variable\\\n"
229 " -Wno-unused-command-line-argument -Wno-unused-but-set-variable\\\n"
234 strcat( cmd
, vg_compiler
.include
);
235 strcat( cmd
, "\\\n" );
239 strcat( cmd
, vg_compiler
.library
);
240 strcat( cmd
, "\\\n" );
244 strcat( cmd
, vg_compiler
.file
);
245 strcat( cmd
, "\\\n" );
248 strcat( cmd
, " -o " );
249 vg_compiler
.executable
[0] = '\0';
250 strcat( vg_compiler
.executable
, vg_compiler
.build_dir
);
251 strcat( vg_compiler
.executable
, "/" );
252 strcat( vg_compiler
.executable
, vg_compiler
.name
);
254 if( vg_compiler
.compiler
== k_compiler_mingw
)
255 strcat( vg_compiler
.executable
, ".exe" );
257 strcat( cmd
, vg_compiler
.executable
);
258 strcat( cmd
, "\\\n" );
262 strcat( cmd
, vg_compiler
.link
);
263 strcat( cmd
, "\\\n" );
265 strcat( cmd
, " -Wl,-rpath=./" );
267 vg_build_syscall( cmd
);