Makefile 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. SUBDIR_ROOTS := . common
  2. DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
  3. GARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ kernel
  4. GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS)))
  5. DIR_LIB=lib
  6. lib_patterns := *.a
  7. LIB_FILES := $(foreach DIR,$(DIR_LIB),$(addprefix $(DIR)/,$(lib_patterns)))
  8. all: kernel
  9. objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary kernel ../bin/kernel/kernel.bin
  10. kernel: head.o entry.o main.o printk.o trap.o mm.o irq.o 8259A.o process.o
  11. 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 -T link.lds
  12. head.o: head.S
  13. gcc -E head.S > head.s # 预处理
  14. as --64 -o head.o head.s
  15. entry.o: exception/entry.S
  16. gcc -E exception/entry.S > exception/entry.s
  17. as --64 -o exception/entry.o exception/entry.s
  18. main.o: main.c
  19. # -fno-builtin: 不使用C语言内建函数
  20. # The -m64 option sets int to 32bits and long and pointer to 64 bits and generates code for AMD’s x86-64 architecture.
  21. gcc -mcmodel=large -fno-builtin -m64 -c main.c -o main.o
  22. printk.o: common/printk.c
  23. gcc -mcmodel=large -fno-builtin -m64 -c common/printk.c -o common/printk.o
  24. trap.o: exception/trap.c
  25. gcc -mcmodel=large -fno-builtin -m64 -c exception/trap.c -o exception/trap.o
  26. irq.o: exception/irq.c
  27. gcc -mcmodel=large -fno-builtin -m64 -c exception/irq.c -o exception/irq.o
  28. 8259A.o: exception/8259A.c
  29. gcc -mcmodel=large -fno-builtin -m64 -c exception/8259A.c -o exception/8259A.o
  30. mm.o: mm/mm.c
  31. gcc -mcmodel=large -fno-builtin -m64 -c mm/mm.c -o mm/mm.o
  32. process.o: process/process.c
  33. gcc -mcmodel=large -fno-builtin -m64 -c process/process.c -o process/process.o
  34. clean:
  35. rm -rf $(GARBAGE)