Advertisement
MichaelPetch

Makefile Toyos

Sep 7th, 2020
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. #TODO: Update this to put everything into a build directory
  2.  
  3. BOOTOUTPUT = boot.bin
  4. OSOUTPUT = os.bin
  5. SRCS = $(wildcard kernel/*.c)
  6. CINC = $(wildcard kernel/*.h)
  7. OBJS = $(patsubst %.c, %.o, $(SRCS))
  8.  
  9. #Final step in the build process
  10. $(OSOUTPUT): kernel.bin $(BOOTOUTPUT)
  11. cat $(BOOTOUTPUT) kernel.bin > $(OSOUTPUT)
  12.  
  13. #Assemble the boot sector code
  14. $(BOOTOUTPUT): boot/bootsector.asm
  15. nasm -f bin boot/bootsector.asm -o $(BOOTOUTPUT)
  16.  
  17. #Compile all the kernel files
  18. %.o:%.c $(CINC)
  19. gcc -m32 -ffreestanding -fno-pie -fno-stack-protector -nostdlib -c $< -o $@
  20.  
  21. #Assemble the kernel entry code
  22. kernelEntry.o: boot/kernelEntry.asm
  23. nasm boot/kernelEntry.asm -f elf32 -o kernelEntry.o
  24.  
  25. #Link all the .o files with the kernel entry
  26. kernel.bin: kernelEntry.o $(OBJS)
  27. ld -melf_i386 -o kernel.bin -Ttext 0x1000 $^ --oformat binary
  28.  
  29. run:
  30. qemu-system-x86_64 -fda $(OSOUTPUT)
  31.  
  32. clean:
  33. rm -f *.bin *.o $(OBJS)
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement