mirror of
https://github.com/rcore-os/rCore-Tutorial-v3.git
synced 2024-11-24 10:26:25 +04:00
39 lines
1.1 KiB
Makefile
39 lines
1.1 KiB
Makefile
TARGET := riscv64gc-unknown-none-elf
|
|
MODE := release
|
|
APP_DIR := src/bin
|
|
TARGET_DIR := target/$(TARGET)/$(MODE)
|
|
BUILD_DIR := build
|
|
OBJDUMP := rust-objdump --arch-name=riscv64
|
|
OBJCOPY := rust-objcopy --binary-architecture=riscv64
|
|
PY := python3
|
|
|
|
TEST ?= 0
|
|
ifeq ($(TEST), 0)
|
|
APPS := $(filter-out $(wildcard $(APP_DIR)/test*.rs), $(wildcard $(APP_DIR)/*.rs))
|
|
else
|
|
APPS := $(wildcard $(APP_DIR)/test$(TEST)*.rs)
|
|
endif
|
|
ELFS := $(patsubst $(APP_DIR)/%.rs, $(TARGET_DIR)/%, $(APPS))
|
|
|
|
binary:
|
|
# @echo $(ELFS)
|
|
@cargo build --release
|
|
@$(foreach elf, $(ELFS), \
|
|
$(OBJCOPY) $(elf) --strip-all -O binary $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.bin, $(elf)); \
|
|
cp $(elf) $(patsubst $(TARGET_DIR)/%, $(TARGET_DIR)/%.elf, $(elf));)
|
|
|
|
pre:
|
|
@mkdir -p $(BUILD_DIR)/bin/
|
|
@mkdir -p $(BUILD_DIR)/elf/
|
|
@mkdir -p $(BUILD_DIR)/app/
|
|
@$(foreach t, $(APPS), cp $(t) $(BUILD_DIR)/app/;)
|
|
|
|
build: clean pre binary
|
|
@$(foreach t, $(ELFS), cp $(t).bin $(BUILD_DIR)/bin/;)
|
|
@$(foreach t, $(ELFS), cp $(t).elf $(BUILD_DIR)/elf/;)
|
|
|
|
clean:
|
|
@cargo clean
|
|
@rm -rf $(BUILD_DIR)
|
|
|
|
.PHONY: elf binary build clean |