From a6501b5d7ad204c3b998c843c7ed68ef7be323ba Mon Sep 17 00:00:00 2001 From: gramanas Date: Wed, 5 Jun 2024 19:04:25 +0300 Subject: more vks, stupid mutlistep build, and imgui --- b.c | 135 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 126 insertions(+), 9 deletions(-) (limited to 'b.c') diff --git a/b.c b/b.c index 0221fff..db24cdd 100644 --- a/b.c +++ b/b.c @@ -1,18 +1,64 @@ #define B_IMPLEMENTATION #include "src/b.h" -void cflags(B_Cmd *cmd) +int debug_level = 1; + +void +debug_or_release(B_Cmd* cmd) +{ + if (debug_level == 0) + b_cmd_append(cmd, "-O3", "-s"); + else if (debug_level == 1) + b_cmd_append(cmd, "-O2", "-ggdb", "-DVKDEBUG"); + else if (debug_level == 2) + b_cmd_append(cmd, "-O1", "-ggdb", "-DVKDEBUG"); + else + b_cmd_append(cmd, "-O0", "-ggdb", "-DVKDEBUG"); +} + +void +inlcude_dirs(B_Cmd* cmd) +{ + b_cmd_append(cmd, "-I./src/"); + b_cmd_append(cmd, "-I./lib"); + b_cmd_append(cmd, "-I./lib/imgui-1.90.7"); +} + +void +cflags(B_Cmd* cmd) +{ + b_cmd_append(cmd, "-Wall", "-Wextra"); + + debug_or_release(cmd); + + b_cmd_append(cmd, "-march=native"); + b_cmd_append(cmd, "-fno-math-errno", "-funroll-loops"); + b_cmd_append(cmd, "-flto", "-pthread"); + + inlcude_dirs(cmd); +} + +void cxxflags(B_Cmd *cmd) { b_cmd_append(cmd, "-Wall", "-Wextra"); b_cmd_append(cmd, "-Wno-string-plus-int", "-Wno-nullability-completeness", "-Wno-unused-function", "-Wno-missing-field-initializers", "-Wno-unused-parameter", "-Wno-unused-variable"); + + debug_or_release(cmd); + b_cmd_append(cmd, "-march=native"); b_cmd_append(cmd, "-fno-math-errno", "-funroll-loops"); b_cmd_append(cmd, "-flto", "-pthread"); - b_cmd_append(cmd, "-I./src/"); - b_cmd_append(cmd, "-O2", "-ggdb", "-DVKDEBUG"); + + inlcude_dirs(cmd); //b_cmd_append(cmd, "-O3"); } +void cxx(B_Cmd *cmd) +{ + b_cmd_append(cmd, "clang"); + cxxflags(cmd); +} + void cc(B_Cmd *cmd) { b_cmd_append(cmd, "clang"); @@ -24,9 +70,17 @@ void libs(B_Cmd *cmd) b_cmd_append(cmd, "-lSDL2", "-lm", "-lvulkan", "-lshaderc_shared", "-lstdc++"); } -bool build_exe(bool force, B_Cmd *cmd, const char **input_paths, size_t input_paths_len, const char **dep_paths, size_t dep_paths_len, const char *output_path) +bool +build_c(bool force, + B_Cmd* cmd, + const char** input_paths, + size_t input_paths_len, + const char** dep_paths, + size_t dep_paths_len, + const char* output_path) { - int rebuild_is_needed = b_needs_rebuild(output_path, input_paths, input_paths_len); + int rebuild_is_needed = + b_needs_rebuild(output_path, input_paths, input_paths_len); int dep_rebuild = b_needs_rebuild(output_path, dep_paths, dep_paths_len); if (rebuild_is_needed < 0 || dep_rebuild < 0) return false; @@ -44,6 +98,34 @@ bool build_exe(bool force, B_Cmd *cmd, const char **input_paths, size_t input_pa return true; } +bool +compile_cxx(bool force, + B_Cmd* cmd, + const char** input_paths, + size_t input_paths_len, + const char** dep_paths, + size_t dep_paths_len, + const char* output_path) +{ + int rebuild_is_needed = b_needs_rebuild(output_path, input_paths, input_paths_len); + int dep_rebuild = b_needs_rebuild(output_path, dep_paths, dep_paths_len); + + if (rebuild_is_needed < 0 || dep_rebuild < 0) return false; + + if (force || rebuild_is_needed || dep_rebuild) { + cmd->count = 0; + cxx(cmd); + b_cmd_append(cmd, "-c"); + //b_cmd_append(cmd, "-o", output_path); + b_da_append_many(cmd, input_paths, input_paths_len); + //libs(cmd); + return b_cmd_run_sync(*cmd); + } + + b_log(B_INFO, "%s is up-to-date", output_path); + return true; +} + int main(int argc, char *argv[]) { @@ -63,17 +145,52 @@ main(int argc, char *argv[]) } } - const char *dep_paths[] = { + const char *cxx_dep_paths[] = { + "src/vksetup.h", + }; + const char* cxx_input_paths[] = { + "src/cplusplus.cpp", + "lib/imgui-1.90.7/imgui.cpp", + "lib/imgui-1.90.7/imgui_demo.cpp", + "lib/imgui-1.90.7/imgui_draw.cpp", + "lib/imgui-1.90.7/imgui_tables.cpp", + "lib/imgui-1.90.7/imgui_widgets.cpp", + "lib/imgui-1.90.7/backends/imgui_impl_sdl2.cpp", + "lib/imgui-1.90.7/backends/imgui_impl_vulkan.cpp", + }; + + const char *c_dep_paths[] = { "src/state.h", "src/vksetup.h", }; - const char *input_paths[] = { + const char* c_input_paths[] = { "src/render.c", - "src/cplusplus.cpp" + "cplusplus.o", + "imgui.o", + "imgui_demo.o", + "imgui_draw.o", + "imgui_tables.o", + "imgui_widgets.o", + "imgui_impl_sdl2.o", + "imgui_impl_vulkan.o", }; B_Cmd cmd = {0}; - if (!build_exe(force, &cmd, input_paths, B_ARRAY_LEN(input_paths), dep_paths, B_ARRAY_LEN(dep_paths),"render")) return 1; + if (!compile_cxx(force, &cmd, cxx_input_paths, B_ARRAY_LEN(cxx_input_paths), cxx_dep_paths, B_ARRAY_LEN(c_dep_paths),"cplusplus.o")) return 1; + if (!build_c(force, &cmd, c_input_paths, B_ARRAY_LEN(c_input_paths), c_dep_paths, B_ARRAY_LEN(c_dep_paths),"render")) return 1; return 0; } + +/* + 1. Build list of .cpp (with s) -> into build/cxx//.o + 2. Build list of .c (with s) -> into build/c//.o + + 3. Build .c linking with the objects from 1 & 2 -> into + + Check for rebuilds: + 1. and s + 2. and s + 3. and all links {cxx,c}/ * / *.o + +*/ -- cgit v1.2.3