-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (52 loc) · 1.87 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
AUXFILES := Makefile
PROJDIRS := src
ASM_SRCFILES := $(shell find $(PROJDIRS) -type f -name "*.s")
C_SRCFILES := $(shell find $(PROJDIRS) -type f -name "*.c")
SRCFILES := $(ASM_SRCFILES) $(C_SRCFILES)
HDRFILES := $(shell find $(PROJDIRS) -type f -name "*.h")
OBJFILES := $(patsubst src%,build%,$(patsubst %.c,%.o,$(patsubst %.s,%.s.o,$(SRCFILES))))
ALLFILES = $(SRCFILES) $(HDRFILES) $(AUXFILES)
arch ?= x86_64
target := $(arch)-elf
kernel := build/kernel-$(arch).bin
iso := build/kernel-$(arch).iso
linker_script := src/arch/$(arch)/kernel.ld
grub_cfg := src/arch/$(arch)/grub.cfg
WARNINGS := -Wall -Wextra -pedantic -Wshadow -Wpointer-arith -Wcast-align \
-Wwrite-strings -Wmissing-prototypes -Wmissing-declarations \
-Wredundant-decls -Wnested-externs -Winline -Wno-long-long \
-Wstrict-prototypes
# TODO: re-enable -Wconversion
CFLAGS := -m64 -g -ffreestanding -mcmodel=large -mno-red-zone -mno-mmx -mno-sse -mno-sse2 $(WARNINGS)
QEMUFLAGS := -display curses
cross_dir ?= $(HOME)/opt/cross/bin/
CC_DIR ?= $(cross_dir)
LD_DIR ?= $(cross_dir)
AS_DIR ?= $(cross_dir)
CC := $(CC_DIR)$(target)-gcc
LD := $(LD_DIR)$(target)-ld
AS := nasm
.PHONY: all clean run iso kernel debug
all: $(iso)
clean:
$(RM) -r build
run: $(iso)
qemu-system-$(arch) $(QEMUFLAGS) -cdrom $(iso)
debug: $(iso)
qemu-system-$(arch) $(QEMUFLAGS) -s -S -cdrom $(iso)
iso: $(iso)
$(iso): $(kernel) $(grub_cfg)
mkdir -p build/isofiles/boot/grub
cp $(kernel) build/isofiles/boot/kernel.bin
cp $(grub_cfg) build/isofiles/boot/grub
grub-mkrescue -o $(iso) build/isofiles 2> /dev/null
-@$(RM) -r build/isofiles
kernel: $(kernel)
$(kernel): $(OBJFILES) $(linker_script)
$(LD) $(LDFLAGS) -n -T $(linker_script) -o $(kernel) $(OBJFILES)
build/%.s.o: src/%.s
mkdir -p $(shell dirname $@)
$(AS) -felf64 $< -o $@
build/%.o: src/%.c
mkdir -p $(shell dirname $@)
$(CC) $(CFLAGS) -c $< -o $@