xref: /DragonOS/kernel/Makefile (revision 574f3232840d522402a7fb99a5a3412797ed48f2)
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
11
12# 控制操作系统使用的中断控制器 _INTR_8259A_ _INTR_APIC_
13PIC := _INTR_APIC_
14CFLAGS += -D $(PIC)
15
16ASFLAGS := --64
17
18all: kernel
19	objcopy -I elf64-x86-64 -S -R ".comment" -R ".eh_frame" -O elf64-x86-64 kernel ../bin/kernel/kernel.elf
20# cp kernel ../bin/kernel/kernel.elf
21
22
23kernel: 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
24	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 \
25	common/cpu.o	\
26	driver/interrupt/pic.o	\
27	-T link.lds
28
29head.o: head.S
30	gcc -E head.S > head.s # 预处理
31	as $(ASFLAGS) -o head.o head.s
32#gcc -mcmodel=large -fno-builtin -m64 -c head.S -o head.o
33
34entry.o: exception/entry.S
35	gcc -E exception/entry.S > exception/entry.s
36	as $(ASFLAGS) -o exception/entry.o exception/entry.s
37
38
39
40main.o: main.c
41# -fno-builtin: 不使用C语言内建函数
42# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture.
43	gcc $(CFLAGS) -c main.c  -o main.o
44
45
46printk.o: common/printk.c
47	gcc $(CFLAGS) -c common/printk.c -o common/printk.o
48
49trap.o:	exception/trap.c
50	gcc $(CFLAGS) -c exception/trap.c -o exception/trap.o
51
52irq.o: exception/irq.c
53	gcc $(CFLAGS) -c exception/irq.c -o exception/irq.o
54
55
56
57mm.o: mm/mm.c
58	gcc $(CFLAGS) -c mm/mm.c -o mm/mm.o
59
60slab.o: mm/slab.c
61	gcc $(CFLAGS) -c mm/slab.c -o mm/slab.o
62
63process.o: process/process.c
64	gcc $(CFLAGS) -c process/process.c -o process/process.o
65syscall.o: syscall/syscall.c
66	gcc $(CFLAGS) -c syscall/syscall.c -o syscall/syscall.o
67
68
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 ifeq($(PIC), _INTR_APIC_)
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
86clean:
87	rm -rf $(GARBAGE)