# $Id: PKGBUILD 14978 2008-10-11 21:04:37Z tpowa $
# Maintainer: Paul Mattal <paul@archlinux.org>

pkgname=lirc
pkgver=0.8.5CVS
pkgrel=17
_kernver=2.6.28-LinHES
pkgdesc="Linux Infrared Remote Control kernel modules for stock arch kernel"
arch=(i686 x86_64)
url="http://www.lirc.org/"
license=('GPL')
depends=('lirc-utils=0.8.5CVS' 'kernel26>=2.6.27' 'kernel26<2.6.29' 'iguanaIR')
makedepends=('python')
replaces=('lirc+pctv')
options=('!makeflags')
install=$pkgname.install
source=(http://www.blushingpenguin.com/mark/lmilk/lirc-0.8.5-CVS-pvr150.tar.bz2 \
	kernel-2.6.26.patch
	kernel-2.6.27.patch
	lirc_atiusb.patch
	http://superb-east.dl.sourceforge.net/sourceforge/mod-mce/lirc_mod_mce-0.1.5.tar.bz2
	lirc_mod_mce.patch
	hw_commandir.c
	hw_commandir.h
	dvicoIR.rules
        lirc.fdi)

build() {
	# configure
	cd $startdir/src/lirc-0.8.5-CVS-pvr150 || return 1
	cp $startdir/src/hw_commandir.* $startdir/src/lirc-0.8.5-CVS-pvr150/daemons
#	patch -Np1 -i ../kernel-2.6.26.patch || return 1
#	patch -Np1 -i ../kernel-2.6.27.patch || return 1
	patch -Np1 -i ../lirc_atiusb.patch || return 1

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

	# disable parallel and bt829
        # because of incompatibility with smp systems
        sed -i -e "s:lirc_parallel::" -e "s:lirc_bt829::" \
		Makefile drivers/Makefile drivers/*/Makefile tools/Makefile \
                || return 1
	# disable lirc_gpio due to brokeness of kernel 2.6.23
	sed -i -e "s:lirc_gpio::" \
		Makefile drivers/Makefile drivers/*/Makefile tools/Makefile \
                || return 1

	# build
	cd drivers || return 1
	make || return 1
	make DESTDIR=$startdir/pkg install || return 1

	# set the kernel we've built for inside the install script
	sed -i -e "s/KERNEL_VERSION=.*/KERNEL_VERSION=${_kernver}/g" \
		$startdir/lirc.install || return 1
	cd $startdir/src/lirc_mod_mce
	cp ../lirc-0.8.5-CVS-pvr150/drivers/lirc_dev/lirc_dev.h .
	patch -p1 < ../lirc_mod_mce.patch
	make KDIR=/usr/src/linux-2.6.28-LinHES/
	cp lirc_mod_mce.ko $startdir/pkg/lib/modules/2.6.28-LinHES/kernel/drivers/misc/
	mv $startdir/pkg/lib/modules/2.6.28-LinHES/kernel/drivers/misc/lirc_mceusb2.ko $startdir/pkg/lib/modules/2.6.28-LinHES/kernel/drivers/misc/lirc_mceusb2.ko.not
	#remove old commandir
	rm $startdir/pkg/lib/modules/$_kernver/kernel/drivers/misc/lirc_cmdir.ko
	rm $startdir/pkg/lib/modules/$_kernver/kernel/drivers/misc/commandir.ko

	# Add a udev rule for the DVICO remote so that if there is more than 
	# one hiddev device, the system cant get confused.
	install -D -m644 $srcdir/dvicoIR.rules $pkgdir/etc/udev/rules.d/dvicoIR.rules

	# Add the fdi file to prevent the Dvico dual 4 remotes from screwing up keyboard interaction.
	install -D -m644 $srcdir/lirc.fdi $pkgdir/usr/share/hal/fdi/preprobe/20thirdparty/lirc.fdi
}
md5sums=('b96dae91b566143b3af433fa2714ec9a'
         '1753acd774f50b638e6173d364de53fd'
         '6f151eb4e81fc7776a06c9063e6ad9a5'
         '7eccd7826ab99e5cf1b9154171c8b927'
         '21ce358809105f005e888e3b138c59e6'
         'b5d52566a9dae8d76e24e8753f33abef'
         'f059f4030afc682c9539a03bf837c1cf'
         '4e698654cc44fc6c4163814acda5a7ee'
         '9a3a6dc03647ee6674a166dfb884ddd6'
         '203d9cd014c4276be4c84cecd103919d')