-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
121 lines (104 loc) · 4.62 KB
/
Makefile
File metadata and controls
121 lines (104 loc) · 4.62 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
CC = clang
LD = ld.lld
OBJCOPY = llvm-objcopy
CFLAGS = -target i386-elf -ffreestanding -fno-pic -fno-pie -mno-red-zone \
-Wall -Wextra -Werror -g -c -Iinc/ -Os \
-ffunction-sections -fdata-sections -flto
LDFLAGS = -m elf_i386 -T link.ld -nostdlib -static --gc-sections -o kernel.elf
BUILD = build
all: stage2 stage1 file_transforms image
CFLAGS += -DALLOC_DBG
$(BUILD):
mkdir -p $(BUILD)
stage1: stage1/boot.asm | $(BUILD)
nasm -f bin stage1/boot.asm -o boot.bin
stage2: stage2/start_loader.asm stage2/loader.c stage2/utils.c stage2/dev/vga.c stage2/io.c stage2/dev/disk.c stage2/dev/serial.c stage2/fat16.c stage2/cpu/interrupts/idt.c stage2/cpu/interrupts/isr.asm stage2/cpu/interrupts/isr.c stage2/cpu/interrupts/irq.asm stage2/cpu/interrupts/irq.c stage2/cpu/pic/pic.c stage2/cpu/pit/pit.c stage2/dev/keyboard.c stage2/mem.c stage2/dev/rtc.c stage2/dev/pci.c stage2/dev/pci_devices.c stage2/dev/e1k.c stage2/net/eth.c stage2/net/arp.c stage2/net/ipv4.c stage2/net/icmp.c stage2/net/udp.c stage2/vfs.c stage2/elf.c | $(BUILD)
nasm -f elf stage2/start_loader.asm -o $(BUILD)/start_loader.o
nasm -f elf stage2/cpu/interrupts/idt.asm -o $(BUILD)/idt_s.o
nasm -f elf stage2/cpu/interrupts/isr.asm -o $(BUILD)/isr_s.o
nasm -f elf stage2/cpu/interrupts/irq.asm -o $(BUILD)/irq_s.o
$(CC) $(CFLAGS) stage2/loader.c -o $(BUILD)/loader.o
$(CC) $(CFLAGS) stage2/utils.c -o $(BUILD)/utils.o
$(CC) $(CFLAGS) stage2/dev/vga.c -o $(BUILD)/vga.o
$(CC) $(CFLAGS) stage2/io.c -o $(BUILD)/io.o
$(CC) $(CFLAGS) stage2/dev/disk.c -o $(BUILD)/disk.o
$(CC) $(CFLAGS) stage2/dev/serial.c -o $(BUILD)/serial.o
$(CC) $(CFLAGS) stage2/fat16.c -o $(BUILD)/fat16.o
$(CC) $(CFLAGS) stage2/cpu/interrupts/idt.c -o $(BUILD)/idt.o
$(CC) $(CFLAGS) stage2/cpu/interrupts/isr.c -o $(BUILD)/isr.o
$(CC) $(CFLAGS) stage2/cpu/interrupts/irq.c -o $(BUILD)/irq.o
$(CC) $(CFLAGS) stage2/cpu/pic/pic.c -o $(BUILD)/pic.o
$(CC) $(CFLAGS) stage2/cpu/pit/pit.c -o $(BUILD)/pit.o
$(CC) $(CFLAGS) stage2/dev/keyboard.c -o $(BUILD)/keyboard.o
$(CC) $(CFLAGS) stage2/mem.c -o $(BUILD)/mem.o
$(CC) $(CFLAGS) stage2/dev/rtc.c -o $(BUILD)/rtc.o
$(CC) $(CFLAGS) stage2/dev/pci.c -o $(BUILD)/pci.o
$(CC) $(CFLAGS) stage2/dev/pci_devices.c -o $(BUILD)/pci_devices.o
$(CC) $(CFLAGS) stage2/dev/e1k.c -o $(BUILD)/e1k.o
$(CC) $(CFLAGS) stage2/net/eth.c -o $(BUILD)/eth.o
$(CC) $(CFLAGS) stage2/net/arp.c -o $(BUILD)/arp.o
$(CC) $(CFLAGS) stage2/net/ipv4.c -o $(BUILD)/ipv4.o
$(CC) $(CFLAGS) stage2/net/icmp.c -o $(BUILD)/icmp.o
$(CC) $(CFLAGS) stage2/net/udp.c -o $(BUILD)/udp.o
$(CC) $(CFLAGS) stage2/vfs.c -o $(BUILD)/vfs.o
$(CC) $(CFLAGS) stage2/elf.c -o $(BUILD)/elf.o
$(LD) $(LDFLAGS) \
$(BUILD)/start_loader.o \
$(BUILD)/loader.o \
$(BUILD)/utils.o \
$(BUILD)/vga.o \
$(BUILD)/serial.o \
$(BUILD)/io.o \
$(BUILD)/disk.o \
$(BUILD)/fat16.o \
$(BUILD)/idt.o \
$(BUILD)/idt_s.o \
$(BUILD)/isr.o \
$(BUILD)/isr_s.o \
$(BUILD)/irq.o \
$(BUILD)/irq_s.o \
$(BUILD)/pic.o \
$(BUILD)/pit.o \
$(BUILD)/keyboard.o \
$(BUILD)/mem.o \
$(BUILD)/rtc.o \
$(BUILD)/pci.o \
$(BUILD)/pci_devices.o \
$(BUILD)/e1k.o \
$(BUILD)/eth.o \
$(BUILD)/arp.o \
$(BUILD)/ipv4.o \
$(BUILD)/icmp.o \
$(BUILD)/udp.o \
$(BUILD)/vfs.o \
$(BUILD)/elf.o
$(OBJCOPY) --only-keep-debug kernel.elf kernel.sym
$(OBJCOPY) -O binary kernel.elf kernel.bin
image:
@./image.sh test_files/hi.txt build/libc.elf build/test.elf
psf: tools/psf.c | $(BUILD)
gcc -o $(BUILD)/psf tools/psf.c -Iinc/ $$(pkg-config --cflags --libs libpng)
imf: tools/imf.c | $(BUILD)
gcc -o $(BUILD)/imf tools/imf.c -Iinc/ $$(pkg-config --cflags --libs libpng)
file_transforms: psf imf | $(BUILD)
$(BUILD)/psf test_files/font.png $(BUILD)/font.psf
$(BUILD)/imf test_files/icon.png $(BUILD)/icon.imf --rle
@echo "Building libc as separate object..."
$(CC) -target i386-elf -m32 -ffreestanding -nostdlib -fno-pic -Iuser/include -c user/src/libc.c -o $(BUILD)/libc.o
@echo "Building test program as separate object..."
$(CC) -target i386-elf -m32 -ffreestanding -nostdlib -fno-pic -Iuser/include -c test_files/test.c -o $(BUILD)/test.o
@echo "Building entry points..."
nasm -f elf user/src/crt0.s -o $(BUILD)/crt0.o
@echo "Creating libc.elf..."
$(LD) $(BUILD)/libc.o -Ttext 0x40000000 -m elf_i386 -static -o $(BUILD)/libc.elf
@echo "Creating test.elf..."
$(LD) $(BUILD)/libc.o $(BUILD)/crt0.o $(BUILD)/test.o -T user/linker_test.ld -m elf_i386 -static -o $(BUILD)/test.elf
format:
@find . -type f \( -name "*.c" -o -name "*.h" \) -exec clang-format -i {} +
clean:
rm -rf $(BUILD)
rm -f *.bin
rm -f kernel.sym
rm -f kernel.elf
rm -f image.img
.PHONY: all clean stage1 stage2 image psf imf file_transforms format