Makefile 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 -m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs \
  10. -Wall -Wextra -Werror
  11. # First rule is run by default
  12. os-image.bin: boot/bootsect.bin kernel.bin
  13. cat $^ > os-image.bin
  14. # '--oformat binary' deletes all symbols as a collateral, so we don't need
  15. # to 'strip' them manually on this case
  16. kernel.bin: boot/kernel_entry.o ${OBJ}
  17. i386-elf-ld -o $@ -Ttext 0x1000 $^ --oformat binary
  18. # Used for debugging purposes
  19. kernel.elf: boot/kernel_entry.o ${OBJ}
  20. i386-elf-ld -o $@ -Ttext 0x1000 $^
  21. run: os-image.bin
  22. qemu-system-i386 -fda os-image.bin
  23. # Open the connection to qemu and load our kernel-object file with symbols
  24. debug: os-image.bin kernel.elf
  25. qemu-system-i386 -s -fda os-image.bin -d guest_errors,int &
  26. ${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
  27. # Generic rules for wildcards
  28. # To make an object, always compile from its .c
  29. %.o: %.c ${HEADERS}
  30. ${CC} ${CFLAGS} -ffreestanding -c $< -o $@
  31. %.o: %.asm
  32. nasm $< -f elf -o $@
  33. %.bin: %.asm
  34. nasm $< -f bin -o $@
  35. clean:
  36. rm -rf *.bin *.dis *.o os-image.bin *.elf
  37. rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o cpu/*.o