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))) 9all: kernel 10 objcopy -I elf64-x86-64 -S -R ".comment" -O elf64-x86-64 kernel ../bin/kernel/kernel.elf 11# cp kernel ../bin/kernel/kernel.elf 12 13 14kernel: head.o entry.o main.o printk.o trap.o mm.o irq.o 8259A.o process.o syscall.o multiboot2.o 15 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 exception/8259A.o mm/mm.o process/process.o syscall/syscall.o driver/multiboot2/multiboot2.o \ 16 -T link.lds 17 18head.o: head.S 19 gcc -E head.S > head.s # 预处理 20 as --64 -o head.o head.s 21#gcc -mcmodel=large -fno-builtin -m64 -c head.S -o head.o 22 23entry.o: exception/entry.S 24 gcc -E exception/entry.S > exception/entry.s 25 as --64 -o exception/entry.o exception/entry.s 26 27 28 29main.o: main.c 30# -fno-builtin: 不使用C语言内建函数 31# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture. 32 gcc -mcmodel=large -fno-builtin -m64 -c main.c -o main.o 33 34 35printk.o: common/printk.c 36 gcc -mcmodel=large -fno-builtin -m64 -c common/printk.c -o common/printk.o 37 38trap.o: exception/trap.c 39 gcc -mcmodel=large -fno-builtin -m64 -c exception/trap.c -o exception/trap.o 40 41irq.o: exception/irq.c 42 gcc -mcmodel=large -fno-builtin -m64 -c exception/irq.c -o exception/irq.o 43 448259A.o: exception/8259A.c 45 gcc -mcmodel=large -fno-builtin -m64 -c exception/8259A.c -o exception/8259A.o 46 47mm.o: mm/mm.c 48 gcc -mcmodel=large -fno-builtin -m64 -c mm/mm.c -o mm/mm.o 49 50process.o: process/process.c 51 gcc -mcmodel=large -fno-builtin -m64 -c process/process.c -o process/process.o 52syscall.o: syscall/syscall.c 53 gcc -mcmodel=large -fno-builtin -m64 -c syscall/syscall.c -o syscall/syscall.o 54 55multiboot2.o: driver/multiboot2/multiboot2.c 56 gcc -mcmodel=large -fno-builtin -m64 -c driver/multiboot2/multiboot2.c -o driver/multiboot2/multiboot2.o 57 58clean: 59 rm -rf $(GARBAGE)