Make it rebuild only when something changes

This commit is contained in:
2026-08-25 20:10:52 +03:00
parent d8c5492e6c
commit cf9058e70a
2 changed files with 30 additions and 1 deletions
+29
View File
@@ -38,6 +38,13 @@ bool render_clangd_config(void) {
} }
bool build_assembly(Nob_Cmd *cmd) { 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"); nob_cmd_append(cmd, "i686-elf-as", "-o", BUILD_FOLDER "boot.o", SRC_FOLDER "boot.s");
if (!nob_cmd_run(cmd)) if (!nob_cmd_run(cmd))
return false; return false;
@@ -46,6 +53,13 @@ bool build_assembly(Nob_Cmd *cmd) {
} }
bool build_c(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, nob_cmd_append(cmd,
"i686-elf-gcc", "i686-elf-gcc",
"-std=gnu99", "-std=gnu99",
@@ -62,6 +76,13 @@ bool build_c(Nob_Cmd *cmd) {
} }
bool link_everything(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_File_Paths objectFiles = {0};
nob_da_append(&objectFiles, BUILD_FOLDER "kernel.o"); nob_da_append(&objectFiles, BUILD_FOLDER "kernel.o");
nob_da_append(&objectFiles, BUILD_FOLDER "boot.o"); nob_da_append(&objectFiles, BUILD_FOLDER "boot.o");
@@ -73,6 +94,7 @@ bool link_everything(Nob_Cmd *cmd) {
"-O2", "-O2",
"-nostdlib"); "-nostdlib");
// Add objectFiles as input
for (size_t i = 0; i < objectFiles.count; ++i) { for (size_t i = 0; i < objectFiles.count; ++i) {
nob_cmd_append(cmd, objectFiles.items[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) { 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")) if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir"))
return false; return false;
if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir/boot")) if (!nob_mkdir_if_not_exists(BUILD_FOLDER "isodir/boot"))
+1 -1
View File
@@ -101,5 +101,5 @@ void kernel_main(void) {
terminal_initialize(); terminal_initialize();
/* Newline support is left as an exercise. */ /* Newline support is left as an exercise. */
terminal_writestring("Hello, kernel World!\n"); terminal_writestring("Hello world from kernel.\n");
} }