# $Id$
# Maintainer: BlackIkeEagle <ike DOT devolder AT gmail DOT com>
# Contributor: Philippe Cherel <philippe.cherel@mayenne.org>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - Exynos and RPi support

pkgname=libcec
pkgver=2.1.4
pkgrel=1.1
pkgdesc="Pulse-Eight's libcec for the Pulse-Eight USB-CEC adapter"
arch=('i686' 'x86_64')
url="http://libcec.pulse-eight.com/"
license=('GPL')
depends=('udev' 'lockdev')
source=("$pkgname-$pkgver.tar.gz::https://github.com/Pulse-Eight/$pkgname/archive/$pkgname-$pkgver.tar.gz"
        'exynos.patch'
        'fix-bool_t.patch')
sha256sums=('79bef5232a5c9ab987ca3a2d4bfcaeb80480fd26f502dc1a996fe845d90fe147'
            'ae746a22142aec24b4a5cfffa3d42c97a9be5d8a22f7215bf217934b9d1ce9d1'
            'ab695a6638d3a4009c4f7f76e2b84b98a7f03c0332f5e1038e53ae804ea12821')

if [[ $CARCH = 'armv6h' ]]; then
  depends+=('raspberrypi-firmware')
  replaces=('libcec-rpi')
  provides=('libcec-rpi')
fi

prepare() {
  cd "$pkgname-$pkgname-$pkgver"

  patch -Np1 -i ../exynos.patch
  patch -Np1 -i ../fix-bool_t.patch
}

build() {
  cd "$pkgname-$pkgname-$pkgver"
  autoreconf -vif

  if [[ $CARCH == 'armv7h' ]]; then
    CONFIG='--enable-exynos'
  elif [[ $CARCH == 'armv6h' ]]; then
    CONFIG='--enable-rpi --with-rpi-include-path=/opt/vc/include --with-rpi-lib-path=/opt/vc/lib'
    unset LDFLAGS
  fi

  ./configure --prefix=/usr $CONFIG
  make
}

package() {
  cd "$pkgname-$pkgname-$pkgver"
  make DESTDIR="$pkgdir" install
}