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

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

DEPS       = firmware-update

SERVICES   =

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

objects = \
	apu1_v$(VER).rom \
	apu2_v$(VER).rom \
	apu3_v$(VER).rom \
	apu4_v$(VER).rom \
	apu5_v$(VER).rom \
	apu6_v$(VER).rom

apu1_v$(VER).rom = $(DL_FROM)/apu1_v$(VER).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

apu1_v$(VER).rom_BLAKE2 = 3223d7ca35797a3e4eaea993fd93eeece842e46829cf3a39625ad3a3b5eceb241812b25198a94545f4de42b4bf2d31503746f08e9b361cff2d7ce11ec0ba24d9
apu2_v$(VER).rom_BLAKE2 = 8d6ddb76189813546c3594ef9f92e341e99cbec8bb3df414589625815269b2fe0973a01185a35f0afe9dd16949ccaccc3d9bf3baee2de696450dfd17c96175d7
apu3_v$(VER).rom_BLAKE2 = 64405157e7bfeca467b70fe4982a844763ed3b1c95d7aac75210cbb14e7e0de0a6c34708002a5be94344eaf96cd1d187ce03e8c0d0f8597048e70c7ab9fa6e14
apu4_v$(VER).rom_BLAKE2 = 4a29d17b2040edc880aea277789cc6158b00c834dba110b2eda2692a1571d51e01cfdec361ca4acdcfc019e4ae904c55dafff18020e7d23eabec5037f4ca7369
apu5_v$(VER).rom_BLAKE2 = db3b87945578a2a86b17d998e2fc316b654a78201b852804ae7067b92d22033817d5a77da3736d31ec54ef5d296ad38e735709a232e9e6cad9674e543306cff6
apu6_v$(VER).rom_BLAKE2 = e9a8bd06658f7df4c09ad304145272419bef7022d0ac577b0f8777f75b90e020790cbfba9c6a2fd5abf52205901ec735b6e2fe52fa9d22040a12b13e0959fb65

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)
