1*ead838bfSfslongjinSUBDIR_ROOTS := . common 2*ead838bfSfslongjinDIRS := . $(shell find $(SUBDIR_ROOTS) -type d) 3*ead838bfSfslongjinGARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ kernel *.a 4*ead838bfSfslongjinGARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS))) 5f479f321Sfslongjin 6f479f321Sfslongjinall: kernel 7f479f321Sfslongjin objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary kernel ../bin/kernel/kernel.bin 8f479f321Sfslongjin 9f479f321Sfslongjin 10*ead838bfSfslongjinkernel: head.o main.o printk.o 11*ead838bfSfslongjin ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o printk.o -T link.lds 12f479f321Sfslongjin 13f479f321Sfslongjinhead.o: head.S 14f479f321Sfslongjin gcc -E head.S > head.s # 预处理 15f479f321Sfslongjin as --64 -o head.o head.s 16f479f321Sfslongjin 17*ead838bfSfslongjinmain.o: main.c 18*ead838bfSfslongjin# -fno-builtin: 不使用C语言内建函数 19*ead838bfSfslongjin# The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture. 20*ead838bfSfslongjin gcc -mcmodel=large -fno-builtin -m64 -c main.c -fno-stack-protector 21*ead838bfSfslongjin 22*ead838bfSfslongjin 23*ead838bfSfslongjinprintk.o: common/printk.c 24*ead838bfSfslongjin gcc -mcmodel=large -fno-builtin -m64 -c common/printk.c -fno-stack-protector 25*ead838bfSfslongjin 26f479f321Sfslongjinclean: 27*ead838bfSfslongjin rm -rf $(GARBAGE)