1ead838bfSfslongjinSUBDIR_ROOTS := . common 2ead838bfSfslongjinDIRS := . $(shell find $(SUBDIR_ROOTS) -type d) 340a551d1SfslongjinGARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ kernel 4ead838bfSfslongjinGARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS))) 5f479f321Sfslongjin 640a551d1SfslongjinDIR_LIB=lib 740a551d1Sfslongjinlib_patterns := *.a 840a551d1SfslongjinLIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns))) 959b4e6f6Sfslongjin 1059b4e6f6SfslongjinCFLAGS := -mcmodel=large -fno-builtin -m64 11574f3232Sfslongjin 12574f3232Sfslongjin# 控制操作系统使用的中断控制器 _INTR_8259A_ _INTR_APIC_ 13574f3232SfslongjinPIC := _INTR_APIC_ 14574f3232SfslongjinCFLAGS += -D $(PIC) 15574f3232Sfslongjin 1659b4e6f6SfslongjinASFLAGS := --64 1759b4e6f6Sfslongjin 18f479f321Sfslongjinall: kernel 1959b4e6f6Sfslongjin objcopy -I elf64-x86-64 -S -R ".comment" -R ".eh_frame" -O elf64-x86-64 kernel ../bin/kernel/kernel.elf 20f479f321Sfslongjin 21f479f321Sfslongjin 22*08fa7b53Sfslongjinkernel: 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 2336ad7a10Sfslongjin 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 \ 24ad51f8b6Sfslongjin common/cpu.o \ 25*08fa7b53Sfslongjin 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 \ 260b0cce93Sfslongjin -T link.lds 27f479f321Sfslongjin 28f479f321Sfslongjinhead.o: head.S 29f479f321Sfslongjin gcc -E head.S > head.s # 预处理 3059b4e6f6Sfslongjin as $(ASFLAGS) -o head.o head.s 31d9d83335Sfslongjin#gcc -mcmodel=large -fno-builtin -m64 -c head.S -o head.o 32f479f321Sfslongjin 3306cfb1ceSfslongjinentry.o: exception/entry.S 3406cfb1ceSfslongjin gcc -E exception/entry.S > exception/entry.s 3559b4e6f6Sfslongjin as $(ASFLAGS) -o exception/entry.o exception/entry.s 3606cfb1ceSfslongjin 37eff673edSfslongjin 38eff673edSfslongjin 39ead838bfSfslongjinmain.o: main.c 40ead838bfSfslongjin# -fno-builtin: 不使用C语言内建函数 41ead838bfSfslongjin# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture. 4259b4e6f6Sfslongjin gcc $(CFLAGS) -c main.c -o main.o 43ead838bfSfslongjin 44ead838bfSfslongjin 45ead838bfSfslongjinprintk.o: common/printk.c 4659b4e6f6Sfslongjin gcc $(CFLAGS) -c common/printk.c -o common/printk.o 4706cfb1ceSfslongjin 4806cfb1ceSfslongjintrap.o: exception/trap.c 4959b4e6f6Sfslongjin gcc $(CFLAGS) -c exception/trap.c -o exception/trap.o 5040a551d1Sfslongjin 51eff673edSfslongjinirq.o: exception/irq.c 5259b4e6f6Sfslongjin gcc $(CFLAGS) -c exception/irq.c -o exception/irq.o 53eff673edSfslongjin 54d5eb9e8aSfslongjin 55eff673edSfslongjin 5640a551d1Sfslongjinmm.o: mm/mm.c 5759b4e6f6Sfslongjin gcc $(CFLAGS) -c mm/mm.c -o mm/mm.o 58ead838bfSfslongjin 5936ad7a10Sfslongjinslab.o: mm/slab.c 6036ad7a10Sfslongjin gcc $(CFLAGS) -c mm/slab.c -o mm/slab.o 6136ad7a10Sfslongjin 6267633eb0Sfslongjinprocess.o: process/process.c 6359b4e6f6Sfslongjin gcc $(CFLAGS) -c process/process.c -o process/process.o 64d3a5048fSfslongjinsyscall.o: syscall/syscall.c 6559b4e6f6Sfslongjin gcc $(CFLAGS) -c syscall/syscall.c -o syscall/syscall.o 6667633eb0Sfslongjin 67574f3232Sfslongjin 680b0cce93Sfslongjin 69ad51f8b6Sfslongjincpu.o: common/cpu.c 70ad51f8b6Sfslongjin gcc $(CFLAGS) -c common/cpu.c -o common/cpu.o 71ad51f8b6Sfslongjin 72d5eb9e8aSfslongjin# 驱动程序 73574f3232Sfslongjin# 中断处理芯片的驱动程序 74e64be7b4Sfslongjinifeq ($(PIC), _INTR_8259A_) 75574f3232Sfslongjinpic.o: driver/interrupt/8259A/8259A.c 76574f3232Sfslongjin gcc $(CFLAGS) -c driver/interrupt/8259A/8259A.c -o driver/interrupt/pic.o 77e64be7b4Sfslongjinelse 78574f3232Sfslongjinpic.o: driver/interrupt/apic/apic.c 79574f3232Sfslongjin gcc $(CFLAGS) -c driver/interrupt/apic/apic.c -o driver/interrupt/pic.o 80574f3232Sfslongjinendif 81574f3232Sfslongjin 82574f3232Sfslongjinmultiboot2.o: driver/multiboot2/multiboot2.c 83574f3232Sfslongjin gcc $(CFLAGS) -c driver/multiboot2/multiboot2.c -o driver/multiboot2/multiboot2.o 84574f3232Sfslongjin 85e64be7b4Sfslongjinacpi.o: driver/acpi/acpi.c 86e64be7b4Sfslongjin gcc $(CFLAGS) -c driver/acpi/acpi.c -o driver/acpi/acpi.o 87e64be7b4Sfslongjin 8871d6af78Sfslongjinps2_keyboard.o: driver/keyboard/ps2_keyboard.c 8971d6af78Sfslongjin gcc $(CFLAGS) -c driver/keyboard/ps2_keyboard.c -o driver/keyboard/ps2_keyboard.o 90832442afSfslongjin 9171d6af78Sfslongjinps2_mouse.o: driver/mouse/ps2_mouse.c 9271d6af78Sfslongjin gcc $(CFLAGS) -c driver/mouse/ps2_mouse.c -o driver/mouse/ps2_mouse.o 93b3cbd3caSfslongjin 94046bce39Sfslongjinata.o: driver/disk/ata.c 95046bce39Sfslongjin gcc $(CFLAGS) -c driver/disk/ata.c -o driver/disk/ata.o 96046bce39Sfslongjin 97*08fa7b53Sfslongjinpci.o: driver/pci/pci.c 98*08fa7b53Sfslongjin gcc $(CFLAGS) -c driver/pci/pci.c -o driver/pci/pci.o 99*08fa7b53Sfslongjin 100b3cbd3caSfslongjin 101f479f321Sfslongjinclean: 102ead838bfSfslongjin rm -rf $(GARBAGE)