Newer
Older
tree-os / Makefile
  1. CC = i686-elf-gcc
  2. CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0
  3. LD = i686-elf-ld
  4. LD_FLAGS = -z max-page-size=0x1000 -T linker.ld
  5. AS = nasm
  6. ASFlAGS = -felf32
  7. GENISO = genisoimage
  8. GENISOFLAGS = -R -b boot/grub/stage2_eltorito -no-emul-boot -boot-load-size 4 -input-charset utf8 -quiet -boot-info-table -A tree-os
  9. EMU = qemu-system-x86_64
  10. EMUFLAGS = -m 256M -drive format=raw,file=tree-os.iso -drive format=raw,file=disk.img,id=disk,if=none -device ahci,id=ahci -device ide-hd,drive=disk,bus=ahci.0
  11.  
  12.  
  13. BUILD_FOLDER = build
  14.  
  15. SOURCE_FILES := $(shell find src -name *.c -or -name *.asm -or -name *.s)
  16. OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o)
  17.  
  18. run: tree-os.iso
  19. @echo "starting qemu"
  20. @$(EMU) $(EMUFLAGS)
  21.  
  22. tree-os.iso: iso/boot/tree-os.bin
  23. @echo "creating the iso image"
  24. @grub-mkrescue -o $@ iso
  25.  
  26. iso/boot/tree-os.bin: linker.ld $(OBJS)
  27. @echo "linking"
  28. @$(LD) $(LD_FLAGS) -o $@ $(OBJS)
  29.  
  30. $(BUILD_FOLDER)/%.asm.o: %.asm
  31. @echo "asembling $<"
  32. @mkdir -p $(dir $@)
  33. @$(AS) $(ASFlAGS) $< -o $@
  34.  
  35. $(BUILD_FOLDER)/%.c.o: %.c
  36. @echo "compiling $<"
  37. @mkdir -p $(dir $@)
  38. @$(CC) $(CCFLAGS) -r $< -o $@
  39.  
  40. $(BUILD_FOLDER)/%.s.o: %.s
  41. @echo "assembling $<"
  42. @mkdir -p $(dir $@)
  43. @$(CC) $(CCFLAGS) -r $< -o $@
  44.  
  45. clean:
  46. @echo "clearing build folder"
  47. @rm -r $(BUILD_FOLDER) tree-os.iso
  48.  
  49. cleanELF:
  50. @echo "clearing the elf file"
  51. @rm iso/boot/tree-os.elf