-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
110 lines (79 loc) · 3.22 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
OSNAME = MatesOS2
LDS = kernel/kernel.ld
CC = gcc
ASMC = nasm
LD = ld
CFLAGS = -ffreestanding -fshort-wchar -mno-red-zone -fno-exceptions -Wall -Wfatal-errors -fno-stack-protector -Iinclude -fno-use-cxa-atexit -fno-builtin -fno-rtti -fno-exceptions -fno-leading-underscore -Wno-write-strings -fzero-initialized-in-bss
ASMFLAGS =
LDFLAGS = -T $(LDS) -static -Bsymbolic -nostdlib
SRCDIR := kernel/src
OBJDIR := kernel/obj
BUILDDIR := kernel/bin
ISO_IMAGE := $(OSNAME).iso
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
SRC = $(call rwildcard,$(SRCDIR),*.cpp)
ASMSRC = $(call rwildcard,$(SRCDIR),*.asm)
OBJS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SRC))
OBJS += $(patsubst $(SRCDIR)/%.asm, $(OBJDIR)/%_asm.o, $(ASMSRC))
.PHONY: debug clean $(ISO_IMAGE) init clean_kernel run run_debug run_efi
all: $(ISO_IMAGE)
init:
sudo apt-get install gcc nasm gdb qemu qemu-system ovmf xorriso ovmf
debug: CFLAGS += -g
debug: clean_kernel kernel
kernel: $(BUILDDIR)/kernel.elf
rebuildkernel: clean_kernel kernel
limine:
git clone https://github.com/limine-bootloader/limine.git --branch=v2.4-binary --depth=1
$(MAKE) -C limine
image: $(ISO_IMAGE)
$(ISO_IMAGE): limine kernel
rm -rf iso_root
mkdir -p iso_root
mkdir -p iso_root/boot
mkdir -p iso_root/static_data
cp limine.cfg limine/limine.sys limine/limine-cd.bin limine/limine-eltorito-efi.bin startup.nsh iso_root/
cp -rf static_data/* iso_root/static_data/
cp $(BUILDDIR)/kernel.elf limine/BOOTX64.EFI iso_root/boot/
xorriso -as mkisofs -b limine-cd.bin \
-no-emul-boot -boot-load-size 4 -boot-info-table \
--efi-boot limine-eltorito-efi.bin \
-efi-boot-part --efi-boot-image --protective-msdos-label \
iso_root -o $(ISO_IMAGE)
limine/limine-install $(ISO_IMAGE)
rm -rf iso_root
run: image
qemu-system-x86_64 -M q35 -m 2G -cdrom $(ISO_IMAGE) -serial pty -serial pty -monitor stdio
run_efi: image
qemu-system-x86_64 -machine q35 -cdrom $(ISO_IMAGE) -m 2G -bios /usr/share/ovmf/OVMF.fd -serial pty -serial pty -monitor stdio
run_debug: debug image
qemu-system-x86_64 -s -S -M q35 -m 2G -cdrom $(ISO_IMAGE) -serial pty -monitor stdio
run_efi_debug: debug image
qemu-system-x86_64 -s -S -machine q35 -cdrom $(ISO_IMAGE) -m 2G -bios /usr/share/ovmf/OVMF.fd -serial pty -serial pty -monitor stdio
clean_kernel:
rm -rf $(BUILDDIR)
rm -rf $(OBJDIR)
clean: clean_kernel
rm -rf limine
rm -rf $(ISO_IMAGE)
$(OBJDIR)/interrupts/interrupt_handlers.o: $(SRCDIR)/interrupts/interrupt_handlers.cpp | $(OBJDIR)
@ echo !======= COMPILING $^
@ mkdir -p $(@D)
$(CC) -mno-red-zone -mgeneral-regs-only -ffreestanding -c $^ -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp | $(OBJDIR)
@ echo !======= COMPILING $^
@ mkdir -p $(@D)
$(CC) $(CFLAGS) -c $^ -o $@
$(OBJDIR)/%_asm.o: $(SRCDIR)/%.asm | $(OBJDIR)
@ echo !======= COMPILING $^
@ mkdir -p $(@D)
$(ASMC) $(ASMFLAGS) $^ -f elf64 -o $@
$(BUILDDIR)/kernel.elf: $(OBJS) | $(BUILDDIR)
@ echo !======= LINKING $^
$(LD) $(LDFLAGS) -o $(BUILDDIR)/kernel.elf $(OBJS)
$(BUILDDIR):
@echo !======= Creating build directory
@mkdir $(BUILDDIR)
$(OBJDIR):
@echo !======= Creating build object
@mkdir $(OBJDIR)