-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
58 lines (43 loc) · 1.15 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
# Compiler and flags
CC = aarch64-none-linux-gnu-gcc
LD = aarch64-none-linux-gnu-ld
OBJCOPY = aarch64-none-linux-gnu-objcopy
OBJDUMP = aarch64-none-linux-gnu-objdump
QEMU = qemu-system-aarch64
GDB = aarch64-none-linux-gnu-gdb
# Directories
SRC_DIR = src
INC_DIR = include
OBJ_DIR = obj
# Source files
SRC = $(wildcard $(SRC_DIR)/*.c)
# Object files
OBJ = $(patsubst $(SRC_DIR)/%.c, $(OBJ_DIR)/%.o, $(SRC))
# Kernel binary
KERNEL = kernel8.img
# Linker script
LINKER_SCRIPT = linker.ld
# Include flags
INC_FLAGS = -I$(INC_DIR)
# Default target
all: $(KERNEL)
# Rule to create object files from source files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(INC_FLAGS) -nostartfiles -c $< -o $@
$(OBJ_DIR):
mkdir $@
# Rule to link object files into kernel binary
$(KERNEL): $(OBJ_DIR) $(OBJ)
$(LD) -T $(LINKER_SCRIPT) -o kernel8.elf $(OBJ)
$(OBJCOPY) -O binary kernel8.elf $@
# Rule to display assembly using objdump
objdump:
$(OBJDUMP) -D kernel8.elf
# Rule to run QEMU
qemu:
$(QEMU) -M raspi3b -kernel kernel8.img -display none -serial null -serial stdio -S -s
# Rule to debug with GDB
gdb:
$(GDB)
clean:
rm -rf $(OBJ) kernel8.elf $(KERNEL) $(OBJ_DIR)