Makefile 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. .PHONY: all clean fmt clippy qemu run
  2. # 检查是否需要进行fmt --check
  3. # 解析命令行参数
  4. FMT_CHECK?=0
  5. ifeq ($(FMT_CHECK), 1)
  6. FMT_CHECK=--check
  7. else
  8. FMT_CHECK=
  9. endif
  10. export ARCH ?= riscv64
  11. ifeq ($(ARCH), riscv64)
  12. RUST_TARGET=riscv64imac-unknown-none-elf
  13. else
  14. @echo "ARCH=$(ARCH) is not supported"
  15. @exit 1
  16. endif
  17. EFI_OUTPUT_DIR?=output
  18. OBJCOPY_FLAGS=
  19. # OBJCOPY_FLAGS+=-j .header -j .text -j .plt -j .sdata -j .data -j .dynamic -j .dynstr -j .dynsym -j .rel -j .rel.* -j .rela* -j .reloc -j .reloc* -j .sbss
  20. OBJCOPY_FLAGS+= --output-target=binary
  21. export RUSTFLAGS=-Crelocation-model=pic
  22. ifeq ($(ARCH), riscv64)
  23. OBJCOPY_FLAGS+= --binary-architecture=riscv
  24. else
  25. @echo "ARCH=$(ARCH) is not supported"
  26. @exit 1
  27. endif
  28. all:
  29. @mkdir -p $(EFI_OUTPUT_DIR)
  30. ifeq ($(ARCH), riscv64)
  31. $(MAKE) riscv64imac
  32. else
  33. @echo "ARCH=$(ARCH) is not supported"
  34. @exit 1
  35. endif
  36. riscv64imac:
  37. RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target riscv64imac-unknown-none-elf
  38. rust-objcopy $(OBJCOPY_FLAGS) target/$(RUST_TARGET)/release/dragon_boot $(EFI_OUTPUT_DIR)/dragon_boot-riscv64imac.efi
  39. run:
  40. @$(MAKE) all || exit 1
  41. @$(MAKE) qemu
  42. clean:
  43. @cargo clean
  44. fmt:
  45. @cargo fmt --all $(FMT_CHECK)
  46. clippy:
  47. @cargo clippy --all --target $(RUST_TARGET) --all-features
  48. qemu:
  49. cd tools && ./run-qemu.sh && cd ..