-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
106 lines (88 loc) · 2.52 KB
/
Makefile
File metadata and controls
106 lines (88 loc) · 2.52 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
95
96
97
98
99
100
101
102
103
104
105
106
# Provides ARCH
include make.config
NAME=TrashOS
ARCH?=i386
MARCH?=i686
ARCHDIR=kernel/arch/$(ARCH)
CC=$(MARCH)-elf-gcc
AS=$(MARCH)-elf-as
LD=$(MARCH)-elf-ld
# TODO Supposedly x86-64 ABI requires .eh_frame sections, so should
# -fno-asynchronous-unwind-tables be removed or placed into an
# architecture-specific config?
DEBUG=-g3 -fno-asynchronous-unwind-tables
OPT=-O3 -pipe
LTO=-flto=jobserver
WARN=-pedantic -Wall -Wextra -Werror
ASFLAGS=-march=$(MARCH)
CFLAGS_NOLTO=-std=gnu18 -ffreestanding $(DEBUG) $(OPT) $(WARN)
CFLAGS=$(CFLAGS_NOLTO) $(LTO)
LDFLAGS=-ffreestanding -nostdlib $(DEBUG) $(OPT) $(WARN) -lgcc
KOBJS=\
$(ARCHDIR)/alloc.o \
$(ARCHDIR)/apic.o \
$(ARCHDIR)/boot.o \
$(ARCHDIR)/gdt.o \
$(ARCHDIR)/init.o \
$(ARCHDIR)/int.o \
$(ARCHDIR)/int_asm.o \
$(ARCHDIR)/kernel.o \
$(ARCHDIR)/printk.o \
$(ARCHDIR)/proc.o \
$(ARCHDIR)/multiboot2.o \
$(ARCHDIR)/page.o \
$(ARCHDIR)/vga.o \
$(ARCHDIR)/init_printk.o \
$(ARCHDIR)/init_vga.o \
KHDRS=\
$(ARCHDIR)/_print.c \
$(ARCHDIR)/alloc.h \
$(ARCHDIR)/apic.h \
$(ARCHDIR)/asm.h \
$(ARCHDIR)/cpuid.h \
$(ARCHDIR)/gdt.h \
$(ARCHDIR)/int.h \
$(ARCHDIR)/io.h \
$(ARCHDIR)/math.h \
$(ARCHDIR)/mem.h \
$(ARCHDIR)/page.h \
$(ARCHDIR)/proc.h \
$(ARCHDIR)/std.h \
$(ARCHDIR)/string.h \
$(ARCHDIR)/vga.h \
KERNEL=$(ARCHDIR)/kernel
ISODIR=iso
ISO=$(NAME).iso
.PHONY: all run clean
# Create implicit rule for linking binaries with ld script prerequisite
%: %.ld
+$(CC) -T $^ $(LDFLAGS) -o $@
all: $(ISO)
# Header file prerequisites
$(KOBJS): $(KHDRS)
# Special rule for compiling interrupt handlers
$(ARCHDIR)/int.o: $(ARCHDIR)/int.c
$(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS) -mgeneral-regs-only
# Since init*.o are placed into a custom section, we must compile without LTO
# due to optimizer bugs. See the following for more details:
# https://bugs.launchpad.net/gcc-arm-embedded/+bug/1418073
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78903
# https://gcc.gnu.org/ml/gcc-bugs/2015-03/msg00094.html
$(ARCHDIR)/init_%.o: $(ARCHDIR)/init_%.c
$(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS_NOLTO)
$(ARCHDIR)/init.o: $(ARCHDIR)/init.c
$(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS_NOLTO)
$(KERNEL): $(KERNEL).ld $(KOBJS)
$(ISO): $(KERNEL)
grub-file --is-x86-multiboot2 $^
mkdir -p $(ISODIR)/boot/grub/
cp $(KERNEL) $(ISODIR)/boot/
echo 'menuentry "$(NAME)" { multiboot2 /boot/kernel }' > $(ISODIR)/boot/grub/grub.cfg
grub-mkrescue -o $@ $(ISODIR)
run: $(ISO)
qemu-system-$(ARCH) -cdrom $^ -d cpu_reset
guide.pdf: guide.tex
pdflatex $^
clean:
rm -f $(KOBJS) $(KERNEL) $(ISO)
rm -rf $(ISODIR)