# Maintainer: Spencer Bull <spencerbull2554@gmail.com>
#
# Self-retiring shim: ships Arch's linux-firmware-cirrus 20260910-2 payload to
# the stable channel while stable's pinned Arch snapshot is still on
# linux-firmware 20260810-2 (which lacks the Dell XPS 13 DX13260 / 1028:0e54
# CS35L56 amplifier firmware aliases, leaving that machine's speakers silent).
#
# Nothing is rebuilt. The signed Arch package is verified against the Arch
# packager key and its payload reinstalled as-is, minus the files that Arch
# moved out of linux-firmware-other in 20260910 (the cs42l45 SDCA tree): on
# the stable snapshot those are still owned by linux-firmware-other 20260810-2
# and would conflict, so they are left to that package.
#
# Versioning is deliberate: 20260810-3 orders above the snapshot's 20260810-2
# and BELOW Arch's real 20260910-2, so as soon as the stable snapshot advances
# pacman replaces this shim with the genuine package in the same transaction
# that upgrades linux-firmware-other, and nothing is lost. Delete this recipe
# once stable's snapshot is at linux-firmware >= 20260910.

pkgname=linux-firmware-cirrus
pkgver=20260810
pkgrel=3
_fwver=20260910
_fwrel=2
_basever=20260810
_baserel=2
pkgdesc="Firmware files for Linux - Firmware for Cirrus Logic audio devices (Arch - payload, stable-snapshot shim)"
arch=('any')
url="https://gitlab.com/kernel-firmware/linux-firmware"
license=('LicenseRef-WHENCE' 'LicenseRef-cirrus')
depends=('linux-firmware-whence')
options=('!strip' '!debug')
_cirrus="linux-firmware-cirrus-${_fwver}-${_fwrel}-any.pkg.tar.zst"
_other="linux-firmware-other-${_basever}-${_baserel}-any.pkg.tar.zst"
source=(
  "https://archive.archlinux.org/packages/l/linux-firmware-cirrus/${_cirrus}"
  "https://archive.archlinux.org/packages/l/linux-firmware-cirrus/${_cirrus}.sig"
  "https://archive.archlinux.org/packages/l/linux-firmware-other/${_other}"
  "https://archive.archlinux.org/packages/l/linux-firmware-other/${_other}.sig"
)
noextract=("${_cirrus}" "${_other}")
sha256sums=('70100c551b079bd8abec3d9c96a16defd04766b2a4afc6d7be9128d37e9840f7'
            'SKIP'
            'b0f016ee0d0532b977211b0cbb630bca75184f68a9ace82675eb3cf9acce4f6c'
            'SKIP')
# Jan Alexander Steffens (heftig) <heftig@archlinux.org>, Arch Linux packager
validpgpkeys=('83BC8889351B5DEBBB68416EB8AC08600F108CDF')

package() {
  # Payload only; makepkg regenerates .PKGINFO/.MTREE/.BUILDINFO.
  bsdtar -xf "${srcdir}/${_cirrus}" -C "${pkgdir}" \
    --exclude='.PKGINFO' --exclude='.MTREE' --exclude='.BUILDINFO' \
    --exclude='.INSTALL' --exclude='.CHANGELOG'

  # Drop every file the snapshot's linux-firmware-other still owns.
  local f
  while IFS= read -r f; do
    [[ -e "${pkgdir}/${f}" || -L "${pkgdir}/${f}" ]] && rm -f "${pkgdir}/${f}"
  done < <(bsdtar -tf "${srcdir}/${_other}" | grep -v '^\.' | grep -v '/$')

  # Remove directories emptied by the step above.
  find "${pkgdir}/usr/lib/firmware" -depth -type d -empty -delete
}
