Makefile 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. C_SOURCES = $(wildcard kernel/*.c drivers/*.c)
  2. HEADERS = $(wildcard kernel/*.h drivers/*.h)
  3. OBJ = ${C_SOURCES:.c=.o}
  4. # Change this if your cross-compiler is somewhere else
  5. CC = /usr/local/i386elfgcc/bin/i386-elf-gcc
  6. GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
  7. # -g: Use debugging symbols
  8. CFLAGS = -g
  9. # First rule is run by default
  10. os-image.bin: boot/bootsect.bin kernel.bin
  11. cat $^ > os-image.bin
  12. kernel.bin: kernel.elf
  13. i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary
  14. run: os-image.bin
  15. qemu-system-i386 -fda os-image.bin
  16. debug: os-image.bin kernel.elf
  17. qemu-system-i386 -s -fda os-image.bin &
  18. ${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
  19. # To build the kernel: make all objects first
  20. kernel.elf: boot/kernel_entry.o ${OBJ}
  21. i386-elf-ld -o $@ -Ttext 0x1000 $^
  22. # To make an object, always compile from its .c
  23. %.o: %.c ${HEADERS}
  24. ${CC} ${CFLAGS} -ffreestanding -c $< -o $@
  25. # Object files from asm files
  26. %.o: %.asm
  27. nasm $< -f elf -o $@
  28. %.bin: %.asm
  29. nasm $< -f bin -o $@
  30. clean:
  31. rm -rf *.bin *.dis *.o os-image.bin *.elf
  32. rm -rf kernel/*.o boot/*.bin drivers/*.o