xref: /DragonOS/kernel/Makefile (revision 60dc9f4932d3a5e975ee6dfef87f2add6ec00781)
1SUBDIR_ROOTS := . common
2DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
3GARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ kernel
4GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS)))
5
6DIR_LIB=lib
7lib_patterns := *.a
8LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns)))
9
10CFLAGS := -mcmodel=large -fno-builtin -m64 -g
11
12# 控制操作系统使用的中断控制器 _INTR_8259A_ _INTR_APIC_
13PIC := _INTR_APIC_
14CFLAGS += -D $(PIC)
15
16ASFLAGS := --64
17
18all: kernel
19	objcopy -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../bin/kernel/kernel.elf
20#
21
22kernel: head.o entry.o main.o printk.o trap.o mm.o slab.o irq.o pic.o process.o syscall.o multiboot2.o cpu.o acpi.o ps2_keyboard.o ps2_mouse.o ata.o pci.o ahci.o smp.o
23	ld -b elf64-x86-64 -z muldefs -o kernel head.o exception/entry.o main.o common/printk.o exception/trap.o exception/irq.o mm/mm.o mm/slab.o process/process.o syscall/syscall.o driver/multiboot2/multiboot2.o \
24	common/cpu.o smp/smp.o 	\
25	driver/acpi/acpi.o driver/interrupt/pic.o driver/keyboard/ps2_keyboard.o driver/mouse/ps2_mouse.o driver/disk/ata.o driver/pci/pci.o driver/disk/ahci/ahci.o \
26	-T link.lds
27
28head.o: head.S
29	gcc -E head.S > head.s # 预处理
30	as $(ASFLAGS) -o head.o head.s
31#gcc -mcmodel=large -fno-builtin -m64 -c head.S -o head.o
32
33entry.o: exception/entry.S
34	gcc -E exception/entry.S > exception/entry.s
35	as $(ASFLAGS) -o exception/entry.o exception/entry.s
36
37
38
39main.o: main.c
40# -fno-builtin: 不使用C语言内建函数
41# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture.
42	gcc $(CFLAGS) -c main.c  -o main.o
43
44
45printk.o: common/printk.c
46	gcc $(CFLAGS) -c common/printk.c -o common/printk.o
47
48trap.o:	exception/trap.c
49	gcc $(CFLAGS) -c exception/trap.c -o exception/trap.o
50
51irq.o: exception/irq.c
52	gcc $(CFLAGS) -c exception/irq.c -o exception/irq.o
53
54
55
56mm.o: mm/mm.c
57	gcc $(CFLAGS) -c mm/mm.c -o mm/mm.o
58
59slab.o: mm/slab.c
60	gcc $(CFLAGS) -c mm/slab.c -o mm/slab.o
61
62process.o: process/process.c
63	gcc $(CFLAGS) -c process/process.c -o process/process.o
64syscall.o: syscall/syscall.c
65	gcc $(CFLAGS) -c syscall/syscall.c -o syscall/syscall.o
66
67smp.o: smp/smp.c
68	gcc $(CFLAGS) -c smp/smp.c  -o smp/smp.o
69
70cpu.o: common/cpu.c
71	gcc $(CFLAGS) -c common/cpu.c -o common/cpu.o
72
73# 驱动程序
74# 中断处理芯片的驱动程序
75ifeq ($(PIC), _INTR_8259A_)
76pic.o: driver/interrupt/8259A/8259A.c
77	gcc $(CFLAGS) -c driver/interrupt/8259A/8259A.c -o driver/interrupt/pic.o
78else
79pic.o: driver/interrupt/apic/apic.c
80	gcc $(CFLAGS) -c driver/interrupt/apic/apic.c -o driver/interrupt/pic.o
81endif
82
83multiboot2.o: driver/multiboot2/multiboot2.c
84	gcc $(CFLAGS) -c driver/multiboot2/multiboot2.c  -o driver/multiboot2/multiboot2.o
85
86acpi.o: driver/acpi/acpi.c
87	gcc $(CFLAGS) -c driver/acpi/acpi.c  -o driver/acpi/acpi.o
88
89ps2_keyboard.o: driver/keyboard/ps2_keyboard.c
90	gcc $(CFLAGS) -c driver/keyboard/ps2_keyboard.c  -o driver/keyboard/ps2_keyboard.o
91
92ps2_mouse.o: driver/mouse/ps2_mouse.c
93	gcc $(CFLAGS) -c driver/mouse/ps2_mouse.c -o driver/mouse/ps2_mouse.o
94
95ata.o: driver/disk/ata.c
96	gcc $(CFLAGS) -c driver/disk/ata.c -o driver/disk/ata.o
97
98pci.o: driver/pci/pci.c
99	gcc $(CFLAGS) -c driver/pci/pci.c -o driver/pci/pci.o
100
101ahci.o: driver/disk/ahci/ahci.c
102	gcc $(CFLAGS) -c driver/disk/ahci/ahci.c -o driver/disk/ahci/ahci.o
103
104
105clean:
106	rm -rf $(GARBAGE)