/
Makefile
134 lines (105 loc) · 3.15 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
GDB=gdb
OBJCOPY=objcopy
CAT=cat
ifeq ($(OS),Windows_NT)
CAT=type
else
OS=$(shell uname -s)
endif
ifeq ($(OS),Darwin)
AS=x86_64-elf-as
LD=x86_64-elf-ld
CC=x86_64-elf-gcc
GDB=x86_64-elf-gdb
OBJCOPY=x86_64-elf-objcopy
endif
CFLAGS = -fno-pic -ffreestanding -static -fno-builtin -fno-strict-aliasing \
-mno-sse \
-Wall -ggdb -m32 -Werror -fno-omit-frame-pointer
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
ASMFLAGS = -m32 -ffreestanding -c -g
ifeq ($(LLVM),on)
ifeq ($(OS),Darwin)
LD=PATH=/usr/local/opt/llvm/bin:$(PATH) ld.lld
else
LD=ld.lld
endif
CC=clang
CFLAGS += -target elf-i386
ASMFLAGS = -target elf-i386 -ffreestanding -c -g
LDKERNELFLAGS = --script=script.ld
endif
OBJECTS = ./kernel.o ./console.o ./drivers/vga.o ./drivers/uart.o ./drivers/keyboard.o \
./cpu/idt.o ./cpu/gdt.o ./cpu/swtch.o ./cpu/vectors.o ./lib/mem.o ./proc.o ./lib/string.o \
./fs/fs.o
run: image.bin
qemu-system-i386 -drive format=raw,file=$< -serial mon:stdio
run-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -serial mon:stdio
ejudge.sh: image.bin
echo >$@ "#!/bin/sh"
echo >>$@ "base64 -d <<===EOF | gunzip >image.bin"
gzip <$^ | base64 >>$@
echo >>$@ "===EOF"
echo >>$@ "exec qemu-system-i386 -nographic -drive format=raw,file=image.bin -serial mon:stdio"
chmod +x $@
diag:
-$(UNAME) -a
-$(CC) --version
-$(LD) -v
-gcc --version
-ld -v
debug-boot-nox: image.bin mbr.elf
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
$(GDB) mbr.elf \
-ex "set architecture i8086" \
-ex "target remote localhost:1234" \
-ex "break *0x7c00" \
-ex "continue"
debug-boot: image.bin mbr.elf
qemu-system-i386 -drive format=raw,file=$< -s -S &
$(GDB) mbr.elf \
-ex "set architecture i8086" \
-ex "target remote localhost:1234" \
-ex "break *0x7c00" \
-ex "continue"
debug-server: image.bin
qemu-system-i386 -drive format=raw,file=$< -s -S
debug-server-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S
debug: image.bin
qemu-system-i386 -drive format=raw,file=$< -s -S &
$(GDB) kernel.bin \
-ex "target remote localhost:1234" \
-ex "break _start" \
-ex "continue"
debug-nox: image.bin
qemu-system-i386 -nographic -drive format=raw,file=$< -s -S &
$(GDB) kernel.bin \
-ex "target remote localhost:1234" \
-ex "break _start" \
-ex "continue"
fs.img: ./kernel.bin ./tools/mkfs ./user/false ./user/greet ./user/div0
./tools/mkfs $@ $< ./user/false ./user/greet ./user/div0
LDFLAGS=-m elf_i386
user/%: user/%.o user/crt.o
$(LD) $(LDFLAGS) -o $@ -Ttext 0x1000 $^
kernel.bin: $(OBJECTS)
$(LD) $(LDFLAGS) $(LDKERNELFLAGS) -o $@ -Ttext 0x9000 $^
bootmain.o: bootmain.c
$(CC) $(CFLAGS) -Os -c $< -o $@
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
%.o: %.S
$(CC) $(ASMFLAGS) $^ -o $@
image.bin: mbr.elf tools/mbrpad fs.img
$(OBJCOPY) -S -O binary -j .text $< $@
tools/mbrpad $@ fs.img
mbr.raw: mbr.o bootmain.o
$(LD) -N -m elf_i386 -Ttext=0x7c00 --oformat=binary $^ -o $@
mbr.elf: mbr.o bootmain.o
$(LD) -N -m elf_i386 -Ttext=0x7c00 $^ -o $@
clean:
rm -f *.elf *.img *.bin *.raw *.o */*.o tools/mkfs ejudge.sh
tools/%: tools/%.c
gcc -Wall -Werror -g $^ -o $@