81 lines
1.9 KiB
C
81 lines
1.9 KiB
C
#define NOB_IMPLEMENTATION
|
|
#include "nob.h"
|
|
#include <stdbool.h>
|
|
|
|
#define BUILD_FOLDER "build/"
|
|
#define SRC_FOLDER "src/"
|
|
|
|
bool render_clangd_config(void) {
|
|
Nob_String_Builder tmpl = {0};
|
|
if (!nob_read_entire_file(".clangd.template", &tmpl))
|
|
return false;
|
|
nob_sb_append_null(&tmpl);
|
|
|
|
const char *include_path = getenv("I686_ELF_GCC_INCLUDE");
|
|
if (include_path == NULL) {
|
|
nob_log(NOB_ERROR, "I686_ELF_GCC_INCLUDE not set");
|
|
nob_sb_free(tmpl);
|
|
return false;
|
|
}
|
|
|
|
const char *needle = "${env:I686_ELF_GCC_INCLUDE}";
|
|
Nob_String_Builder out = {0};
|
|
|
|
const char *cursor = tmpl.items;
|
|
const char *found;
|
|
while ((found = strstr(cursor, needle)) != NULL) {
|
|
nob_sb_append_buf(&out, cursor, found - cursor);
|
|
nob_sb_append_cstr(&out, include_path);
|
|
cursor = found + strlen(needle);
|
|
}
|
|
nob_sb_append_cstr(&out, cursor);
|
|
|
|
bool ok = nob_write_entire_file(".clangd", out.items, out.count);
|
|
|
|
nob_sb_free(tmpl);
|
|
nob_sb_free(out);
|
|
return ok;
|
|
}
|
|
|
|
bool build_assembly(Nob_Cmd *cmd) {
|
|
nob_cmd_append(cmd, "i686-elf-as", "-o", BUILD_FOLDER "boot.o", SRC_FOLDER "boot.s");
|
|
if (!nob_cmd_run(cmd))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool build_c(Nob_Cmd *cmd) {
|
|
nob_cmd_append(cmd,
|
|
"i686-elf-gcc",
|
|
"-std=gnu99",
|
|
"-ffreestanding",
|
|
"-Wall",
|
|
"-Wextra",
|
|
"-O2",
|
|
"-o", BUILD_FOLDER "kernel.o",
|
|
"-c", SRC_FOLDER "kernel.c");
|
|
if (!nob_cmd_run(cmd))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
int main(int argc, char **argv) {
|
|
NOB_GO_REBUILD_URSELF(argc, argv);
|
|
|
|
if (!nob_mkdir_if_not_exists(BUILD_FOLDER))
|
|
return 1;
|
|
|
|
Nob_Cmd cmd = {0};
|
|
|
|
if (!render_clangd_config())
|
|
return 1;
|
|
if (!build_assembly(&cmd))
|
|
return 1;
|
|
if (!build_c(&cmd))
|
|
return 1;
|
|
|
|
return 0;
|
|
}
|