###############################################################################
#                                                                             #
# IPFire.org - A linux based firewall                                         #
# Copyright (C) 2007-2025  IPFire Team  <info@ipfire.org>                     #
#                                                                             #
# This program is free software: you can redistribute it and/or modify        #
# it under the terms of the GNU General Public License as published by        #
# the Free Software Foundation, either version 3 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# This program is distributed in the hope that it will be useful,             #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
#                                                                             #
###############################################################################

###############################################################################
# Definitions
###############################################################################

include Config

VER        = 1.92.0

# https://forge.rust-lang.org/infra/other-installation-methods.html#standalone-installers

THISAPP    = rust-$(VER)
DL_FILE    = $(THISAPP)-$(RUST_PLATFORM).tar.gz
DL_FROM    = $(URL_IPFIRE)
DIR_APP    = $(DIR_SRC)/$(THISAPP)-$(RUST_PLATFORM)
TARGET     = $(DIR_INFO)/$(THISAPP)

###############################################################################
# Top-level Rules
###############################################################################

objects = $(DL_FILE)

$(DL_FILE) = $(DL_FROM)/$(DL_FILE)

$(THISAPP)-x86_64-unknown-linux-gnu.tar.gz_BLAKE2 = 2a137a994632cbc572cb286975440f723420de37d5d29e7523242bfe5ae50a4d0f303f0c0ac8a38bc12fb9bec716f2e699234a2fe858ed647ec1bfd1a77d9adb
$(THISAPP)-aarch64-unknown-linux-gnu.tar.xz_BLAKE2 = 268524a8066b68dfc2aa4fa524679b3ecc1bf47f74aab47b794eeb0a3ecc76255b7056ad1a852512a52a06802a2dc457bba8c60107d0cb9b464215c344c5430d
$(THISAPP)-riscv64gc-unknown-linux-gnu.tar.xz_BLAKE2 = e9b200abbd0e294019cd99bb3c6768615ce0bbb7609b3c723a0a57a0d697bdc438c691523f8487b14a9c9397eff0f56b02662b0eb78e057d03100d1ab8d888d6
$(THISAPP)-loongarch64-unknown-linux-gnu.tar.gz_BLAKE2 = f1bc66476a86d9ccf0dab691dcd19f51c95e6574a23302a37d8ad0b2df1f3685ce428430d635b589f0908cf9415b012a40e68a2a6b554b19c14a06b70e9233a8

install : $(TARGET)

check : $(patsubst %,$(DIR_CHK)/%,$(objects))

download :$(patsubst %,$(DIR_DL)/%,$(objects))

b2 : $(subst %,%_BLAKE2,$(objects))

###############################################################################
# Downloading, checking, b2sum
###############################################################################

$(patsubst %,$(DIR_CHK)/%,$(objects)) :
	@$(CHECK)

$(patsubst %,$(DIR_DL)/%,$(objects)) :
	@$(LOAD)

$(subst %,%_BLAKE2,$(objects)) :
	@$(B2SUM)

###############################################################################
# Installation Details
###############################################################################

$(TARGET) : $(patsubst %,$(DIR_DL)/%,$(objects))
	@$(PREBUILD)
	@rm -rf $(DIR_APP) && cd $(DIR_SRC) && tar axf $(DIR_DL)/$(DL_FILE)

	cd $(DIR_APP) && ./install.sh \
		--components=cargo,rustc,rust-std-$(RUST_PLATFORM) \
		--prefix=/usr \
		--disable-ldconfig

	# Create local registry
	mkdir -pv $(CARGO_REGISTRY)

	@rm -rf $(DIR_APP)
	@$(POSTBUILD)
