Makefile 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c libc/*.c)
  2. HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h libc/*.h)
  3. # Nice syntax for file extension replacement
  4. OBJ = ${C_SOURCES:.c=.o cpu/interrupt.o}
  5. # Change this if your cross-compiler is somewhere else
  6. CC = /usr/local/i386elfgcc/bin/i386-elf-gcc
  7. GDB = /usr/local/i386elfgcc/bin/i386-elf-gdb
  8. # -g: Use debugging symbols in gcc
  9. CFLAGS = -g
  10. # First rule is run by default
  11. os-image.bin: boot/bootsect.bin kernel.bin
  12. cat $^ > os-image.bin
  13. # '--oformat binary' deletes all symbols as a collateral, so we don't need
  14. # to 'strip' them manually on this case
  15. kernel.bin: boot/kernel_entry.o ${OBJ}
  16. i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary
  17. # Used for debugging purposes
  18. kernel.elf: boot/kernel_entry.o ${OBJ}
  19. i386-elf-ld -o $@ -Ttext 0x1000 $^
  20. run: os-image.bin
  21. qemu-system-i386 -fda os-image.bin
  22. # Open the connection to qemu and load our kernel-object file with symbols
  23. debug: os-image.bin kernel.elf
  24. qemu-system-i386 -s -fda os-image.bin -d guest_errors,int &
  25. ${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
  26. # Generic rules for wildcards
  27. # To make an object, always compile from its .c
  28. %.o: %.c ${HEADERS}
  29. ${CC} ${CFLAGS} -ffreestanding -c $< -o $@
  30. %.o: %.asm
  31. nasm $< -f elf -o $@
  32. %.bin: %.asm
  33. nasm $< -f bin -o $@
  34. clean:
  35. rm -rf *.bin *.dis *.o os-image.bin *.elf
  36. rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o cpu/*.o