Advertisement
MichaelPetch

Makefile

Sep 3rd, 2019
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 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. os-image.bin: 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 DripOS.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: os-image.bin
  33. echo "------------NOTE----------------"
  34. echo "Please select floppy drive as boot drive"
  35. echo "------------NOTE----------------"
  36. qemu-system-x86_64 -soundhw pcspk -device isa-debug-exit,iobase=0xf4,iosize=0x04 -boot menu=on -cdrom DripOS.iso -hdb dripdisk.img
  37.  
  38. myos.iso: os-image.bin
  39. dd if=/dev/zero of=floppy.img bs=1024 count=1440
  40. dd if=os-image.bin of=floppy.img seek=0 conv=notrunc
  41. cp floppy.img iso/
  42. genisoimage -quiet -V 'DRIPOS' -input-charset iso8859-1 -o myos.iso -b floppy.img iso/
  43.  
  44. iso: myos.iso
  45. cp myos.iso doneiso/
  46. # Open the connection to qemu and load our kernel-object file with symbols
  47. debug: os-image.bin
  48. qemu-system-x86_64 -soundhw pcspk -device isa-debug-exit,iobase=0xf4,iosize=0x04 -s -S -boot menu=on -fda boot/bootsect.bin -hdb dripdisk.img -hda kernel.bin &
  49. ${GDB} -ex "target remote localhost:1234" -ex "symbol-file bootsect.elf"
  50.  
  51. # Generic rules for wildcards
  52. # To make an object, always compile from its .c $< $@
  53. %.o: %.c ${HEADERS}
  54. i686-elf-gcc -O2 -g -MD -c $< -o $@ -std=gnu11
  55.  
  56. %.o: %.s
  57. i686-elf-gcc -O2 -g -MD -c $< -o $@
  58.  
  59. %.o: %.asm
  60. nasm -g -f elf32 -F dwarf -o $@ $<
  61.  
  62. clean:
  63. rm -rf *.bin *.dis *.o os-image.bin *.elf *.iso
  64. rm -rf kernel/*.o boot/*.bin drivers/*.o boot/*.o cpu/*.o libc/*.o
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement