From 4e84a5e6ee64e7f355257190915ef44d0320168e Mon Sep 17 00:00:00 2001 From: Amelia Coutard Date: Thu, 15 Jun 2023 04:33:36 +0200 Subject: [PATCH] Modified build system a bit, to fix mistakes and simplify it. Only very small changes --- Makefile | 4 ++-- kernel/module.mk | 8 ++++++-- test_module/module.mk | 11 +++++++---- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4ea3471..baf0912 100644 --- a/Makefile +++ b/Makefile @@ -14,10 +14,10 @@ build: # Build as default target 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 diff --git a/kernel/module.mk b/kernel/module.mk index fc1afbf..579083d 100644 --- a/kernel/module.mk +++ b/kernel/module.mk @@ -23,12 +23,16 @@ LOCAL_CXXFLAGS := $(CXXFLAGS) -mcmodel=kernel -mno-red-zone \ 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) diff --git a/test_module/module.mk b/test_module/module.mk index 6b0e124..194a4f0 100644 --- a/test_module/module.mk +++ b/test_module/module.mk @@ -19,8 +19,10 @@ TO_CLEAN += $(OUT_DIR) $(DEP_DIR) 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) @@ -30,9 +32,9 @@ 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) @@ -41,3 +43,4 @@ $(OUT_DIR)%.o: $(SRC_DIR)% mkdir -p $(dir $(DEP_DIR)$*) $(CXX) $(CXXFLAGS) -c "$<" -MMD -MT "$@" -MF "$(DEP_DIR)$*.d" -o "$@" +-include $(DEP_DIR)*.d -- 2.47.0