-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
56 lines (45 loc) · 1.43 KB
/
Makefile
File metadata and controls
56 lines (45 loc) · 1.43 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
ASM=nasm
SRC_DIR=src
BUILD_DIR=build
CC_PATH=/home/logan/opt/cross/bin
CC=$(CC_PATH)/i686-elf-gcc
ACC=$(CC_PATH)/i686-elf-as
# Find all .c files
C_SOURCES = $(shell find $(SRC_DIR) -name '*.c')
# Convert src/path/file.c -> build/path/file.o
OBJ = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(C_SOURCES))
#
# Find all .asm files
ASM_SOURCES = $(shell find $(SRC_DIR) -name '*.asm')
# Convert src/path/file.asm -> build/path/file.o
ASM_OBJ = $(patsubst $(SRC_DIR)/%.asm, $(BUILD_DIR)/%.o, $(ASM_SOURCES))
# Add the boot object
ALL_OBJECTS = $(OBJ) $(ASM_OBJ) $(BUILD_DIR)/boot.o
run: kernel.iso
qemu-system-i386 -serial stdio -cdrom kernel.iso
# Build the ISO
# Note: We now depend on kernel.bin, but we can copy it to isodir as just "kernel"
kernel.iso: $(BUILD_DIR)/kernel.bin
mkdir -p isodir/boot/grub
cp $(BUILD_DIR)/kernel.bin isodir/boot/kernel
cp grub.cfg isodir/boot/grub/grub.cfg
grub-mkrescue -o kernel.iso isodir
# Linker Rule
$(BUILD_DIR)/kernel.bin: $(ALL_OBJECTS)
$(CC) -T $(SRC_DIR)/boot/linker.ld -o $@ -ffreestanding -O2 -nostdlib $^ -lgcc
# Compilation Rule
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(dir $@)
$(CC) -c $< -o $@ -std=gnu99 -ffreestanding -O2 -Wall -Wextra
# Assembly Rule
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.asm
@mkdir -p $(dir $@)
$(ASM) -f elf32 $< -o $@
# Boot Rule
$(BUILD_DIR)/boot.o: $(SRC_DIR)/boot/boot.s
@mkdir -p $(BUILD_DIR)
$(ACC) $< -o $@
clean:
rm -rf $(BUILD_DIR)/*
rm -rf isodir
rm -f kernel.iso