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 " );
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( "-lSDL2 -lGL -lX11 -lXxf86vm -lXrandr -lXi -ldl " );
113 vg_build_link( "-lmingw32 -lSDL2main -lSDL2 -lopengl32 -mwindows \\\n" );
114 vg_build_link( " -Wl,--dynamicbase -Wl,--nxcompat " );
117 vg_build_object( "vg/dep/glad/glad.c " );
119 vg_build_link( "-lm " );
120 if( vg_compiler
.compiler
== k_compiler_mingw
){
121 //vg_build_link( "-mthreads " );
122 //vg_build_link( "-static-libgcc " );
125 vg_build_link( "-pthread " );
129 void vg_build_add_link_for_game(void)
131 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
132 (vg_compiler
.compiler
== k_compiler_clang
) )
134 vg_build_link( "-lsteam_api " );
138 vg_build_library_dir( "-L./vg/dep/sdl " );
139 vg_build_link( "vg/dep/steam/steam_api.dll " );
142 vg_build_include( "-I./vg/dep " );
143 vg_build_library_dir( "-L./vg/dep/steam " );
146 void vg_build_bin_dependency_file( const char *src
)
148 vg_build_syscall( "cp %s %s", src
, vg_compiler
.build_dir
);
151 void vg_build_symbolic_link( const char *folder
, const char *bin_name
)
154 snprintf( dest
, 512, "%s/%s", vg_compiler
.build_dir
, bin_name
);
156 if( !access( dest
, F_OK
) )
157 vg_build_syscall( "unlink %s", dest
);
159 vg_build_syscall( "ln -srf %s %s", folder
, dest
);
162 void vg_build_copy_graphics_dependencies(void)
164 if( vg_compiler
.compiler
== k_compiler_mingw
)
166 vg_build_bin_dependency_file( "vg/dep/sdl/SDL2.dll" );
170 void vg_build_copy_game_dependencies(void)
172 vg_build_bin_dependency_file(
173 "vg/submodules/SDL_GameControllerDB/gamecontrollerdb.txt" );
175 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
176 (vg_compiler
.compiler
== k_compiler_clang
) )
178 vg_build_bin_dependency_file( "vg/dep/steam/libsteam_api.so" );
182 vg_build_bin_dependency_file( "vg/dep/steam/steam_api.dll" );
186 void vg_build_mode_release(void)
188 vg_compiler
.optimization_profile
= k_optimization_profile_release
;
191 void vg_build_mode_debug(void)
193 vg_compiler
.optimization_profile
= k_optimization_profile_debug
;
202 strcat( cmd
, "ccache " );
203 strcat( cmd
, vg_compiler_str() );
204 strcat( cmd
, " -std=gnu99 -D_REENTRANT \\\n" );
206 /* Debugging information */
207 if( vg_compiler
.optimization_profile
== k_optimization_profile_debug
)
209 strcat( cmd
, " -O0 -ggdb3 -fno-omit-frame-pointer " );
211 if( (vg_compiler
.compiler
== k_compiler_gcc
) ||
212 (vg_compiler
.compiler
== k_compiler_clang
) )
214 strcat( cmd
, "-rdynamic -fsanitize=address " );
217 strcat( cmd
, "\\\n" );
221 strcat( cmd
, " -O3 -DVG_RELEASE\\\n" );
227 " -Wno-unused-function -Wno-unused-variable\\\n"
228 " -Wno-unused-command-line-argument -Wno-unused-but-set-variable\\\n"
231 if( vg_compiler
.compiler
== k_compiler_clang
){
233 " -ferror-limit=5\\\n" );
238 strcat( cmd
, vg_compiler
.include
);
239 strcat( cmd
, "\\\n" );
243 strcat( cmd
, vg_compiler
.library
);
244 strcat( cmd
, "\\\n" );
248 strcat( cmd
, vg_compiler
.file
);
249 strcat( cmd
, "\\\n" );
252 strcat( cmd
, " -o " );
253 vg_compiler
.executable
[0] = '\0';
254 strcat( vg_compiler
.executable
, vg_compiler
.build_dir
);
255 strcat( vg_compiler
.executable
, "/" );
256 strcat( vg_compiler
.executable
, vg_compiler
.name
);
258 if( vg_compiler
.compiler
== k_compiler_mingw
)
259 strcat( vg_compiler
.executable
, ".exe" );
261 strcat( cmd
, vg_compiler
.executable
);
262 strcat( cmd
, "\\\n" );
266 strcat( cmd
, vg_compiler
.link
);
267 strcat( cmd
, "\\\n" );
269 strcat( cmd
, " -Wl,-rpath=./" );
271 vg_build_syscall( cmd
);