17 enum optimization_profile
19 k_optimization_profile_debug
,
20 k_optimization_profile_release
46 void vg_build_syscall(const char *fmt
, ...)
49 va_start( args
, fmt
);
52 vsnprintf( call
, vg_list_size( call
), fmt
, args
);
62 void vg_build_object( const char *file
)
64 strcat( vg_compiler
.file
, file
);
67 void vg_build_library_dir( const char *ldir
)
69 strcat( vg_compiler
.library
, ldir
);
72 void vg_build_link( const char *link
)
74 strcat( vg_compiler
.link
, link
);
77 void vg_build_include( const char *inc
)
79 strcat( vg_compiler
.include
, inc
);
82 const char *vg_compiler_str(void)
84 return (const char *[])
85 { "clang", "gcc", "i686-w64-mingw32-gcc", "zig", "none" }
86 [vg_compiler
.compiler
];
89 void vg_build_start( const char *name
, enum compiler compiler
)
91 vg_compiler
.file
[0] = '\0';
92 vg_compiler
.link
[0] = '\0';
93 vg_compiler
.include
[0] = '\0';
94 vg_compiler
.library
[0] = '\0';
95 vg_compiler
.compiler
= compiler
;
96 strcpy( vg_compiler
.name
, name
);
98 snprintf( vg_compiler
.build_dir
, 512,
103 if( vg_compiler
.clean
){
104 vg_build_syscall( "rm -rf %s", vg_compiler
.build_dir
);
107 vg_build_syscall( "mkdir -p %s", vg_compiler
.build_dir
);
108 vg_build_include( "-I. -I./vg " );
109 vg_build_library_dir( "-L. " );
111 if( vg_compiler
.compiler
== k_compiler_zigcc
)
112 vg_build_library_dir( "-L/usr/lib " );
115 void vg_build_add_link_for_graphics(void)
117 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
118 (vg_compiler
.compiler
== k_compiler_clang
) ||
119 (vg_compiler
.compiler
== k_compiler_zigcc
) )
121 vg_build_link( "-lSDL2 -lGL -lX11 -lXxf86vm -lXrandr -lXi -ldl " );
125 vg_build_link( "-lmingw32 -lSDL2main -lSDL2 -lopengl32 -mwindows \\\n" );
126 vg_build_link( " -Wl,--dynamicbase -Wl,--nxcompat \\\n" );
128 /* + 26.05.23: Suddenly something is pulling in winpthread.
129 * cant work out whats doing it or why. */
130 vg_build_link( " -Wl,-Bstatic,--whole-archive \\\n" );
131 vg_build_link( " -lwinpthread \\\n" );
132 vg_build_link( " -Wl,--no-whole-archive " );
135 vg_build_object( "vg/dep/glad/glad.c " );
137 vg_build_link( "-lm " );
138 if( vg_compiler
.compiler
== k_compiler_mingw
){
139 //vg_build_link( "-mthreads " );
140 //vg_build_link( "-static-libgcc " );
143 vg_build_link( "-pthread " );
147 void vg_build_add_link_for_game(void)
149 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
150 (vg_compiler
.compiler
== k_compiler_clang
) ||
151 (vg_compiler
.compiler
== k_compiler_zigcc
) )
153 vg_build_link( "-lsteam_api " );
157 vg_build_library_dir( "-L./vg/dep/sdl " );
158 vg_build_link( "vg/dep/steam/steam_api.dll " );
161 vg_build_include( "-I./vg/dep " );
162 vg_build_library_dir( "-L./vg/dep/steam " );
165 void vg_build_bin_dependency_file( const char *src
)
167 vg_build_syscall( "cp %s %s", src
, vg_compiler
.build_dir
);
170 void vg_build_symbolic_link( const char *folder
, const char *bin_name
)
173 snprintf( dest
, 512, "%s/%s", vg_compiler
.build_dir
, bin_name
);
175 if( !access( dest
, F_OK
) )
176 vg_build_syscall( "unlink %s", dest
);
178 vg_build_syscall( "ln -srf %s %s", folder
, dest
);
181 void vg_build_copy_graphics_dependencies(void)
183 if( vg_compiler
.compiler
== k_compiler_mingw
)
185 vg_build_bin_dependency_file( "vg/dep/sdl/SDL2.dll" );
189 void vg_build_copy_game_dependencies(void)
191 vg_build_bin_dependency_file(
192 "vg/submodules/SDL_GameControllerDB/gamecontrollerdb.txt" );
194 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
195 (vg_compiler
.compiler
== k_compiler_clang
) ||
196 (vg_compiler
.compiler
== k_compiler_zigcc
) )
198 vg_build_bin_dependency_file( "vg/dep/steam/libsteam_api.so" );
202 vg_build_bin_dependency_file( "vg/dep/steam/steam_api.dll" );
206 void vg_build_mode_release(void)
208 vg_compiler
.optimization_profile
= k_optimization_profile_release
;
211 void vg_build_mode_debug(void)
213 vg_compiler
.optimization_profile
= k_optimization_profile_debug
;
216 void vg_build_clean(void){
217 vg_compiler
.clean
= 1;
226 strcat( cmd
, "ccache " );
227 strcat( cmd
, vg_compiler_str() );
228 strcat( cmd
, " cc" );
229 strcat( cmd
, " -std=gnu99 -D_REENTRANT \\\n" );
231 /* Debugging information */
232 if( vg_compiler
.optimization_profile
== k_optimization_profile_debug
)
234 strcat( cmd
, " -O0 -ggdb3 -fno-omit-frame-pointer " );
236 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
237 (vg_compiler
.compiler
== k_compiler_clang
) ||
238 (vg_compiler
.compiler
== k_compiler_zigcc
) )
240 strcat( cmd
, "-rdynamic -fsanitize=address "
241 "-fPIE -fstack-protector-strong " );
244 strcat( cmd
, "\\\n" );
248 strcat( cmd
, " -O3 -DVG_RELEASE\\\n" );
254 " -Wno-unused-function -Wno-unused-variable -Wno-format-truncation\\\n"
255 " -Wno-unused-command-line-argument -Wno-unused-but-set-variable\\\n"
258 if( vg_compiler
.compiler
== k_compiler_clang
){
260 " -ferror-limit=5\\\n" );
265 strcat( cmd
, vg_compiler
.include
);
266 strcat( cmd
, "\\\n" );
270 strcat( cmd
, vg_compiler
.library
);
271 strcat( cmd
, "\\\n" );
275 strcat( cmd
, vg_compiler
.file
);
276 strcat( cmd
, "\\\n" );
279 strcat( cmd
, " -o " );
280 vg_compiler
.executable
[0] = '\0';
281 strcat( vg_compiler
.executable
, vg_compiler
.build_dir
);
282 strcat( vg_compiler
.executable
, "/" );
283 strcat( vg_compiler
.executable
, vg_compiler
.name
);
285 if( vg_compiler
.compiler
== k_compiler_mingw
)
286 strcat( vg_compiler
.executable
, ".exe" );
288 strcat( cmd
, vg_compiler
.executable
);
289 strcat( cmd
, "\\\n" );
293 strcat( cmd
, vg_compiler
.link
);
294 strcat( cmd
, "\\\n" );
296 strcat( cmd
, " -Wl,-rpath=./" );
298 if( vg_compiler
.compiler
== k_compiler_zigcc
){
299 strcat( cmd
, " -target native-native-gnu.2.23" );
302 vg_build_syscall( cmd
);