diff --git a/ch2/user/Makefile b/ch2/user/Makefile index 3935639..f2ee41e 100644 --- a/ch2/user/Makefile +++ b/ch2/user/Makefile @@ -1,16 +1,28 @@ MODE := release TARGET := riscv64gc-unknown-none-elf - +OBJDUMP := rust-objdump --arch-name=riscv64 +OBJCOPY := rust-objcopy --binary-architecture=riscv64 RUST_FLAGS := -Clink-arg=-Tsrc/linker.ld # 使用我们自己的链接脚本 RUST_FLAGS += -Cforce-frame-pointers=yes # 强制编译器生成帧指针 RUST_FLAGS:=$(strip ${RUST_FLAGS}) +APP_DIR := src/bin +TARGET_DIR := target/$(TARGET)/$(MODE) +APPS := $(wildcard $(APP_DIR)/*.rs) +ELFS := $(patsubst $(APP_DIR)/%.rs, $(TARGET_DIR)/%, $(APPS)) +BINS := $(patsubst $(APP_DIR)/%.rs, $(TARGET_DIR)/%.bin, $(APPS)) + + # 编译elf文件 build_elf: clean CARGO_BUILD_RUSTFLAGS="$(RUST_FLAGS)" \ cargo build --$(MODE) --target=$(TARGET) +build: build_elf + @$(foreach elf, $(ELFS), $(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf));) + + clean: rm -rf ./target* \ No newline at end of file