From cf9058e70afad523f85e7635cfbcf0802b416e5b Mon Sep 17 00:00:00 2001 From: ImagineHaxing Date: Tue, 25 Aug 2026 20:10:52 +0300 Subject: [PATCH] Make it rebuild only when something changes --- nob.c | 29 +++++++++++++++++++++++++++++ src/kernel.c | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nob.c b/nob.c index 653356c..1c3c8c8 100644 --- a/nob.c +++ b/nob.c @@ -38,6 +38,13 @@ bool render_clangd_config(void) { } bool build_assembly(Nob_Cmd *cmd) { + const char *output = BUILD_FOLDER "boot.o"; + const char *input = SRC_FOLDER "boot.s"; + int rebuild = nob_needs_rebuild1(output, input); + + if (!rebuild) + return true; + nob_cmd_append(cmd, "i686-elf-as", "-o", BUILD_FOLDER "boot.o", SRC_FOLDER "boot.s"); if (!nob_cmd_run(cmd)) return false; @@ -46,6 +53,13 @@ bool build_assembly(Nob_Cmd *cmd) { } bool build_c(Nob_Cmd *cmd) { + const char *output = BUILD_FOLDER "kernel.o"; + const char *input = SRC_FOLDER "kernel.c"; + int rebuild = nob_needs_rebuild1(output, input); + + if (!rebuild) + return true; + nob_cmd_append(cmd, "i686-elf-gcc", "-std=gnu99", @@ -62,6 +76,13 @@ bool build_c(Nob_Cmd *cmd) { } bool link_everything(Nob_Cmd *cmd) { + const char *output = BUILD_FOLDER "kernel"; + const char *input[] = {SRC_FOLDER "linker.ld", BUILD_FOLDER "kernel.o", BUILD_FOLDER "boot.o"}; + int rebuild = nob_needs_rebuild(output, input, NOB_ARRAY_LEN(input)); + + if (!rebuild) + return true; + Nob_File_Paths objectFiles = {0}; nob_da_append(&objectFiles, BUILD_FOLDER "kernel.o"); nob_da_append(&objectFiles, BUILD_FOLDER "boot.o"); @@ -73,6 +94,7 @@ bool link_everything(Nob_Cmd *cmd) { "-O2", "-nostdlib"); + // Add objectFiles as input for (size_t i = 0; i < objectFiles.count; ++i) { nob_cmd_append(cmd, objectFiles.items[i]); } @@ -116,6 +138,13 @@ bool clean_dir(const char *dir_path) { } bool build_bootable_image(Nob_Cmd *cmd) { + const char *output = BUILD_FOLDER "kernel.iso"; + const char *input[] = {BUILD_FOLDER "kernel", SRC_FOLDER "grub.cfg"}; + int rebuild = nob_needs_rebuild(output, input, NOB_ARRAY_LEN(input)); + + if (!rebuild) + return true; + if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir")) return false; if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir/boot")) diff --git a/src/kernel.c b/src/kernel.c index 40abccb..d1ba8a0 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -101,5 +101,5 @@ void kernel_main(void) { terminal_initialize(); /* Newline support is left as an exercise. */ - terminal_writestring("Hello, kernel World!\n"); + terminal_writestring("Hello world from kernel.\n"); }