-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
79 lines (64 loc) · 1.88 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
#!Makefile
#
# --------------------------------------------------------
#
# 默认使用的C语言编译器是 GCC、汇编语言编译器是 nasm
#
# --------------------------------------------------------
#
# patsubst 处理所有在 C_SOURCES 字列中的字(一列文件名),如果它的 结尾是 '.c',就用 '.o' 把 '.c' 取代
C_SOURCES = $(shell find . -name "*.c")
C_OBJECTS = $(patsubst %.c, %.o, $(C_SOURCES))
S_SOURCES = $(shell find . -name "*.s")
S_OBJECTS = $(patsubst %.s, %.o, $(S_SOURCES))
CC = gcc
LD = ld
ASM = nasm
C_FLAGS = -c -Wall -m32 -ggdb -gstabs+ -fgnu89-inline -nostdinc -fno-pic -fno-builtin -fno-stack-protector -I include #-DDEBUG
LD_FLAGS = -T scripts/kernel.ld -m elf_i386 -nostdlib
ASM_FLAGS = -f elf -g -F stabs -I include/
all: clean $(S_OBJECTS) $(C_OBJECTS) link update_image
# The automatic variable `$<' is just the first prerequisite
.c.o:
@echo 编译代码文件 $< ...
$(CC) $(C_FLAGS) $< -o $@
.s.o:
@echo 编译汇编文件 $< ...
$(ASM) $(ASM_FLAGS) $<
link:
@echo 链接内核文件...
$(LD) $(LD_FLAGS) $(S_OBJECTS) $(C_OBJECTS) -o BaGua_OS
# $(RM) $(S_OBJECTS) $(C_OBJECTS)
.PHONY:clean
clean:
$(RM) $(S_OBJECTS) $(C_OBJECTS) BaGua_OS BaGua_HD.img
.PHONY:obj
obj:$(S_OBJECTS) $(C_OBJECTS)
@echo 生成目标文件,可执行文件
$(LD) $(LD_FLAGS) $(S_OBJECTS) $(C_OBJECTS) -o BaGua_OS
.PHONY:update_image
update_image:
sudo mount ./hd.img /mnt/kernel
sudo rm -rf /mnt/kernel/BaGua_OS
sudo cp -i BaGua_OS /mnt/kernel/BaGua_OS
sleep 3
sudo umount /mnt/kernel
sleep 3
qemu-img convert -f raw -O qcow2 hd.img BaGua_HD.img
.PHONY:mount_image
mount_image:
sudo mount hd.img /mnt/kernel
.PHONY:umount_image
umount_image:
sudo umount /mnt/kernel
.PHONY:qemu
qemu:
qemu -m 512M -hda BaGua_HD.img -boot a
.PHONY:raw
raw:
qemu -hda hd.img
.PHONY:debug
debug:
qemu -S -s -hda BaGua_HD.img -boot a &
sleep 1
cgdb -x scripts/gdbinit