-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
44 lines (32 loc) · 1.32 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
C_SRCS = $(wildcard $(KERNEL_DIR)*.c) $(wildcard $(DRIVERS_DIR)*.c) $(wildcard $(LIBS_DIR)*.c) $(wildcard $(INT_DIR)*.c) $(wildcard $(PAGING_DIR)*.c)
HDRS = $(wildcard $(KERNEL_DIR)*.h) $(wildcard $(DRIVERS_DIR)*.h) $(wildcard $(LIBS_DIR)*.h) $(wildcard $(INT_DIR)*.h) $(wildcard $(PAGING_DIR)*.h)
OBJS = $(C_SRCS:%.c=%.o) $(INT_DIR)interrupts.o $(KERNEL_DIR)kernel_entry.o
BOOT_DIR = src/boot/
KERNEL_DIR = src/kernel/
DRIVERS_DIR = src/drivers/
PAGING_DIR = src/paging/
INT_DIR = src/interrupts/
LIBS_DIR = src/libs/
BIN_DIR = bin/
GDB = gdb
CC = gcc
CFLAGS = -g -ffreestanding -Wall -Wextra -fno-exceptions -m32 -fno-pie
os-image.bin: $(BIN_DIR)boot_sect.bin $(BIN_DIR)kernel.bin
cat $^ > os-image.bin
kernel.elf: $(OBJS)
ld -m elf_i386 -o $@ -Ttext 0x1000 $^
$(BIN_DIR)boot_sect.bin: $(BOOT_DIR)*.asm
nasm -I $(BOOT_DIR) $(BOOT_DIR)boot_sect.asm -f bin -o $@
$(BIN_DIR)kernel.bin: $(OBJS)
ld -m elf_i386 -o $@ -Ttext 0x1000 $^ --oformat binary
%.o: %.c $(HDRS)
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.asm
nasm $< -f elf -o $@
debug: os-image.bin kernel.elf
qemu-system-i386 -s -fda os-image.bin &
${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
clean:
rm -rf $(BIN_DIR)*.bin os-image.bin
rm -rf $(KERNEL_DIR)*.o $(DRIVERS_DIR)*.o $(INT_DIR)*.o $(LIBS_DIR)*.o $(BOOT_DIR)*.o $(PAGING_DIR)*.o
rm -rf kernel.elf