# $Id: PKGBUILD 127217 2011-06-11 09:10:14Z ibiru $
# Maintainer: Paul Mattal <paul@archlinux.org>

pkgbase=lirc
pkgname=('lirc' 'lirc-utils')
pkgver=0.9.0
pkgrel=8
#epoch=1
_kernver=2.6.39-LinHES
arch=('i686' 'x86_64')
url="http://www.lirc.org/"
license=('GPL')
makedepends=('help2man' 'kernel26-headers>=2.6.39' 'kernel26-headers<2.6.40' 'alsa-lib' 'libx11' 'libftdi' 'libirman' 'python')
options=('!makeflags' '!strip')
source=(http://prdownloads.sourceforge.net/${pkgbase}/${pkgbase}-${pkgver}.tar.bz2
        lirc_wpc8769l.patch
        lircd-handle-large-config.patch
        lirc_atiusb-kfifo.patch
        kernel-2.6.39.patch
	lircd lircmd lirc.lr lircd.conf irexec.conf irexecd
        lirc_imon.conf)

build() {
  cd "${srcdir}/lirc-${pkgver}"
  patch -Np1 -i "${srcdir}/lirc_wpc8769l.patch"
  patch -Np1 -i "${srcdir}/lircd-handle-large-config.patch"
  patch -Np1 -i "${srcdir}/lirc_atiusb-kfifo.patch"
  patch -Np1 -i "${srcdir}/kernel-2.6.39.patch"

  sed -i '/AC_PATH_XTRA/d' configure.ac
  sed -e 's/@X_CFLAGS@//g' \
      -e 's/@X_LIBS@//g' \
      -e 's/@X_PRE_LIBS@//g' \
      -e 's/@X_EXTRA_LIBS@//g' -i Makefile.am tools/Makefile.am
  libtoolize
  autoreconf

  PYTHON=python2 ./configure --enable-sandboxed --prefix=/usr \
      --with-driver=all --with-kerneldir=/usr/src/linux-${_kernver}/ \
      --with-moduledir=/lib/modules/${_kernver}/kernel/drivers/misc \
      --with-transmitter

  # Remove drivers already in kernel
  sed -e "s:lirc_dev::" -e "s:lirc_bt829::" -e "s:lirc_igorplugusb::" \
      -e "s:lirc_imon::" -e "s:lirc_parallel::" -e "s:lirc_sasem::" \
      -e "s:lirc_serial::" -e "s:lirc_sir::" -e "s:lirc_ttusbir::" \
      -i Makefile drivers/Makefile drivers/*/Makefile tools/Makefile 
  make
}

package_lirc() {
  pkgdesc="Linux Infrared Remote Control kernel modules for stock arch kernel"
  depends=('lirc-utils' 'kernel26>=2.6.39' 'kernel26<2.6.40')
  replaces=('lirc+pctv')
  install=lirc.install

  cd "${srcdir}/lirc-${pkgver}/drivers"
  make DESTDIR="${pkgdir}" install

  # set the kernel we've built for inside the install script
  sed -i -e "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_kernver}/g" "${startdir}/lirc.install"
  # gzip -9 modules
  find "${pkgdir}" -name '*.ko' -exec gzip -9 {} \;
}

package_lirc-utils() {
  pkgdesc="Linux Infrared Remote Control utils"
  depends=('alsa-lib' 'libx11' 'libftdi' 'libirman')
  optdepends=('python2: pronto2lirc utility')
  options=('strip' '!libtool')
  backup=('etc/conf.d/lircd.conf' 'etc/conf.d/irexec.conf')

  cd "${srcdir}/lirc-${pkgver}"
  make DESTDIR="${pkgdir}" install
  install -d "${pkgdir}/usr/share/lirc" "${pkgdir}/etc/rc.d"
  cp "${srcdir}"/{lircd,lircmd,irexecd} "${pkgdir}/etc/rc.d"
  cp -rp remotes "${pkgdir}/usr/share/lirc"
  chmod -R go-w "${pkgdir}/usr/share/lirc/"

  # install the logrotate config
  install -Dm644 "${srcdir}/lirc.lr" "${pkgdir}/etc/logrotate.d/lirc"
    
  # install conf.d file
  install -Dm644 "${srcdir}/lircd.conf" "${pkgdir}/etc/conf.d/lircd.conf"

  # install conf.d file
  install -Dm644 "${srcdir}/irexec.conf" "${pkgdir}/etc/conf.d/irexec.conf"

  install -d "${pkgdir}/etc/lirc"
  
  # install IMON VFD module options
  install -Dm644 ${srcdir}/lirc_imon.conf ${pkgdir}/etc/modprobe.d/lirc_imon.conf

  # remove built modules
  rm -r "${pkgdir}/lib/"
}
md5sums=('b232aef26f23fe33ea8305d276637086'
         '1cce37e18e3f6f46044abab29016d18f'
         'b70cc9640505205446ec47b7d4779f38'
         '1f8b104a2365d9f93404b143f499059b'
         '087a7d102e1c96bf1179f38db2b0b237'
         '8d0e238dc0eda95e340fe570605da492'
         '85f7fdac55e5256967241864049bf5e9'
         '33905430f163432d70e66e593dc4ca5a'
         '5b1f8c9cd788a39a6283f93302ce5c6e'
         'f0c0ac930326168035f0c8e24357ae55'
         '69d099e6deedfa3c1ee2b6e82d9b8bfb'
         '56f1d74bd20edd96c8e2f2687b124341')