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 20d9d83335Sfslongjin# cp kernel ../bin/kernel/kernel.elf 21f479f321Sfslongjin 22f479f321Sfslongjin 23*832442afSfslongjinkernel: 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 keyboard.o 2436ad7a10Sfslongjin 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 \ 25ad51f8b6Sfslongjin common/cpu.o \ 26*832442afSfslongjin driver/acpi/acpi.o driver/interrupt/pic.o driver/keyboard/keyboard.o \ 270b0cce93Sfslongjin -T link.lds 28f479f321Sfslongjin 29f479f321Sfslongjinhead.o: head.S 30f479f321Sfslongjin gcc -E head.S > head.s # 预处理 3159b4e6f6Sfslongjin as $(ASFLAGS) -o head.o head.s 32d9d83335Sfslongjin#gcc -mcmodel=large -fno-builtin -m64 -c head.S -o head.o 33f479f321Sfslongjin 3406cfb1ceSfslongjinentry.o: exception/entry.S 3506cfb1ceSfslongjin gcc -E exception/entry.S > exception/entry.s 3659b4e6f6Sfslongjin as $(ASFLAGS) -o exception/entry.o exception/entry.s 3706cfb1ceSfslongjin 38eff673edSfslongjin 39eff673edSfslongjin 40ead838bfSfslongjinmain.o: main.c 41ead838bfSfslongjin# -fno-builtin: 不使用C语言内建函数 42ead838bfSfslongjin# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture. 4359b4e6f6Sfslongjin gcc $(CFLAGS) -c main.c -o main.o 44ead838bfSfslongjin 45ead838bfSfslongjin 46ead838bfSfslongjinprintk.o: common/printk.c 4759b4e6f6Sfslongjin gcc $(CFLAGS) -c common/printk.c -o common/printk.o 4806cfb1ceSfslongjin 4906cfb1ceSfslongjintrap.o: exception/trap.c 5059b4e6f6Sfslongjin gcc $(CFLAGS) -c exception/trap.c -o exception/trap.o 5140a551d1Sfslongjin 52eff673edSfslongjinirq.o: exception/irq.c 5359b4e6f6Sfslongjin gcc $(CFLAGS) -c exception/irq.c -o exception/irq.o 54eff673edSfslongjin 55d5eb9e8aSfslongjin 56eff673edSfslongjin 5740a551d1Sfslongjinmm.o: mm/mm.c 5859b4e6f6Sfslongjin gcc $(CFLAGS) -c mm/mm.c -o mm/mm.o 59ead838bfSfslongjin 6036ad7a10Sfslongjinslab.o: mm/slab.c 6136ad7a10Sfslongjin gcc $(CFLAGS) -c mm/slab.c -o mm/slab.o 6236ad7a10Sfslongjin 6367633eb0Sfslongjinprocess.o: process/process.c 6459b4e6f6Sfslongjin gcc $(CFLAGS) -c process/process.c -o process/process.o 65d3a5048fSfslongjinsyscall.o: syscall/syscall.c 6659b4e6f6Sfslongjin gcc $(CFLAGS) -c syscall/syscall.c -o syscall/syscall.o 6767633eb0Sfslongjin 68574f3232Sfslongjin 690b0cce93Sfslongjin 70ad51f8b6Sfslongjincpu.o: common/cpu.c 71ad51f8b6Sfslongjin gcc $(CFLAGS) -c common/cpu.c -o common/cpu.o 72ad51f8b6Sfslongjin 73d5eb9e8aSfslongjin# 驱动程序 74574f3232Sfslongjin# 中断处理芯片的驱动程序 75e64be7b4Sfslongjinifeq ($(PIC), _INTR_8259A_) 76574f3232Sfslongjinpic.o: driver/interrupt/8259A/8259A.c 77574f3232Sfslongjin gcc $(CFLAGS) -c driver/interrupt/8259A/8259A.c -o driver/interrupt/pic.o 78e64be7b4Sfslongjinelse 79574f3232Sfslongjinpic.o: driver/interrupt/apic/apic.c 80574f3232Sfslongjin gcc $(CFLAGS) -c driver/interrupt/apic/apic.c -o driver/interrupt/pic.o 81574f3232Sfslongjinendif 82574f3232Sfslongjin 83574f3232Sfslongjinmultiboot2.o: driver/multiboot2/multiboot2.c 84574f3232Sfslongjin gcc $(CFLAGS) -c driver/multiboot2/multiboot2.c -o driver/multiboot2/multiboot2.o 85574f3232Sfslongjin 86e64be7b4Sfslongjinacpi.o: driver/acpi/acpi.c 87e64be7b4Sfslongjin gcc $(CFLAGS) -c driver/acpi/acpi.c -o driver/acpi/acpi.o 88e64be7b4Sfslongjin 89*832442afSfslongjinkeyboard.o: driver/keyboard/keyboard.c 90*832442afSfslongjin gcc $(CFLAGS) -c driver/keyboard/keyboard.c -o driver/keyboard/keyboard.o 91*832442afSfslongjin 92f479f321Sfslongjinclean: 93ead838bfSfslongjin rm -rf $(GARBAGE)