xref: /DragonOS/kernel/Makefile (revision b7df2805ed92afcba05610cc2471a8bab68739f4)
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 -O0
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 apu_boot.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 smp/apu_boot.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
70apu_boot.o: smp/apu_boot.S
71	gcc -E smp/apu_boot.S > smp/apu_boot.s # 预处理
72	as $(ASFLAGS) -o smp/apu_boot.o smp/apu_boot.s
73
74cpu.o: common/cpu.c
75	gcc $(CFLAGS) -c common/cpu.c -o common/cpu.o
76
77# 驱动程序
78# 中断处理芯片的驱动程序
79ifeq ($(PIC), _INTR_8259A_)
80pic.o: driver/interrupt/8259A/8259A.c
81	gcc $(CFLAGS) -c driver/interrupt/8259A/8259A.c -o driver/interrupt/pic.o
82else
83pic.o: driver/interrupt/apic/apic.c
84	gcc $(CFLAGS) -c driver/interrupt/apic/apic.c -o driver/interrupt/pic.o
85endif
86
87multiboot2.o: driver/multiboot2/multiboot2.c
88	gcc $(CFLAGS) -c driver/multiboot2/multiboot2.c  -o driver/multiboot2/multiboot2.o
89
90acpi.o: driver/acpi/acpi.c
91	gcc $(CFLAGS) -c driver/acpi/acpi.c  -o driver/acpi/acpi.o
92
93ps2_keyboard.o: driver/keyboard/ps2_keyboard.c
94	gcc $(CFLAGS) -c driver/keyboard/ps2_keyboard.c  -o driver/keyboard/ps2_keyboard.o
95
96ps2_mouse.o: driver/mouse/ps2_mouse.c
97	gcc $(CFLAGS) -c driver/mouse/ps2_mouse.c -o driver/mouse/ps2_mouse.o
98
99ata.o: driver/disk/ata.c
100	gcc $(CFLAGS) -c driver/disk/ata.c -o driver/disk/ata.o
101
102pci.o: driver/pci/pci.c
103	gcc $(CFLAGS) -c driver/pci/pci.c -o driver/pci/pci.o
104
105ahci.o: driver/disk/ahci/ahci.c
106	gcc $(CFLAGS) -c driver/disk/ahci/ahci.c -o driver/disk/ahci/ahci.o
107
108
109clean:
110	rm -rf $(GARBAGE)