###############################################################################
#                                                                             #
# IPFire.org - A linux based firewall                                         #
# Copyright (C) 2007-2023  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

SUMMARY    = Firmware files for PC Engines apu system boards

VER        = 4.19.0.1

THISAPP    = pcengines-apu-firmware-$(VER)
DL_FROM    = $(URL_IPFIRE)
DIR_APP    = $(DIR_SRC)/$(THISAPP)
TARGET     = $(DIR_INFO)/$(THISAPP)
PROG       = pcengines-apu-firmware
PAK_VER    = 16
SUP_ARCH   = x86_64

DEPS       = firmware-update

SERVICES   =

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

objects = \
	apu1_v4.17.0.3.rom \
	apu2_v$(VER).rom \
	apu3_v$(VER).rom \
	apu4_v$(VER).rom \
	apu5_v$(VER).rom \
	apu6_v$(VER).rom \
	apu7_v$(VER).rom

apu1_v4.17.0.3.rom = $(DL_FROM)/apu1_v4.17.0.3.rom
apu2_v$(VER).rom = $(DL_FROM)/apu2_v$(VER).rom
apu3_v$(VER).rom = $(DL_FROM)/apu3_v$(VER).rom
apu4_v$(VER).rom = $(DL_FROM)/apu4_v$(VER).rom
apu5_v$(VER).rom = $(DL_FROM)/apu5_v$(VER).rom
apu6_v$(VER).rom = $(DL_FROM)/apu6_v$(VER).rom
apu7_v$(VER).rom = $(DL_FROM)/apu7_v$(VER).rom

apu1_v4.17.0.3.rom_BLAKE2 = e64c56f6105a206b6af2da4d54bd36d9caa53154b17d5fc32966ee3ed74b0b25749fd10c6936b5b9e526b779c2ef9f1d566915297244e1570c5000b555561aea
apu2_v$(VER).rom_BLAKE2 = e079af4e8f6898a83a0ad2ba2c5af5e89416b58562fd47fb22ba5d9332f88c822efd354e21d486b0002b41769f26fe02cc2b78a3d6b52fc8e95b48ea68c2fb4c
apu3_v$(VER).rom_BLAKE2 = edfff21da4d6391ac89d911ee205445ac714e7813e92b5721e05b2d81701e5891eaf073ebcc282648b09645d88b897a8d2201029888a9cdf09ed7b9503f840da
apu4_v$(VER).rom_BLAKE2 = 5b92cbfe6ac0c75e4a01a18b9c8c0e8abd924b335063edc60944c65bec4edb439d3e1320129cd363e55497590cae7d16a205fdbb33621ff5e9be99e63723eaa1
apu5_v$(VER).rom_BLAKE2 = fbeda636542a78670faaed859bb774b7f380c7e9a5b2efb12865118df96e9a010a611a7e5fee8a88cb05063bc7cec9eaa780974b27b5c3738fbaea8d64de6493
apu6_v$(VER).rom_BLAKE2 = af595261161cb214059906e613dfac72d083a370706c4ae37a9d234348f74ece7e2a9c3ea305dc6a66e73c56e86e42754adf516e828d3cf5923466584c2317e9
apu7_v$(VER).rom_BLAKE2 = 1a22c3d7f13927bb765ec0538e6d79fd9e5bed31fda5b3530901710444232fd007a705cad86318d52b1204448a7b9b020c00fd87eaf41268bbed12a0ebed2f47

install : $(TARGET)

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

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

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

dist:
	@$(PAK)

###############################################################################
# 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)

	# Install firmware to /lib/firmware
	mkdir -pv /lib/firmware/pcengines/apu
	cd $(DIR_DL) && install -v -m 644 $(objects) \
		/lib/firmware/pcengines/apu

	@$(POSTBUILD)
