-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
73 lines (51 loc) · 1.51 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
70
71
72
73
# Makefile for building a simple kernel with i686-elf-gcc
CONST = # Constants
# Paths to tools
AS = i686-elf-as
CC = i686-elf-g++
LD = i686-elf-gcc
OBJCP = i686-elf-objcopy
GRUB = grub-mkrescue
# Flags for the compiler and linker
CFLAGS = -ffreestanding -O2 -Wall -Wextra -fno-exceptions -fno-rtti
LDFLAGS = -T linker.ld -ffreestanding -O2 -nostdlib -lgcc
CFLAGS += $(CONST)
# Output files
KERNEL = bin/paranoia.bin
OBJ_FILES = boot.o paranoia.o terminal.o string.o assemblyUtils.o pit.o math.o memory.o fail.o
ISO_IMAGE = paranoia.iso
ISO_DIR = iso
# The default target
all: $(ISO_IMAGE)
boot.o: src/boot.s
$(AS) $< -o $@
# Compile the C code (with inline assembly)
paranoia.o: src/paranoia.cpp
$(CC) $(CFLAGS) -c $< -o $@
terminal.o: src/terminal.cpp
$(CC) $(CFLAGS) -c $< -o $@
string.o: src/string.cpp
$(CC) $(CFLAGS) -c $< -o $@
math.o: src/math.cpp
$(CC) $(CFLAGS) -c $< -o $@
memory.o: src/memory.cpp
$(CC) $(CFLAGS) -c $< -o $@
assemblyUtils.o: src/assemblyUtils.cpp
$(CC) $(CFLAGS) -c $< -o $@
pit.o: src/pit.cpp
$(CC) $(CFLAGS) -c $< -o $@
fail.o: src/fail.cpp
$(CC) $(CFLAGS) -c $< -o $@
# Link the kernel
$(KERNEL): $(OBJ_FILES)
$(LD) $(LDFLAGS) -o $(KERNEL) $(OBJ_FILES)
# Make the kernel bootable by adding the multiboot header and padding it to a 512-byte boundary
$(OBJCP) --pad-to=512 $(KERNEL)
$(ISO_IMAGE): $(KERNEL)
mkdir -p $(ISO_DIR)/boot/grub
cp $(KERNEL) $(ISO_DIR)/boot/
$(GRUB) -o $(ISO_IMAGE) $(ISO_DIR)
# Clean the generated files
clean:
rm -f $(OBJ_FILES) $(KERNEL)
rm paranoia.iso