# Template file for 'linux-firmware'
pkgname=linux-firmware
version=20230210
revision=1
depends="${pkgname}-amd>=${version}_${revision} ${pkgname}-network>=${version}_${revision}"
short_desc="Binary firmware blobs for the Linux kernel"
maintainer="Érico Nogueira <ericonr@disroot.org>"
license="See /usr/share/licenses/${pkgname}"
homepage="https://www.kernel.org/"
distfiles="https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git/snapshot/${pkgname}-${version}.tar.gz"
checksum=ccc2ff9d475f368fa915e509fddb2c3815189f9461a008db1af0f096a2bfdbd3
python_version=3
nostrip=yes

subpackages="linux-firmware-amd linux-firmware-broadcom
 linux-firmware-intel linux-firmware-nvidia linux-firmware-network
 linux-firmware-qualcomm"

do_install() {
	make install FIRMWAREDIR=/usr/lib/firmware DESTDIR=$DESTDIR

	for _l in LICEN* WHENCE
	do
		vlicense "$_l"
	done

	# XXX: should some firmwares, like carl9170, be pruned?
}

linux-firmware-amd_package() {
	short_desc+=" - AMD CPU/GPU microcode"
	nostrip=yes
	pkg_install() {
		vmove usr/lib/firmware/amd*
		vmove usr/lib/firmware/radeon
		vmove usr/share/licenses/linux-firmware/LICENSE.amdgpu
		vmove usr/share/licenses/linux-firmware/LICENSE.amd-ucode
		vmove usr/share/licenses/linux-firmware/LICENSE.radeon
	}
}

linux-firmware-broadcom_package() {
	short_desc+=" - Broadcom network blobs"
	nostrip=yes
	replaces="rpi-firmware-network>=0"
	pkg_install() {
		vmove usr/lib/firmware/brcm
		vmove usr/share/licenses/linux-firmware/LICENCE.broadcom_bcm43xx
		# firmware/brcm contains multiple symlinks to ../cypress/
		vmove usr/lib/firmware/cypress
		vmove usr/share/licenses/linux-firmware/LICENCE.cypress
	}
}

linux-firmware-intel_package() {
	short_desc+=" - Intel CPU/GPU microcode"
	nostrip=yes
	pkg_install() {
		vmove usr/lib/firmware/i915
		vmove usr/share/licenses/linux-firmware/LICENSE.i915
	}
}

linux-firmware-nvidia_package() {
	short_desc+=" NVIDIA GPU microcode"
	nostrip=yes
	pkg_install() {
		vmove usr/lib/firmware/nvidia
		vmove usr/share/licenses/linux-firmware/LICENCE.nvidia*
	}
}

linux-firmware-network_package() {
	short_desc+=" - network"
	depends="linux-firmware-broadcom>=${version}_${revision}"
	case "$XBPS_TARGET_MACHINE" in
		armv7*|aarch64*)
			depends+=" linux-firmware-qualcomm>=${version}_${revision}"
			;;
	esac
	nostrip=yes
	pkg_install() {
		vmove usr/lib/firmware/3com
		vmove usr/lib/firmware/RTL8192E
		vmove "usr/lib/firmware/rt*"
		vmove "usr/lib/firmware/ath*"
		vmove "usr/lib/firmware/ar*"
		vmove "usr/lib/firmware/bnx2*"
		vmove "usr/lib/firmware/cxgb*"
		vmove "usr/lib/firmware/htc*"
		vmove "usr/lib/firmware/iwl*"
		vmove "usr/lib/firmware/intel*"
		vmove usr/lib/firmware/kaweth
		vmove usr/lib/firmware/libertas
		vmove usr/lib/firmware/mrvl
		vmove "usr/lib/firmware/mt*.bin"
		vmove usr/lib/firmware/ueagle-atm
		vmove usr/lib/firmware/ti-connectivity
		vmove usr/lib/firmware/dpaa2
		vmove usr/lib/firmware/qca
	}
}

linux-firmware-qualcomm_package() {
	short_desc+=" - Qualcomm SoC blobs"
	nostrip=yes
	pkg_install() {
		vmove usr/lib/firmware/qcom
	}
}
