]> git.ameliathe1st.gay Git - voyage-au-centre-des-fichiers.git/commitdiff
Restructured build system, to allow for easier adding of separate programs later
authorAmelia Coutard <eliottulio.coutard@gmail.com>
Thu, 13 Oct 2022 23:17:24 +0000 (01:17 +0200)
committerAmelia Coutard <eliottulio.coutard@gmail.com>
Thu, 13 Oct 2022 23:17:24 +0000 (01:17 +0200)
22 files changed:
.gitignore
Makefile
kernel/linker.ld [moved from linker.ld with 100% similarity]
kernel/module.mk [new file with mode: 0644]
kernel/src/boot.S [moved from src/boot.S with 100% similarity]
kernel/src/crti.S [moved from src/crti.S with 100% similarity]
kernel/src/crtn.S [moved from src/crtn.S with 100% similarity]
kernel/src/interrupts.S [moved from src/interrupts.S with 100% similarity]
kernel/src/interrupts.cpp [moved from src/interrupts.cpp with 100% similarity]
kernel/src/interrupts.hpp [moved from src/interrupts.hpp with 100% similarity]
kernel/src/kernel.cpp [moved from src/kernel.cpp with 100% similarity]
kernel/src/multiboot2.hpp [moved from src/multiboot2.hpp with 100% similarity]
kernel/src/paging.cpp [moved from src/paging.cpp with 100% similarity]
kernel/src/paging.hpp [moved from src/paging.hpp with 100% similarity]
kernel/src/phys_ptr.hpp [moved from src/phys_ptr.hpp with 100% similarity]
kernel/src/ring3.S [moved from src/ring3.S with 100% similarity]
kernel/src/ring3.cpp [moved from src/ring3.cpp with 100% similarity]
kernel/src/ring3.hpp [moved from src/ring3.hpp with 100% similarity]
kernel/src/serial.cpp [moved from src/serial.cpp with 100% similarity]
kernel/src/serial.hpp [moved from src/serial.hpp with 100% similarity]
kernel/src/utils.cpp [moved from src/utils.cpp with 100% similarity]
kernel/src/utils.hpp [moved from src/utils.hpp with 100% similarity]

index a701a8ff8514d2fcaee474fc8100ea14bcebeb6d..60ebeb11e77e8f29ac24daea46b2f8c0cd17c2e8 100644 (file)
@@ -1,4 +1,4 @@
 out
-deps
+dep
 isodir
-doxygen
+amycros.iso
index 63b12d667940e8d29cf40e720d3bb33ce20d7265..5b2df7f154c1f5827c8ca71060fe0b3b1b9e9dc6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,50 +1,33 @@
+# Written in 2022 by Amélia COUTARD <eliottulio.coutard@gmail.com>
+# To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this file to the public domain worldwide. This file is distributed without any warranty.
+# You should have received a copy of the CC0 Public Domain Dedication along with this file. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+# So, about the license. I don't think I have a copyright on this file's code, but,
+# since I gave it the CC0 license in case I do, that doesn't matter either way.
+
 .PHONY: build qemu clean
 
-OUT_DIR ?= out/
-SRC_DIR ?= src/
-DEPS_DIR ?= deps/
+build: # Build as default target
 
 CXX := x86_64-elf-g++
 CXXFLAGS ?= -O2
 CXXFLAGS := $(CXXFLAGS) -Wall -Wextra -Werror -std=c++20 \
-       -ffreestanding -mcmodel=kernel -mno-red-zone -mno-mmx -mno-sse -mno-sse2 -fno-exceptions -fno-rtti \
-       -isystem /usr/include -isystem /usr/include/c++/12.2.0 -isystem /usr/include/c++/12.2.0/x86_64-pc-linux-gnu
-
+            -mno-mmx -mno-sse -mno-sse2 -fno-exceptions -fno-rtti -ffreestanding
 LDFLAGS ?= -O2
-LDFLAGS := $(LDFLAGS) -Wall -Wextra -Werror -std=c++20 \
-       -ffreestanding -T linker.ld -z max-page-size=0x1000 \
-       -mno-red-zone -mcmodel=kernel # Normally has no effect, but is used to change the multilib libgcc, to use mcmodel=kernel and be able to use global constructors and destructors.
-LDLIBS := $(LDLIBS) -nostdlib -lgcc
-
-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' -and -not -name 'crti.S' -and -not -name 'crtn.S'))
-OBJECTS := $(CPPOBJS) $(ASMOBJS)
-CRTI_OBJ := $(OUT_DIR)crti.S.o
-CRTBEGIN_OBJ := $(shell $(CXX) $(LDFLAGS) -print-file-name=crtbegin.o)
-CRTEND_OBJ := $(shell $(CXX) $(LDFLAGS) -print-file-name=crtend.o)
-CRTN_OBJ := $(OUT_DIR)crtn.S.o
-
-build: $(OUT_DIR)amycros.iso
-qemu: build
-       qemu-system-x86_64 -cdrom $(OUT_DIR)amycros.iso -serial stdio -cpu qemu64,pdpe1gb -no-reboot $(QEMUFLAGS)
+LDFLAGS := $(LDFLAGS) -Wall -Wextra -Werror -std=c++20 -ffreestanding
 
-$(OUT_DIR)amycros.iso: $(OUT_DIR)kernel.elf64 grub.cfg
-       mkdir -p isodir/boot/grub
-       cp $(OUT_DIR)kernel.elf64 isodir/boot
-       cp grub.cfg isodir/boot/grub
-       grub-mkrescue -o "$@" isodir
+TO_ISO :=
+TO_CLEAN :=
 
-clean:
-       -rm -rf $(DEPS_DIR) $(OUT_DIR) isodir
+include */module.mk
 
+build: amycros.iso
+qemu: build
+       qemu-system-x86_64 -cdrom amycros.iso -serial stdio -cpu qemu64,pdpe1gb -no-reboot $(QEMUFLAGS)
+clean:
+       -rm -rf $(TO_CLEAN) isodir amycros.iso
 
-$(OUT_DIR)kernel.elf64: $(OBJECTS) $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(CRTEND_OBJ) $(CRTN_OBJ) linker.ld
-       mkdir -p $(OUT_DIR)
-       $(CXX) $(LDFLAGS) -o "$@" $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OBJECTS) $(CRTEND_OBJ) $(CRTN_OBJ) $(LDLIBS)
-
-$(OUT_DIR)%.o: $(SRC_DIR)%
-       mkdir -p $(@D)
-       mkdir -p $(dir $(DEPS_DIR)$*)
-       $(CXX) $(CXXFLAGS) -c "$<" -MMD -MT "$@" -MF "$(DEPS_DIR)$*.d" -o "$@"
-
--include deps/*.d
+amycros.iso: $(TO_ISO) grub.cfg
+       mkdir -p isodir/boot/grub
+       install -m 644 grub.cfg isodir/boot/grub/grub.cfg
+       grub-mkrescue -o "$@" isodir
similarity index 100%
rename from linker.ld
rename to kernel/linker.ld
diff --git a/kernel/module.mk b/kernel/module.mk
new file mode 100644 (file)
index 0000000..eefe87c
--- /dev/null
@@ -0,0 +1,55 @@
+# Written in 2022 by Amélia COUTARD <eliottulio.coutard@gmail.com>
+# To the extent possible under law, the author(s) have dedicated all copyright and related and neighboring rights to this file to the public domain worldwide. This file is distributed without any warranty.
+# You should have received a copy of the CC0 Public Domain Dedication along with this file. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
+
+# So, about the license. I don't think I have a copyright on this file's code, but,
+# since I gave it the CC0 license in case I do, that doesn't matter either way.
+
+SRC_DIR := kernel/src/
+OUT_DIR := kernel/out/
+DEP_DIR := kernel/dep/
+EXEC_NAME := kernel.elf64
+
+TO_ISO   += isodir/boot/$(EXEC_NAME)
+TO_CLEAN += $(OUT_DIR) $(DEP_DIR)
+
+OLD_CXXFLAGS := $(CXXFLAGS)
+OLD_LDFLAGS := $(LDFLAGS)
+CXXFLAGS := $(OLD_CXXFLAGS) -mcmodel=kernel -mno-red-zone \
+       -isystem /usr/include -isystem /usr/include/c++/12.2.0 \
+       -isystem /usr/include/c++/12.2.0/x86_64-pc-linux-gnu
+       # The previous two lines are a dirty hack.
+LDFLAGS := $(OLD_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))
+CRTI_OBJ     := $(OUT_DIR)crti.S.o
+CRTBEGIN_OBJ := $(shell $(CXX) $(LDFLAGS) -print-file-name=crtbegin.o)
+CRTEND_OBJ   := $(shell $(CXX) $(LDFLAGS) -print-file-name=crtend.o)
+CRTN_OBJ     := $(OUT_DIR)crtn.S.o
+OBJS := $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(CPPOBJS) $(ASMOBJS) $(CRTEND_OBJ) $(CRTN_OBJ)
+
+isodir/boot/$(EXEC_NAME): $(OUT_DIR)$(EXEC_NAME)
+       mkdir -p "$(@D)"
+       install -m 644 "$<" "$@"
+
+$(OUT_DIR)$(EXEC_NAME): OBJS := $(OBJS)
+$(OUT_DIR)$(EXEC_NAME): LDLIBS := -nostdlib -lgcc
+$(OUT_DIR)$(EXEC_NAME): LDFLAGS := $(LDFLAGS)
+$(OUT_DIR)$(EXEC_NAME): $(OBJS) kernel/linker.ld
+       mkdir -p "$(@D)"
+       $(CXX) $(LDFLAGS) -o "$@" $(OBJS) $(LDLIBS)
+
+
+$(OUT_DIR)%.o: DEP_DIR := $(DEP_DIR)
+$(OUT_DIR)%.o: CXXFLAGS := $(CXXFLAGS)
+$(OUT_DIR)%.o: $(SRC_DIR)%
+       mkdir -p $(@D)
+       mkdir -p $(dir $(DEP_DIR)$*)
+       $(CXX) $(CXXFLAGS) -c "$<" -MMD -MT "$@" -MF "$(DEP_DIR)$*.d" -o "$@"
+
+-include $(DEPS_DIR)*.d
+
+CXXFLAGS := $(OLD_CXXFLAGS)
+LDFLAGS := $(OLD_LDFLAGS)
similarity index 100%
rename from src/boot.S
rename to kernel/src/boot.S
similarity index 100%
rename from src/crti.S
rename to kernel/src/crti.S
similarity index 100%
rename from src/crtn.S
rename to kernel/src/crtn.S
similarity index 100%
rename from src/interrupts.S
rename to kernel/src/interrupts.S
similarity index 100%
rename from src/interrupts.cpp
rename to kernel/src/interrupts.cpp
similarity index 100%
rename from src/interrupts.hpp
rename to kernel/src/interrupts.hpp
similarity index 100%
rename from src/kernel.cpp
rename to kernel/src/kernel.cpp
similarity index 100%
rename from src/multiboot2.hpp
rename to kernel/src/multiboot2.hpp
similarity index 100%
rename from src/paging.cpp
rename to kernel/src/paging.cpp
similarity index 100%
rename from src/paging.hpp
rename to kernel/src/paging.hpp
similarity index 100%
rename from src/phys_ptr.hpp
rename to kernel/src/phys_ptr.hpp
similarity index 100%
rename from src/ring3.S
rename to kernel/src/ring3.S
similarity index 100%
rename from src/ring3.cpp
rename to kernel/src/ring3.cpp
similarity index 100%
rename from src/ring3.hpp
rename to kernel/src/ring3.hpp
similarity index 100%
rename from src/serial.cpp
rename to kernel/src/serial.cpp
similarity index 100%
rename from src/serial.hpp
rename to kernel/src/serial.hpp
similarity index 100%
rename from src/utils.cpp
rename to kernel/src/utils.cpp
similarity index 100%
rename from src/utils.hpp
rename to kernel/src/utils.hpp