# Maintainer: David P. <megver83@parabola.nu>
# Contributor: André Silva <emulatorman@hyperbola.info>
# Contributor: Márcio Silva <coadde@hyperbola.info>
# Contributor: Luke Shumaker <lukeshu@sbcglobal.net>

pkgname=linux-libre-firmware
pkgver=1.2.1
pkgrel=2
epoch=1
pkgdesc='Firmware files for Linux-libre'
arch=('any')
url='https://jxself.org/firmware'
license=('GPL3' 'GPL2')
makedepends=('cmake' 'arm-linux-gnueabi-gcc' 'sh-elf-gcc' 'sh-elf-newlib' 'xtensa-elf-gcc')
provides=('linux-firmware')
conflicts=('linux-firmware'
           'linux-firmware-git'
           'kernel26-firmware'
           'ar9170-fw'
           'iwlwifi-1000-ucode'
           'iwlwifi-3945-ucode'
           'iwlwifi-4965-ucode'
           'iwlwifi-5000-ucode'
           'iwlwifi-5150-ucode'
           'iwlwifi-6000-ucode'
           'rt2870usb-fw'
           'rt2x00-rt61-fw'
           'rt2x00-rt71w-fw'
           'amd-ucode'
           'openfwwf'
           'ath9k-htc-firmware')
replaces=(${conflicts[@]})
options=(!buildflags)
source=("$url/$pkgname-$pkgver.tar.lz"{,.asc} 'remove-external-toolchains.patch' 'install-ath9k_htc-on-prefix-ath9k_htc-too.patch')
sha512sums=('dc4f2e931b4dde217f2e3430e7a0c1a5f42f0844087bf9a771c7e40dbdd8050205d7a80495bd130f87a02a823db7514241d68bfded19548132b3620d4c7e630a'
            'SKIP'
            '474fcfad6c447fded19c8d678b5e29e21d6e1406a3350453e483fd1fe4031c5b3da754fdb94174a538c026ab0b266f7f794f60868c5d6b438aacbdbd214c1046'
            '9aea747fe09593ca407cb638964613720f871cbf2ae480b300e881d3f209692dace6f7c3ee65478a8f3715949bc8b41460dbd25344433df9facdcf318815a177')
validpgpkeys=('F611A908FFA165C699584ED49D0DB31B545A3198') # Jason Self

prepare() {
  cd $srcdir/$pkgname-$pkgver/src

  # do not download toolchains so we can build offline
  patch -p1 -i $srcdir/remove-external-toolchains.patch

  # https://labs.parabola.nu/issues/1445
  patch -p1 -i $srcdir/install-ath9k_htc-on-prefix-ath9k_htc-too.patch
}  

build() {
  cd $srcdir/$pkgname-$pkgver/src
  make
}

package() {
  cd $srcdir/$pkgname-$pkgver/src

  install -dm755 $pkgdir/usr/lib/firmware
  make prefix=$pkgdir/usr/lib/firmware install

  install -Dm644 WHENCE $pkgdir/usr/share/licenses/$pkgname/WHENCE
}