Makefile 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. arch := x86_64
  2. target := x86_64-unknown-none
  3. mode := release
  4. kernel := target/$(target)/$(mode)/$(arch)
  5. img := target/$(target)/$(mode)/img
  6. accel ?= on
  7. tcp ?= on
  8. sysroot := $(shell rustc --print sysroot)
  9. objdump := $(shell find $(sysroot) -name llvm-objdump) --arch-name=$(arch)
  10. objcopy := $(shell find $(sysroot) -name llvm-objcopy)
  11. BUILD_ARGS += --target $(target)
  12. ifeq ($(mode), release)
  13. BUILD_ARGS += --release
  14. endif
  15. ifeq ($(tcp), on)
  16. BUILD_ARGS += --features tcp
  17. else
  18. BUILD_ARGS += --no-default-features
  19. endif
  20. QEMU_ARGS += \
  21. -machine q35 \
  22. -serial mon:stdio \
  23. -kernel $(kernel) \
  24. -device virtio-gpu-pci -vga none \
  25. -device virtio-blk-pci,drive=x0 -drive file=$(img),if=none,format=raw,id=x0 \
  26. -device virtio-net-pci,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:5555
  27. ifeq ($(accel), on)
  28. QEMU_ARGS += -cpu host -accel kvm
  29. endif
  30. .PHONY: kernel clean qemu run env
  31. kernel:
  32. cargo build $(BUILD_ARGS) --config 'build.rustflags="--cfg platform=\"qemu\" -Clink-args=-Tlinker.ld -Clink-args=-no-pie"'
  33. env:
  34. rustup component add llvm-tools-preview rustfmt
  35. rustup target add $(target)
  36. asm: kernel
  37. $(objdump) -d $(kernel) | less
  38. sym: kernel
  39. $(objdump) -t $(kernel) | less
  40. header: kernel
  41. $(objdump) -x $(kernel) | less
  42. clean:
  43. cargo clean
  44. qemu: kernel $(img)
  45. # Wait a few seconds, then try to open a connection to the VM so it can test its networking.
  46. ( sleep 4 && echo "hello" | nc localhost 5555 -N -v) &
  47. qemu-system-$(arch) $(QEMU_ARGS)
  48. $(img):
  49. dd if=/dev/zero of=$@ bs=512 count=32
  50. run: qemu