-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
66 lines (53 loc) · 1.48 KB
/
Copy pathMakefile
File metadata and controls
66 lines (53 loc) · 1.48 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
#!Makefile
#基于依赖递归更新的编译规则
#patsubt 模式字符串替换,在C_SRC字列中的字(一列文件名),如果结尾是'.c',就用'.o'取代'.c'
C_SRC=$(shell find . -name "*.c")
C_OBJ=$(patsubst %.c,%.o,$(C_SRC))
S_SRC=$(shell find . -name "*.s")
S_OBJ=$(patsubst %.s,%.o,$(S_SRC))
CC=gcc
LD=ld
ASM=nasm
C_FLAGS=-c -Wall -m32 -ggdb -gstabs+ -nostdinc -fno-builtin -fno-stack-protector -I include
LD_FLAGS=-T scripts/kernel.ld -m elf_i386 -nostdlib
ASM_FLAGS=-f elf -g -F stabs
all:$(S_OBJ) $(C_OBJ) link update_image
#模式规则
#$<为所有依赖文件,$@为所有目标文件,相当于foreach处理操作
%.o:%.c
@echo 编译代码文件...
$(CC) $(C_FLAGS) $< -o $@
%.o:%.s
@echo 编译汇编文件...
$(ASM) $(ASM_FLAGS) $< -o $@
link:
@echo 链接内核文件...
$(LD) $(LD_FLAGS) $(S_OBJ) $(C_OBJ) -o atkos
#隐晦规则,伪目标文件
.PHONY:update_image
update_image:
sudo mount floppy.img /mnt/kernel
sudo cp atkos /mnt/kernel/
sleep 1
sudo umount /mnt/kernel/
.PHONY:mount_image
mount_image:
sudo mount floppy.img /mnt/kernel
.PHONY:umount_image
umount_image:
sudo umount /mnt/kernel
.PHONY:qemu
qemu:
qemu-system-i386 -fda floppy.img -boot a -m 64 -localtime
.PHONY:bochs
bochs:
bochs -f scripts/bochsrc.txt
.PHONY:debug
debug:
qemu-system-i386 -S -s -fda floppy.img -boot a &
sleep 1
cgdb -x scripts/gdbinit
#-rm 某些文件出现问题,但不要管,继续做后面的事
.PHONY:clean
clean:
-rm -f $(S_OBJ) $(C_OBJ) atkos