1.PHONY: all clean fmt clippy qemu run 2 3# 检查是否需要进行fmt --check 4# 解析命令行参数 5FMT_CHECK?=0 6 7ifeq ($(FMT_CHECK), 1) 8 FMT_CHECK=--check 9else 10 FMT_CHECK= 11endif 12 13export ARCH ?= riscv64 14 15ifeq ($(ARCH), riscv64) 16 RUST_TARGET=riscv64imac-unknown-none-elf 17else 18 @echo "ARCH=$(ARCH) is not supported" 19 @exit 1 20endif 21 22EFI_OUTPUT_DIR?=output 23 24OBJCOPY_FLAGS= 25 26# 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 27 28 29OBJCOPY_FLAGS+= --output-target=binary 30 31export RUSTFLAGS=-Crelocation-model=pic 32 33ifeq ($(ARCH), riscv64) 34 OBJCOPY_FLAGS+= --binary-architecture=riscv 35else 36 @echo "ARCH=$(ARCH) is not supported" 37 @exit 1 38endif 39 40all: 41 @mkdir -p $(EFI_OUTPUT_DIR) 42ifeq ($(ARCH), riscv64) 43 $(MAKE) riscv64imac 44else 45 @echo "ARCH=$(ARCH) is not supported" 46 @exit 1 47endif 48 49riscv64imac: 50 RUSTFLAGS=$(RUSTFLAGS) cargo build --release --target riscv64imac-unknown-none-elf 51 rust-objcopy $(OBJCOPY_FLAGS) target/$(RUST_TARGET)/release/dragon_boot $(EFI_OUTPUT_DIR)/dragon_boot-riscv64imac.efi 52 53run: 54 @$(MAKE) all || exit 1 55 @$(MAKE) qemu 56 57clean: 58 @cargo clean 59 60 61fmt: 62 @cargo fmt --all $(FMT_CHECK) 63 64clippy: 65 @cargo clippy --all --target $(RUST_TARGET) --all-features 66 67 68qemu: 69 cd tools && ./run-qemu.sh && cd .. 70