COMPONENT_TARGETS = $(HARDWARE_INTEL_PC64)
COMPONENT_TARGETS += $(HARDWARE_BAIKAL_M1)
include ../../../build-system/constants.mk
# ======= __END_OF_REQUIRES__ =======
bin_src = package/src/main.rs
cargo_toml = package/Cargo.toml
build_dir = $(TARGET_BUILD_DIR)/build
bin_target = $(TARGET_BUILD_DIR)/main
info_target = $(TARGET_BUILD_DIR)/.info-done
cross_file = $(CURDIR)/$(TARGET_BUILD_DIR)/$(TARGET)-config.toml
BUILD_TARGETS = $(bin_target) $(info_target)
#
# The user may reject the sysroot usage. For this the user have to declare
# the USE_TARGET_DEST_DIR_SYSROOT variable with value 'no':
#
# USE_TARGET_DEST_DIR_SYSROOT = no
#
USE_TARGET_DEST_DIR_SYSROOT = no
include ../../../build-system/core.mk
ARCH = $(shell echo $(TARGET) | cut -f1 -d'-')
cargo-flags = +$(RUST_TOOLCHAIN) --config $(cross_file)
cargo-target-dir = $(CURDIR)/$(TARGET_BUILD_DIR)/target
rust-target = $(TARGET)
$(bin_target): $(cargo_toml) $(bin_src)
@mkdir -p $(build_dir)/
@cp -a package/* $(build_dir)/
@echo "======= Create cross file: ======="
@echo '' > $(cross_file)
@echo '[target.$(rust-target)]' >> $(cross_file)
@echo 'rustflags = [' >> $(cross_file)
@echo ' "-C", "linker=$(CROSS_PREFIX)gcc",' >> $(cross_file)
@echo ' "--cap-lints", "allow",' >> $(cross_file)
@echo ']' >> $(cross_file)
#
# RUSTFLAGS='-C linker=$(CROSS_PREFIX)gcc --cap-lints allow'
#
@echo "======= Build the `basename $(bin_target)` executable: ======="
@cd $(build_dir) && CARGO_HOME=$(CARGO_HOME) \
RUSTUP_HOME=$(RUSTUP_HOME) \
CARGO_BUILD_RUSTC=$(RUSTC) \
CARGO_BUILD_TARGET='$(rust-target)' \
CARGO_TARGET_DIR='$(cargo-target-dir)' \
$(CARGO) $(cargo-flags) build --verbose --release --bin main
@cp $(TARGET_BUILD_DIR)/target/$(TARGET)/release/main $(TARGET_BUILD_DIR)/
@touch $@
$(info_target): $(bin_target)
@echo "==================================="
@echo "======= Environment: ======="
@echo "==================================="
@echo "======= RUST_TOOLCHAIN = '$(RUST_TOOLCHAIN)'"
@echo "======= CARGO_HOME = '$(CARGO_HOME)'"
@echo "======= RUSTUP_HOME = '$(RUSTUP_HOME)'"
@echo "======= RUSTC = '$(RUSTC)'"
@echo "======= RUSTDOC = '$(RUSTDOC)'"
@echo "======= RUSTFMT = '$(RUSTFMT)'"
@echo "======= CBINDGEN = '$(CBINDGEN)'"
@echo "======= RUST_PATH = '$(RUST_PATH)'"
@echo ""
@echo "#"
@echo "# Please find the `basename $(bin_target)` executable in the $(TARGET_BUILD_DIR)/ directory."
@echo "#"
@echo "# Run the `basename $(bin_target)` executable:"
@echo ""
@$(BUILDSYSTEM)/usr/bin/qemu-$(ARCH) \
$(TOOLCHAIN_PATH)/$(TARGET)/sys-root/$(shell $(PATCHELF) --print-interpreter $(bin_target) | sed 's,^\/,,') \
--library-path $(TOOLCHAIN_PATH)/$(TARGET)/lib:$(TOOLCHAIN_PATH)/$(TARGET)/sys-root/lib:$(TOOLCHAIN_PATH)/$(TARGET)/sys-root/usr/lib \
$(bin_target)
@echo ""
@touch $@