# Maintainer: stratum nine <strata@dropswitch.net>
#
# Please do not consider this a replacement for flashrom.
# This is Google's version. There are differences.
#

buildarch=4

pkgname=flashrom-google
pkgrel=1
pkgver=20140226
pkgdesc="Chromium's fork of flashrom needed for SAMSUNG ARM Chromebook"
arch=('armv7h')
url="http://git.chromium.org/gitweb/?p=chromiumos/third_party/flashrom.git"
license=('GPL2')
depends=('libusb-compat' 'libftdi' 'pciutils')
makedepends=('git' 'libusb-compat' 'libftdi' 'pciutils')
source=('stubbery.patch')
md5sums=('a24b8cb6d4a678ba25ffa3cb270c46c8')

_gitroot='http://git.chromium.org/chromiumos/third_party/flashrom.git'
_gitname='flashrom-google'
_githead='release-R26-3701.B'

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [[ -d "$_gitname" ]]; then
    cd "$_gitname" && git pull origin
    msg "The local files are updated."
  else
    git clone "$_gitroot" "$_gitname"
    cd "$_gitname"
    git checkout "$_githead"
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting build..."

  rm -rf "$srcdir/$_gitname-build"
  git clone "$srcdir/$_gitname" "$srcdir/$_gitname-build"
  cd "$srcdir/$_gitname-build"

  #
  # Some dirty hacks were needed to get this to build outside of
  # chromium + build on ARM.
  #
  patch -Np1 -i "${srcdir}/stubbery.patch"

  CONFIG_SATAMV=no CONFIG_LINUX_I2C=no CONFIG_LINUX_SPI=yes WARNERROR=no \
    make
}

package() {
  cd "$srcdir/$_gitname-build"
  mkdir -p "${pkgdir}/usr/bin"
  cp flashrom "${pkgdir}/usr/bin/flashrom.google"
}

# vim:set ts=2 sw=2 et: