Newer
Older
honey-os / Makefile
  1. IMAGE_FILE = /run/user/1000/honey-os.img
  2.  
  3. CC = i686-elf-gcc
  4. CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I src/include -I src/kernel/include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0
  5. LD = i686-elf-ld
  6. LD_FLAGS = -z max-page-size=0x1000 -T link.ld
  7. AS = nasm
  8. ASFlAGS = -felf32
  9. EMU = qemu-system-x86_64
  10. EMUFLAGS = -m 1G -drive if=none,id=stick,format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci -device usb-mouse -device usb-storage,drive=stick -device usb-kbd
  11.  
  12. BUILD_FOLDER = build
  13.  
  14. SOURCE_FILES := $(shell find src/kernel -name *.c -or -name *.asm -or -name *.s)
  15. OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o)
  16. USER_PROGRAMS := $(shell tree -d -L 1 -i --noreport src/userland/ | tail -n+2)
  17. USER_PROGRAM_NAMES := $(USER_PROGRAMS:%=user/%)
  18. USER_PROGRAM_FILES := $(USER_PROGRAMS:%=initrd/%)
  19.  
  20. run: build initrd user/hlib $(USER_PROGRAM_NAMES) $(IMAGE_FILE)
  21. @echo "starting qemu"
  22. @$(EMU) $(EMUFLAGS)
  23.  
  24. build:
  25. @mkdir build
  26.  
  27. initrd:
  28. @mkdir initrd
  29.  
  30. $(IMAGE_FILE): rootfs/boot/kernel rootfs/initrd.tar
  31. @echo "creating the iso image"
  32. @dd if=/dev/zero of=$(IMAGE_FILE) bs=512 count=32768 &&\
  33. printf "n\np\n1\n\n\na\nw\n" | fdisk $(IMAGE_FILE) &&\
  34. loop0=$$(sudo losetup -f) &&\
  35. sudo losetup $$loop0 $(IMAGE_FILE) &&\
  36. loop1=$$(sudo losetup -f) &&\
  37. sudo losetup $$loop1 $(IMAGE_FILE) -o 1048576 &&\
  38. sudo mkfs.fat -F16 $$loop1 &&\
  39. sudo mount $$loop1 /mnt &&\
  40. sudo grub-install --root-directory=/mnt --no-floppy --modules="normal part_msdos multiboot" $$loop0 &&\
  41. sudo cp -RT rootfs/ /mnt &&\
  42. sync &&\
  43. sudo umount /mnt &&\
  44. sudo losetup -d $$loop0 &&\
  45. sudo losetup -d $$loop1
  46.  
  47. rootfs/initrd.tar: $(USER_PROGRAM_FILES)
  48. tar cvf rootfs/initrd.tar initrd/
  49.  
  50. rootfs/boot/kernel: $(OBJS) link.ld
  51. @echo "linking"
  52. @$(LD) $(LD_FLAGS) -o $@ $(OBJS)
  53.  
  54. $(BUILD_FOLDER)/%.asm.o: %.asm
  55. @echo "asembling $<"
  56. @mkdir -p $(dir $@)
  57. @$(AS) $(ASFlAGS) $< -o $@
  58.  
  59. $(BUILD_FOLDER)/%.c.o: %.c
  60. @echo "compiling $<"
  61. @mkdir -p $(dir $@)
  62. @$(CC) $(CCFLAGS) -r $< -o $@
  63.  
  64. $(BUILD_FOLDER)/%.s.o: %.s
  65. @echo "assembling $<"
  66. @mkdir -p $(dir $@)
  67. @$(CC) $(CCFLAGS) -r $< -o $@
  68.  
  69. user/%: src/userland/%
  70. @echo "compiling userspace program $<"
  71. @make -C $<
  72.  
  73. clean:
  74. @echo "clearing build folder"
  75. @rm -r $(BUILD_FOLDER)