# $Id: PKGBUILD 233080 2015-03-08 11:34:44Z tpowa $
# Maintainer: Thomas Bächler <thomas@archlinux.org>

pkgname=intel-ucode
pkgver=20150121
pkgrel=1
pkgdesc="Microcode update files for Intel CPUs"
arch=('any')
install=$pkgname.install
url="http://downloadcenter.intel.com/SearchResult.aspx?lang=eng&keyword=%22microcode%22"
replaces=('microcode_ctl')
license=('custom')
# Some random "download id" that intel has in their downloadcenter
_dlid=24661
source=(http://downloadmirror.intel.com/${_dlid}/eng/microcode-${pkgver}.tgz
        LICENSE
        intel-microcode2ucode.c)
sha256sums=('23353b93bb421971496cea5e9f9d390ce0ed22580a8cc45ae7b3b322dcd8f6b3'
            '6983e83ec10c6467fb9101ea496e0443f0574c805907155118e2c9f0bbea97b6'
            '03a13a966316a4d3d9c7e1b46007fd4b80911aea5ddd957ddf33ce660efe03de')
build() {
  cd "$srcdir"
  gcc -Wall ${CFLAGS} -o intel-microcode2ucode intel-microcode2ucode.c
  ./intel-microcode2ucode ./microcode.dat
}

package() {
  cd "$srcdir"

  install -d -m755 "${pkgdir}"/boot

  mkdir -p kernel/x86/microcode
  mv microcode.bin kernel/x86/microcode/GenuineIntel.bin
  echo kernel/x86/microcode/GenuineIntel.bin | bsdcpio -o -H newc -R 0:0 > "${pkgdir}"/boot/intel-ucode.img
  
  install -D -m644 LICENSE "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
