CXX := x86_64-elf-g++
CXXFLAGS ?= -O2
-CXXFLAGS := $(CXXFLAGS) -fno-strict-aliasing -Wall -Wextra -Werror -std=c++20 \
+CXXFLAGS := $(CXXFLAGS) -std=c++20 -fno-strict-aliasing -Wall -Wextra -Werror \
-mgeneral-regs-only -fno-exceptions -fno-rtti -ffreestanding
LDFLAGS ?= -O2
-LDFLAGS := $(LDFLAGS) -Wall -Wextra -Werror -std=c++20 -ffreestanding
+LDFLAGS := $(LDFLAGS) -std=c++20 -Wall -Wextra -Werror -ffreestanding
TO_ISO := isodir/boot/grub/grub.cfg
TO_CLEAN := isodir isos.iso
LOCAL_LDFLAGS := $(LDFLAGS) -T kernel/linker.ld -z max-page-size=0x1000 \
-mno-red-zone -mcmodel=kernel
-CPPOBJS := $(patsubst $(SRC_DIR)%,$(OUT_DIR)%.o,$(shell find $(SRC_DIR) -name '*.cpp'))
-ASMOBJS := $(patsubst $(SRC_DIR)%,$(OUT_DIR)%.o,$(shell find $(SRC_DIR) -name '*.S' | grep -v crt))
+CPPSRCS := $(shell find $(SRC_DIR) -name '*.cpp')
+CPPOBJS := $(CPPSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o)
+ASMSRCS := $(shell find $(SRC_DIR) -name '*.S' | grep -v crt)
+ASMOBJS := $(ASMSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o)
+
CRTI_OBJ := $(OUT_DIR)/lib/crti.S.o
CRTBEGIN_OBJ := $(shell $(CXX) $(LOCAL_LDFLAGS) -print-file-name=crtbegin.o)
CRTEND_OBJ := $(shell $(CXX) $(LOCAL_LDFLAGS) -print-file-name=crtend.o)
CRTN_OBJ := $(OUT_DIR)/lib/crtn.S.o
+
OBJS := $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(CPPOBJS) $(ASMOBJS) $(CRTEND_OBJ) $(CRTN_OBJ)
isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME)
LOCAL_CXXFLAGS := $(CXXFLAGS)
LOCAL_LDFLAGS := $(LDFLAGS)
-CPPOBJS := $(patsubst $(SRC_DIR)%,$(OUT_DIR)%.o,$(shell find $(SRC_DIR) -name '*.cpp'))
-ASMOBJS := $(patsubst $(SRC_DIR)%,$(OUT_DIR)%.o,$(shell find $(SRC_DIR) -name '*.S'))
+CPPSRCS := $(shell find $(SRC_DIR) -name '*.cpp')
+CPPOBJS := $(CPPSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o)
+ASMSRCS := $(shell find $(SRC_DIR) -name '*.S')
+ASMOBJS := $(ASMSRCS:$(SRC_DIR)%=$(OUT_DIR)%.o)
OBJS := $(CPPOBJS) $(ASMOBJS)
isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME)
$(OUT_DIR)$(EXEC_NAME): OBJS := $(OBJS)
$(OUT_DIR)$(EXEC_NAME): LDLIBS := -nostdlib -lgcc
$(OUT_DIR)$(EXEC_NAME): LDFLAGS := $(LOCAL_LDFLAGS)
-$(OUT_DIR)$(EXEC_NAME): $(OBJS) kernel/linker.ld
+$(OUT_DIR)$(EXEC_NAME): $(OBJS)
mkdir -p "$(@D)"
- $(CXX) $(LDFLAGS) -o "$@" $(OBJS) $(LDLIBS)
+ $(CXX) $(LDFLAGS) -o "$@" $+ $(LDLIBS)
$(OUT_DIR)%.o: DEP_DIR := $(DEP_DIR)
$(OUT_DIR)%.o: CXXFLAGS := $(LOCAL_CXXFLAGS)
mkdir -p $(dir $(DEP_DIR)$*)
$(CXX) $(CXXFLAGS) -c "$<" -MMD -MT "$@" -MF "$(DEP_DIR)$*.d" -o "$@"
+-include $(DEP_DIR)*.d