#define NOB_IMPLEMENTATION #include #include #include "nob.h" #define BUILD_DIR "./build/" #define SRC_DIR "./src/" #define OBJDIR BUILD_DIR"obj/" #define LIB_DIR "./lib/" #define LIB_OUT LIB_DIR"libglc.a" Cmd ar_cmd = {0}; _Bool walk_dir_func(Nob_Walk_Entry e) { printf("Path: %s\n", e.path); if (e.type == NOB_FILE_REGULAR) { size_t input_len = strlen(e.path); if (input_len > 3) { if (strcmp(&e.path[input_len - 2], ".h") != 0) { Cmd cmd = {0}; String_Builder sb_out = {0}; String_View sv = {0}; char *path_cpy = strdup(e.path); sv = sv_from_cstr(path_cpy); size_t l = strlen(e.path); while (--l) { if (e.path[l] == '/') { sv_chop_left(&sv, l + 1); break ; } } printf("file_name: %s\n", sv.data); cmd_append(&cmd, "cc", "-c", "-static"); nob_cc_flags(&cmd); cmd_append(&cmd, "-o"); sb_append_cstr(&sb_out, OBJDIR); sb_append_cstr(&sb_out, sv.data); cmd_append(&cmd, sb_out.items); cmd_append(&cmd, strdup(path_cpy)); cmd_run(&cmd); cmd_append(&ar_cmd, strdup(sb_out.items)); memset(sb_out.items, 0, sb_out.count); sb_free(sb_out); } } } *e.action = NOB_WALK_CONT; return true; } int main(int argc, char **argv) { NOB_GO_REBUILD_URSELF(argc, argv); if (!nob_mkdir_if_not_exists(BUILD_DIR)) { nob_log(ERROR, "Failed to create %s: %s\n", BUILD_DIR, strerror(errno)); return 1; } if (!nob_mkdir_if_not_exists(OBJDIR)) { nob_log(ERROR, "Failed to create %s: %s\n", OBJDIR, strerror(errno)); return 1; } const char *bin_path = BUILD_DIR "main"; cmd_append(&ar_cmd, "ar", "rcs", LIB_OUT); nob_walk_dir(SRC_DIR, walk_dir_func, .post_order = true); cmd_run(&ar_cmd); nob_log(INFO, "Starting build...\n"); }