Advertisement
MichaelPetch

Makefile

Sep 3rd, 2019
424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. C_SOURCES = $(wildcard kernel/*.c drivers/*.c cpu/*.c libc/*.c fs/*.c)
  2. NASM_SOURCES = $(wildcard kernel/*.asm drivers/*.asm cpu/*.asm libc/*.asm fs/*.asm)
  3. HEADERS = $(wildcard kernel/*.h drivers/*.h cpu/*.h libc/*.h fs/*.h)
  4. S_SOURCES = $(wildcard kernel/*.s drivers/*.s cpu/*.s libc/*.s fs/*.s *.s)
  5.  
  6. # Nice syntax for file extension replacement
  7. OBJ = ${C_SOURCES:.c=.o} ${NASM_SOURCES:.asm=.o} ${S_SOURCES:.s=.o}
  8.  
  9. # Change this if your cross-compiler is somewhere else
  10. CC = /usr/bin/i686-elf-gcc
  11. GDB = gdb
  12. # -g: Use debugging symbols in gcc
  13. CFLAGS = -g #-m32 -nostdlib -nostdinc -fno-builtin -fno-stack-protector -nostartfiles -nodefaultlibs -Wall -Wextra
  14.  
  15. # First rule is run by default
  16. myos.iso: kernel.elf
  17. grub-file --is-x86-multiboot kernel.elf
  18. mkdir -p isodir/boot/grub
  19. cp kernel.elf isodir/boot/os-image.bin
  20. cp grub.cfg isodir/boot/grub/grub.cfg
  21. grub-mkrescue -o myos.iso isodir
  22.  
  23. # '--oformat binary' deletes all symbols as a collateral, so we don't need
  24. # to 'strip' them manually on this case
  25. kernel.bin: kernel.elf
  26. objcopy -O binary $^ $@
  27.  
  28. # Used for debugging purposes
  29. kernel.elf: ${OBJ}
  30. i686-elf-ld -melf_i386 -o $@ -T linker.ld $^
  31.  
  32. run: myos.iso
  33. qemu-system-x86_64 -soundhw pcspk -device isa-debug-exit,iobase=0xf4,iosize=0x04 -boot menu=on -cdrom myos.iso
  34.  
  35. iso: myos.iso
  36. cp myos.iso doneiso/
  37. # Open the connection to qemu and load our kernel-object file with symbols
  38. debug: myos.iso
  39. qemu-system-x86_64 -soundhw pcspk -device isa-debug-exit,iobase=0xf4,iosize=0x04 -s -S -boot menu=on -cdrom myos.iso &
  40. ${GDB} -ex "target remote localhost:1234" -ex "symbol-file kernel.elf"
  41.  
  42. # Generic rules for wildcards
  43. # To make an object, always compile from its .c $< $@
  44. %.o: %.c ${HEADERS}
  45. i686-elf-gcc -O2 -g -MD -c $< -o $@ -std=gnu11
  46.  
  47. %.o: %.s
  48. i686-elf-gcc -O2 -g -MD -c $< -o $@
  49.  
  50. %.o: %.asm
  51. nasm -g -f elf32 -F dwarf -o $@ $<
  52.  
  53. clean:
  54. rm -rf *.bin *.dis *.o os-image.bin *.elf *.iso
  55. rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o cpu/*.o libc/*.o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement