Make clangd work with toolchain's headers
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
CompileFlags:
|
||||
Compiler: i686-elf-gcc
|
||||
Add:
|
||||
- "-target"
|
||||
- "i686-elf"
|
||||
- "-ffreestanding"
|
||||
- "-nostdlibinc"
|
||||
- "-isystem"
|
||||
- "${env:I686_ELF_GCC_INCLUDE}"
|
||||
+2
-1
@@ -139,4 +139,5 @@ dkms.conf
|
||||
|
||||
build/
|
||||
nob
|
||||
nob.old
|
||||
nob.old
|
||||
.clangd
|
||||
@@ -1,9 +1,66 @@
|
||||
#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);
|
||||
|
||||
@@ -12,12 +69,11 @@ int main(int argc, char **argv) {
|
||||
|
||||
Nob_Cmd cmd = {0};
|
||||
|
||||
nob_cmd_append(&cmd, "i686-elf-as", "-o", BUILD_FOLDER "boot.o", SRC_FOLDER "boot.s");
|
||||
if (!nob_cmd_run(&cmd))
|
||||
if (!render_clangd_config())
|
||||
return 1;
|
||||
|
||||
nob_cmd_append(&cmd, "i686-elf-gcc", "-Wall", "-Wextra", "-o", BUILD_FOLDER "kernel", SRC_FOLDER "kernel.c");
|
||||
if (!nob_cmd_run(&cmd))
|
||||
if (!build_assembly(&cmd))
|
||||
return 1;
|
||||
if (!build_c(&cmd))
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -7,4 +7,8 @@ pkgs.mkShell {
|
||||
pkgsCross.i686-embedded.buildPackages.binutils
|
||||
gdb
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
export I686_ELF_GCC_INCLUDE="${pkgs.pkgsCross.i686-embedded.buildPackages.gcc.cc}/lib/gcc/i686-elf/${pkgs.pkgsCross.i686-embedded.buildPackages.gcc.version}/include"
|
||||
'';
|
||||
}
|
||||
|
||||
+13
-3
@@ -1,6 +1,16 @@
|
||||
#include "stdio.h"
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__linux__)
|
||||
#error "Not using a cross compiler"
|
||||
#endif
|
||||
|
||||
#if !defined(__i386__)
|
||||
#error "Not using the right compiler"
|
||||
#endif
|
||||
|
||||
int main() {
|
||||
printf("Hello, world!\n");
|
||||
return 0;
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user