-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
96 lines (78 loc) · 2.7 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
# Makefile for Qiux
# 设置调试选项, True 或 False
DEBUG := True
# 设置优化级别, -O0, -O1, -O2, -O3等
OPTIMIZATION := -O2
# 编译、运行和调试工具
GDB := gdb
BOCHS := bochs
BXIMG := bximage
LD := ld
ASM := nasm
CC := gcc
AR := ar
# 源文件
CSOURCE := $(wildcard device/*.c filesys/*.c kernel/*.c lib/*.c service/*.c)
ASMSOURCE := $(wildcard device/*.asm filesys/*.asm kernel/*.asm lib/*.asm service/*.asm)
HEADER := $(wildcard device/*.h filesys/*.h kernel/*.h lib/*.h service/*.h include/*.h)
BOOTSOURCE := boot/boot.asm
USRSOURCE := $(wildcard usrprog/*.c)
# 目标文件
BUILD := build
IMG := Qiux.img
BOOT := $(BUILD)/boot.bin
KERNEL := $(BUILD)/kernel.bin
OBJS := $(addprefix $(BUILD)/, $(notdir $(CSOURCE:.c=.o) $(ASMSOURCE:.asm=.o)))
USRLIB := $(BUILD)/qiux.a
USRPROG := usrprog/build/cat usrprog/build/cp usrprog/build/echo \
usrprog/build/hexdump usrprog/build/ls usrprog/build/fcreate \
usrprog/build/mkdir usrprog/build/pwd usrprog/build/rm
# 配置文件
BOCHSRC := bochsrc
# 参数
GDBFLAGS := -q -ex "target remote localhost:1234" \
-ex "set disassembly-flavor intel" \
-ex "set disassemble-next-line on"
LDFLAGS := -Ttext 0x10400 -e kernel_main -m elf_i386
ifeq ($(DEBUG), True)
ASMFLAGS := -f elf -g -F DWARF
CFLAGS := -I include/ -m32 -c -fno-builtin -fno-stack-protector -nostdinc -g -D DEBUG $(OPTIMIZATION)
else
ASMFLAGS := -f elf
CFLAGS := -I include/ -m32 -c -fno-builtin -fno-stack-protector -nostdinc $(OPTIMIZATION)
endif
.PHONY: all clean rebuild debug fsck copy
all:$(BUILD) $(IMG)
clean:
rm -f $(IMG)
rm -rf $(BUILD)
rebuild: clean all
fsck:$(IMG)
fsck.minix -fsl $<
copy:$(IMG)
cp $(IMG) /mnt/c/Users/Qiu/Documents/qiux/
# 请确保bochsrc文件中最后一行gdbstub:enabled=1 ... 被取消注释
debug:$(IMG) $(KERNEL)
$(BOCHS) -f $(BOCHSRC) -q 2>/dev/null >/dev/null &
$(GDB) $(GDBFLAGS) $(KERNEL)
$(IMG): $(BOOT) $(KERNEL) $(USRPROG)
rm -f *.img
$(BXIMG) -q $@ -hd=10M -mode=create
mkfs.minix -1 -n14 $@
dd if=$(BOOT) of=$@ bs=512 count=2 conv=notrunc
tool/tool $(KERNEL) $(USRPROG) $@
$(BOOT): $(BOOTSOURCE) boot/include/*
$(ASM) -o $@ $< -I boot/include/
$(KERNEL): $(OBJS)
$(LD) $(LDFLAGS) -o $@ $^
$(BUILD)/%.o:*/%.c $(HEADER)
$(CC) $(CFLAGS) -o $@ $<
$(BUILD)/%.o:*/%.asm
$(ASM) $(ASMFLAGS) -o $@ $<
$(BUILD):
mkdir $@
$(USRLIB): $(BUILD)/list.o $(BUILD)/stdio.o $(BUILD)/stdlib.o \
$(BUILD)/string.o $(BUILD)/syscall.o $(BUILD)/debug.o $(BUILD)/ipc.o
$(AR) rcs $@ $^
$(USRPROG): $(USRLIB) $(USRSOURCE)
$(MAKE) -C usrprog