#Packager: George Vlahavas <vlahavas~at~gmail~dot~com>

pkgname=sof-firmware
pkgver=2025.12
pkgrel=2gv
arch=x86_64
source=("https://github.com/thesofproject/sof-bin/releases/download/v${pkgver}/sof-bin-${pkgver}.tar.gz")
docs=("readme*" "notice*" "licence*")
url=https://thesofproject.github.io/

doinst() {
	# This is a hack so we can get behind upgrading symlinks to directories
	# weirdness with spkg.
	if [ -L lib/firmware/intel/sof ]; then
		SYMLINK_POINT=$( readlink lib/firmware/intel/sof )
		rm -f lib/firmware/intel/sof
		mv lib/firmware/intel/${SYMLINK_POINT} lib/firmware/intel/sof
	fi
	if [ -L lib/firmware/intel/sof-tplg ]; then
		SYMLINK_POINT=$( readlink lib/firmware/intel/sof-tplg )
		rm -f lib/firmware/intel/sof-tplg
		mv lib/firmware/intel/${SYMLINK_POINT} lib/firmware/intel/sof-tplg
	fi
}

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"sof-firmware (Open source audio DSP firmware)"
"Sound Open Firmware is an open source audio DSP firmware and SDK that"
"provides audio firmware infrastructure and development tools for"
"developers who are interested in audio or signal processing on modern"
"DSPs."
)


build() {
	# This installs the firmware along with the tools. However, the tools are
	# built for a newer GLIBC than we have in Salix 15.0. We'll have those in
	# a separate sof package.
	cd $startdir/src/sof-bin-$pkgver
	export DESTDIR=$startdir/pkg
	export FW_DEST=$DESTDIR/lib/firmware/intel
	export TOOLS_DEST=$DESTDIR/usr/bin
	mkdir -p $FW_DEST
	mkdir -p $TOOLS_DEST
	./install.sh

	# SST topology files (not SOF related, but it's a Intel hw support
	# and this package seems a good place to distribute them
	# - Quote Fedora (via Slackware)
	alsatplg -c /usr/share/alsa/topology/hda-dsp/skl_hda_dsp_generic-tplg.conf \
	  -o $startdir/pkg/lib/firmware/skl_hda_dsp_generic-tplg.bin
	
	# remove the prebuilt binaries
	rm -rf $startdir/pkg/usr/bin

	# fix ownerships
	chown -R root:root $startdir/pkg
} 
