From d8d5955b6084d7a626efbeb5606537a2e90d23ee Mon Sep 17 00:00:00 2001 From: zhangxinyu <840317537@qq.com> Date: Wed, 17 May 2023 14:21:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E7=94=A8=E6=88=B7=E7=A8=8B?= =?UTF-8?q?=E5=BA=8FMakefile,=20=E7=8E=B0=E5=9C=A8=E5=8F=AF=E4=BB=A5build?= =?UTF-8?q?=E5=87=BA=E6=9D=A5=E4=BA=8C=E8=BF=9B=E5=88=B6=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ch2/user/Makefile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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