SUMMARY="Intel WiFi firmware modules"
DESCRIPTION="Intel WiFi devices require firmware to operate. This package \
contains those necessary firmware files, corresponding to the WiFi drivers \
contained within the base system."
HOMEPAGE="https://www.intel.com/content/www/us/en/support/articles/000005511/wireless.html"
COPYRIGHT="2006-2019 Intel Corporation"
LICENSE="Intel WiFi Firmware"
REVISION="1"
srcGitRev="50b5a6cc0ad284c55ad95d0b8a2b3190d045b7a3"
SOURCE_URI="https://github.com/freebsd/freebsd-src/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="3081411b6786d960263502bf7af2100153e7bf73787b12ce14a1a8930fd7eb65"
SOURCE_DIR="freebsd-src-$srcGitRev/sys/contrib/dev/"

ARCHITECTURES="any"
DISABLE_SOURCE_PACKAGE="yes"

PROVIDES="
	intel_wifi_firmwares = $portVersion
	"

BUILD_REQUIRES="
	cmd:uudecode
	"

BUILD()
{
	rm -rf install-firmware
	mkdir -p install-firmware

	process_firmware()
	{
		freebsd_driver=$1
		haiku_driver=$2
		cd $freebsd_driver
		mkdir ../install-firmware/$haiku_driver
		for f in *.uu; do
			uudecode -o ../install-firmware/$haiku_driver/$(echo $f | cut -d'.' -f-1).ucode $f
		done
		cp LICENSE ../install-firmware/$haiku_driver
		cd ..
	}

	process_firmware wpi iprowifi3945
	process_firmware iwn iprowifi4965
	process_firmware iwm idualwifi7260

	# remap one firmware
	cd install-firmware/iprowifi4965/
	mv iwnwifi-2030-18.ucode iwlwifi-2030-18.ucode
	cd ../..

	# delete unneeded older firmwares
	cd install-firmware/idualwifi7260/
	rm iwm-8000C-17.ucode iwm-8000C-16.ucode
	rm iwm-7265D-17.ucode
	rm iwm-7265-16.ucode
	rm iwm-7260-16.ucode iwm-3160-16.ucode
	cd ../..
}

INSTALL()
{
	mkdir -p $dataDir/firmware/
	cp -r install-firmware/. $dataDir/firmware/
}
