From 9847614871e861c216425b95a8300dba37b0f6e6 Mon Sep 17 00:00:00 2001 From: grm Date: Sun, 2 Mar 2025 13:53:54 +0200 Subject: Also improve midi and add tt for templating --- b.c | 93 ++++++++++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 57 insertions(+), 36 deletions(-) (limited to 'b.c') diff --git a/b.c b/b.c index 3056ebf..6ac5db6 100644 --- a/b.c +++ b/b.c @@ -3,6 +3,7 @@ #include #define BUILD_DIR "build/" +#define TEMPLATE_DIR BUILD_DIR"templates/" int debug_level = 0; @@ -25,59 +26,40 @@ debug_or_release(B_Cmd* cmd) void inlcude_dirs(B_Cmd* cmd) { - b_cmd_append(cmd, "-I./src/"); + b_cmd_append(cmd, "-I./src/", "-I./"TEMPLATE_DIR); } void -cflags(B_Cmd* cmd) +cflags_common(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"); - b_cmd_append(cmd, "-lportaudio", "-lrt", "-lm", "-lasound", "-lraylib", "-lportmidi", "-ljack", "-lfftw3f", "-lsndfile", "-lconfig", "-lmicrohttpd", "-lpthread", "-lwebsockets"); - - inlcude_dirs(cmd); + b_cmd_append(cmd, "-march=native", "-lm"); + b_cmd_append(cmd, "-fno-math-errno", "-funroll-loops", "-flto"); } -void cxxflags(B_Cmd *cmd) +void +synth_libs(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, "-lportaudio", "-lrt", "-lasound", "-lraylib", "-lportmidi", + "-lfftw3f", "-lsndfile", "-lconfig", "-lpthread", + "-lwebsockets"); 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"); - cflags(cmd); + cflags_common(cmd); } -void libs(B_Cmd *cmd) -{ - b_cmd_append(cmd, "-lSDL2", "-lm", "-lvulkan", "-lshaderc_shared", "-lstdc++"); -} +bool force = false; bool -build_c(bool force, - B_Cmd* cmd, +build_c(B_Cmd* cmd, const char** input_paths, size_t input_paths_len, const char** dep_paths, @@ -85,11 +67,13 @@ build_c(bool force, const char* output_path) { int rebuild_is_needed = - b_needs_rebuild(output_path, input_paths, input_paths_len); + b_needs_rebuild(B_COMPILE, output_path, input_paths, input_paths_len); int dep_rebuild = 0; if (rebuild_is_needed == 0) - dep_rebuild = b_needs_rebuild(output_path, dep_paths, dep_paths_len); + dep_rebuild = + b_needs_rebuild(B_COMPILE, output_path, dep_paths, dep_paths_len); + if (rebuild_is_needed < 0 || dep_rebuild < 0) return false; @@ -98,7 +82,8 @@ build_c(bool force, cc(cmd); b_cmd_append(cmd, "-o", output_path); b_da_append_many(cmd, input_paths, input_paths_len); - libs(cmd); + if (0 == strcmp(output_path, BUILD_DIR"synth")) + synth_libs(cmd); return b_cmd_run_sync(*cmd); } @@ -106,6 +91,30 @@ build_c(bool force, return true; } +bool build_templates(B_Cmd *cmd, const char **templates, size_t len) { + char dest[1024] = ""; + for (size_t i = 0; i < len; i++) { + cmd->count = 0; + char *base = strdup(templates[i]); + strcpy(dest, TEMPLATE_DIR); + strcat(dest, basename(base)); + strcat(dest, ".h"); + if (b_needs_rebuild1(B_TEMPLATE, dest, templates[i]) == 0 && + force == false) { + b_log(B_INFO, "%s is up-to-date", dest); + continue; + } + char tmp[1024] = ""; + strcat(tmp, "build/tt "); + strcat(tmp, templates[i]); + strcat(tmp, " > "); + strcat(tmp, dest); + b_cmd_append(cmd, "bash", "-c", tmp); + b_cmd_run_sync(*cmd); + } + return true; +} + int main(int argc, char *argv[]) { @@ -113,7 +122,6 @@ main(int argc, char *argv[]) const char *program_name = b_shift_args(&argc, &argv); (void)program_name; - bool force = false; while (argc > 0) { const char *flag = b_shift_args(&argc, &argv); @@ -148,6 +156,7 @@ main(int argc, char *argv[]) "src/types.h", "src/web.h", "src/gui.h", + BUILD_DIR"templates/index.html.h", }; const char* synth_paths[] = { @@ -174,11 +183,23 @@ main(int argc, char *argv[]) "src/web.c", }; + const char *templates[] = { + "tmpl/index.html" + }; + B_Cmd cmd = {0}; b_mkdir_if_not_exists(BUILD_DIR); + b_mkdir_if_not_exists(TEMPLATE_DIR); + + if (!build_c(&cmd, (const char *[]){"src/tt.c"}, 1, NULL, 0, + BUILD_DIR "tt")) + return 1; + + if (!build_templates(&cmd, templates, B_ARRAY_LEN(templates))) + return 1; - if (!build_c(force, &cmd, synth_paths, B_ARRAY_LEN(synth_paths), synth_deps, + if (!build_c(&cmd, synth_paths, B_ARRAY_LEN(synth_paths), synth_deps, B_ARRAY_LEN(synth_deps), BUILD_DIR "synth")) return 1; -- cgit v1.2.3