From 0e1595330211351823e68691fca013bb47772aeb Mon Sep 17 00:00:00 2001
From: 3gg <3gg@shellblade.net>
Date: Sat, 8 Feb 2025 15:05:52 -0800
Subject: Track changes to header files.

---
 Makefile | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

(limited to 'Makefile')

diff --git a/Makefile b/Makefile
index 7478d63..d3f0121 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,12 @@
+TOOLCHAIN     := $(HOME)/bin/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-elf
+TOOLCHAIN_BIN := $(TOOLCHAIN)/bin
+TOOLCHAIN_LIB := $(TOOLCHAIN)/lib/gcc/aarch64-none-elf/14.2.1/include
+
+AS      := $(TOOLCHAIN_BIN)/aarch64-none-elf-as
+CC      := $(TOOLCHAIN_BIN)/aarch64-none-elf-gcc
+LD      := $(TOOLCHAIN_BIN)/aarch64-none-elf-ld
+OBJCOPY := $(TOOLCHAIN_BIN)/aarch64-none-elf-objcopy
+
 SRC_DIR   := src
 BUILD_DIR := build
 OBJ_DIR   := $(BUILD_DIR)
@@ -8,20 +17,15 @@ ELF := $(BIN_DIR)/kernel8.elf
 
 SRC     := $(wildcard $(SRC_DIR)/*.c)
 OBJ     := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
+DEP     := $(SRC:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.d)
 ASM_SRC := $(wildcard $(SRC_DIR)/*.s)
 ASM_OBJ := $(ASM_SRC:$(SRC_DIR)/%.s=$(OBJ_DIR)/%.o)
 LINK    := $(SRC_DIR)/link.ld
 
-CPPFLAGS := -I$(SRC_DIR) -MMD -MP
+CPPFLAGS := -MMD -MP -I$(TOOLCHAIN_LIB) -I$(SRC_DIR)
 CFLAGS   := -Wall -Wextra -O2 -ffreestanding -nostdinc -nostdlib -nostartfiles
 LDFLAGS  := -nostdlib
 
-TOOLCHAIN := $(HOME)/bin/arm-gnu-toolchain-14.2.rel1-x86_64-aarch64-none-elf/bin
-AS        := $(TOOLCHAIN)/aarch64-none-elf-as
-CC        := $(TOOLCHAIN)/aarch64-none-elf-gcc
-LD        := $(TOOLCHAIN)/aarch64-none-elf-ld
-OBJCOPY   := $(TOOLCHAIN)/aarch64-none-elf-objcopy
-
 .PHONY: all clean
 
 all: $(IMG)
@@ -36,7 +40,7 @@ $(ELF): $(OBJ) $(ASM_OBJ) | $(BIN_DIR)
 
 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
 	@echo Building $< "->" $@
-	$(CC) $(CFLAGS) -c $< -o $@
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
 
 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.s | $(BUILD_DIR)
 	@echo Building $< "->" $@
@@ -51,3 +55,5 @@ $(BUILD_DIR):
 $(BIN_DIR):
 	mkdir -p $(BIN_DIR)
 
+-include $(DEP)
+
-- 
cgit v1.2.3