-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmakefile
More file actions
94 lines (78 loc) · 1.96 KB
/
makefile
File metadata and controls
94 lines (78 loc) · 1.96 KB
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
# mini-kernel Makefile
# Toolchain
CC = i686-elf-gcc
CXX = i686-elf-g++
AS = nasm
LD = i686-elf-ld
# Flags
CFLAGS = -m32 -ffreestanding -O2 -Wall -Wextra \
-fno-stack-protector -nostdlib -nostdinc \
-I kernel -I lib
CXXFLAGS = -m32 -ffreestanding -O2 -Wall -Wextra \
-fno-stack-protector -fno-exceptions -fno-rtti \
-fno-threadsafe-statics -fno-use-cxa-atexit \
-nostdlib -nostdinc -nostdinc++ \
-I kernel -I lib
ASFLAGS = -f elf32
LDFLAGS = -T linker.ld -m elf_i386 --nostdlib
# Output
TARGET = mykernel.bin
ISO = mykernel.iso
# Source files — order matters for linking
C_SRCS :=
C_SRCS += kernel/main.c
C_SRCS += kernel/panic.c
C_SRCS += kernel/shell.c
C_SRCS += kernel/cpp_runtime.c
C_SRCS += drivers/vga.c
C_SRCS += drivers/keyboard.c
C_SRCS += drivers/timer.c
C_SRCS += cpu/gdt.c
C_SRCS += cpu/idt.c
C_SRCS += cpu/isr.c
C_SRCS += cpu/irq.c
C_SRCS += mm/kmalloc.c
C_SRCS += mm/paging.c
C_SRCS += mm/pmm.c
C_SRCS += lib/string.c
C_SRCS += lib/kprintf.c
C_SRCS += lib/ports.c
ASM_SRCS :=
ASM_SRCS += boot/boot.asm
ASM_SRCS += boot/kernel_entry.asm
ASM_SRCS += cpu/tables_flush.asm
# Optional C++ sources (keep empty unless you add .cpp files)
CPP_SRCS :=
# CPP_SRCS += kernel/example.cpp
# Object files
C_OBJS = $(C_SRCS:.c=.o)
CPP_OBJS = $(CPP_SRCS:.cpp=.o)
ASM_OBJS = $(ASM_SRCS:.asm=.o)
OBJS = $(ASM_OBJS) $(C_OBJS) $(CPP_OBJS)
# Default target
.PHONY: all clean iso run
all: $(TARGET)
# Link
$(TARGET): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
# Compile C
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
# Compile C++
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@
# Assemble
%.o: %.asm
$(AS) $(ASFLAGS) $< -o $@
# Build bootable ISO with GRUB
iso: $(TARGET)
mkdir -p isodir/boot/grub
cp $(TARGET) isodir/boot/$(TARGET)
cp grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o $(ISO) isodir
# Run in QEMU
run: iso
qemu-system-i386 -cdrom $(ISO)
clean:
rm -f $(OBJS) $(TARGET) $(ISO)
rm -rf isodir