Makefile 893 B

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