Summary:	The Linux Infrared Remote Control package.
Summary(ja):	赤外線リモートコントロールパッケージ
Name:		lirc
Version:	0.9.0
Release:	1%{?_dist_release}
License:	GPL
Group:		System Environment/Daemons
URL:		http://www.lirc.org/
Source0:	http://prdownloads.sourceforge.net/lirc/%{name}-%{version}.tar.bz2
Source1:	lirc.init
Source2:	lircd.logrotate
Source3:	lirc.sysconfig
Patch0:		lirc-use-new-instead-of-conf-as-filename-suffix.patch

# Vine patch

BuildRequires:	perl
BuildRequires:	libusb-devel, python-devel
BuildRequires:	automake libtool
BuildRequires:	alsa-lib-devel
BuildRequires:  libXt-devel
## Currently not supportd (yet) for Vine Linux
#BuildRequires:	libftdi-devel, libirman-devel
Requires(post): /sbin/chkconfig
Requires(post): /sbin/ldconfig
Requires(preun): /sbin/chkconfig
Requires(postun): /sbin/ldconfig

BuildRoot:	%{_tmppath}/%{name}-%{version}-root

Vendor: Project Vine
Distribution: Vine Linux
Packager:	owa, kazutaka

%description
LIRC stands for 'Linux Infra-red Remote Control'.

This package provides the daemons and some utilities to support
infra-red remote controls under Linux. 

%description -l ja
LIRC は 'Linux Infra-red Remote Control' の略です。

このパッケージには Linux で赤外線リモコンをサポートする為に
必要なデーモンといくつかのユーティリティが含まれています。

%package -n dkms-%{name}
Summary:	Kernel modules for LIRC
Group:		System Environment/Kernel
Requires(post):	dkms
Requires(preun):dkms

%description -n	dkms-%{name}
This package provides the kernel modules for LIRC.

Install this package if the LIRC driver you are using requires
them and your kernel doesn't include them.

Note that lirc_gpio and lirc_parallel are in packages of their own.

%description -n	dkms-%{name} -l ja
このパッケージには LIRC 用のカーネルモジュールが含まれています。

もしあなたが使っている赤外線リモコン用のドライバがカーネルに
含まれていない場合は、このパッケージをインストールしてください。

注記: lirc_gpio と lirc_parallel は別のパッケージになっています。

## This package up (uni processor) kernel, but only smp kernel is supplied officially.
## So we don't create this sub package.
#%package -n dkms-%{name}-parallel
#Summary:	Parallel port module for LIRC
#Group:		System/Kernel and hardware
#Requires:	dkms-%{name} = %version
#Requires(post):	dkms
#Requires(preun):dkms
#
#%description -n dkms-%{name}-parallel
#This package provides the parallel port module for LIRC.
#
#This module requires a non-SMP kernel.
#
#%description -n dkms-%{name}-parallel -l ja
#このパッケージにはパラレルポート接続の LIRC 用のカーネル
#モジュールが含まれています。
#
#このモジュールは SMP カーネルでは使用できません。

## Required header files (bttv.h ...) are not included in kernel-devel.
## So we can't build this package (now?).
#%package -n dkms-%{name}-gpio
#Summary:	GPIO module for LIRC
#Group:		System/Kernel and hardware
#Requires:	dkms-%{name} = %version
#Requires(post):	dkms
#Requires(preun):dkms
#
#%description -n	dkms-%{name}-gpio
#This package provides the GPIO module for LIRC.
#
#%description -n	dkms-%{name}-gpio -l ja
#このパッケージには GPIO 接続の LIRC 用のカーネルモジュールが
#含まれています。


%prep
%setup -q
%patch0 -p1 -b .suffix

%{__chmod} 644 contrib/*
%{__chmod} +x contrib/hal
%{__sed} -i -e 's|/usr/local/etc/|/etc/|' contrib/irman2lirc
%{__sed} -i -e 's/\r//' remotes/hercules/lircd.conf.smarttv_stereo \
                remotes/adstech/lircd.conf.usbx-707
%{__sed} -i -e 's|/sbin/init.d/lircd|%{_initdir}/lirc|' contrib/lircs
for f in remotes/chronos/lircd.conf.chronos \
         remotes/creative/lircd.conf.livedrive \
         remotes/atiusb/lircd.conf.atiusb \
         NEWS ChangeLog AUTHORS contrib/lircrc ; do
    iconv -f iso-8859-1 -t utf-8 $f > $f.utf8 ; mv $f.utf8 $f
done

# use /dev/lirc0 by default instead of /dev/lirc
%{__sed} -i -e 's|#define DEV_LIRC	"lirc"|#define DEV_LIRC	"lirc0"|' config.h.in

# use fixed instead of Courier w/xmode2, should be more prevalent on linux boxen
%{__sed} -i -e 's|char.*font1_name.*Courier.*$|char		font1_name[]="-misc-fixed-*-r-*-*-12-*-*-*-*-*-iso8859-1";|g' tools/xmode2.c

# lib64 rpath
%{__sed} -i -e 's|"/lib /usr/lib |"/%{_lib} %{_libdir} |' configure 

# *cough* I wish there was a good way to disable portaudio/svgalib...
%{__sed} -i -e 's/portaudio.h/PORTAUDIO_DISABLED/g' configure*
%{__sed} -i -e 's/vga.h/SVGALIB_DISABLED/g' configure*

# avoid autofoo re-run
touch -r aclocal.m4 configure.ac 

# Do this after, as we're touching the remote definitions earlier
# Don't create a backup, or the original definitions will get installed

%build
%configure \
         --disable-static \
         --disable-manage-devices \
         --enable-sandboxed \
         --with-x \
         --with-transmitter \
	--with-driver=userspace \
	--with-kerneldir=$(pwd)

%{__make}


%install
%{__rm} -rf $RPM_BUILD_ROOT __docs
%{__make} install DESTDIR=$RPM_BUILD_ROOT

%{__install} -Dpm 755 %{SOURCE1} $RPM_BUILD_ROOT%{_initdir}/lirc
%{__perl} -pi -e \
  's|/etc/|%{_sysconfdir}/|g ;
   s|/var/|%{_localstatedir}/|g ;
   s|/usr/sbin/|%{_sbindir}/|g' \
  $RPM_BUILD_ROOT%{_initdir}/lirc
#%{__install} -m 644 -D %{SOURCE2} $RPM_BUILD_ROOT/etc/logrotate.d/lircd
%{__install} -Dpm 644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/lirc

%{__install} -Dpm 644 doc/lirc.hwdb $RPM_BUILD_ROOT%{_datadir}/lirc/lirc.hwdb

%{__install} -dm 755 $RPM_BUILD_ROOT%{_sysconfdir}/lirc
touch $RPM_BUILD_ROOT%{_sysconfdir}/lirc/lirc{d,md}.conf

%{__install} -dm 755 $RPM_BUILD_ROOT%{_localstatedir}/run/lirc/
touch $RPM_BUILD_ROOT%{_localstatedir}/run/lirc/lirc{d,m}

# Put remote definitions in place
cp -ar remotes $RPM_BUILD_ROOT%{_datadir}/lirc-remotes

# Remove unpacked file
%{__rm} $RPM_BUILD_ROOT%{_libdir}/liblirc_client.la

# Remove unnecessary documents
%{__mkdir} __docs
%{__cp} -pR doc contrib __docs
pushd __docs
%{__rm} -rf doc/Makefile* doc/.libs doc/man* doc/lirc.hwdb
%{__rm} -rf contrib/irman2lirc contrib/lirc.* contrib/sendxevent.c
popd


## For DKMS sub packagtes
#
#for lircsrcdir in %{name} %{name}-parallel %{name}-gpio; do
for lircsrcdir in %{name}; do

install -d -m755 $RPM_BUILD_ROOT/usr/src/$lircsrcdir-%{version}-%{release}
cp -a Makefile Makefile.in Makefile.am acinclude.m4 \
	configure.ac config.status config.h \
	$RPM_BUILD_ROOT/usr/src/$lircsrcdir-%{version}-%{release}

# Makefiles call there to unnecessarily regenerate files
echo '#!/bin/true' > $RPM_BUILD_ROOT/usr/src/$lircsrcdir-%{version}-%{release}/configure
chmod +x $RPM_BUILD_ROOT/usr/src/$lircsrcdir-%{version}-%{release}/configure

done

cp -a drivers $RPM_BUILD_ROOT/usr/src/%{name}-%{version}-%{release}

#for drivername in parallel gpio; do
#install -d -m755 $RPM_BUILD_ROOT/usr/src/%{name}-$drivername-%{version}-%{release}/drivers
#mv $RPM_BUILD_ROOT/usr/src/%{name}-%{version}-%{release}/drivers/lirc_$drivername \
#	$RPM_BUILD_ROOT/usr/src/%{name}-$drivername-%{version}-%{release}/drivers/
#cp -a drivers/*.h drivers/Makefile* drivers/lirc_dev \
#	$RPM_BUILD_ROOT/usr/src/%{name}-$drivername-%{version}-%{release}/drivers/
#
#done

# get modulelist
pushd drivers
drivers=$(echo lirc_* | sed "s/lirc_parallel //" | sed "s/lirc_gpio //")
popd

# Anssi 2009-03 empty directory
drivers="${drivers/lirc_cmdir /}"

cat > $RPM_BUILD_ROOT/usr/src/%{name}-%{version}-%{release}/dkms.conf <<EOF
PACKAGE_NAME="%{name}"
PACKAGE_VERSION="%{version}-%{release}"
MAKE[0]="droot=\\\$(pwd); for driver in $drivers; do cd \\\$droot/drivers/\\\$driver; make \
	KERNEL_LOCATION=\$kernel_source_dir AUTOMAKE=true AUTOCONF=true ACLOCAL=true; done"
CLEAN="droot=\\\$(pwd); for driver in $drivers; do cd \\\$droot/drivers/\\\$driver; make \
	clean AUTOMAKE=true AUTOCONF=true ACLOCAL=true; done"
AUTOINSTALL=yes
EOF

i=0
for module in $drivers; do
	cat >> $RPM_BUILD_ROOT/usr/src/%{name}-%{version}-%{release}/dkms.conf <<-EOF
	BUILT_MODULE_NAME[$i]="$module"
	BUILT_MODULE_LOCATION[$i]="drivers/$module"
	DEST_MODULE_LOCATION[$i]="/kernel/drivers/input/misc"
	EOF
	i=$((i+1))
done

#for drivername in parallel gpio; do
#cat > %{buildroot}/usr/src/%{name}-$drivername-%{version}-%{release}/dkms.conf <<EOF
#PACKAGE_NAME="%{name}-$drivername"
#PACKAGE_VERSION="%{version}-%{release}"
#MAKE[0]="cd drivers/lirc_$drivername; make \
#	KERNEL_LOCATION=\$kernel_source_dir AUTOMAKE=true AUTOCONF=true ACLOCAL=true"
#CLEAN="cd drivers/lirc_$drivername; make \
#	clean AUTOMAKE=true AUTOCONF=true ACLOCAL=true"
#AUTOINSTALL=yes
#BUILT_MODULE_NAME[0]="lirc_$drivername"
#BUILT_MODULE_LOCATION[0]="drivers/lirc_$drivername"
#DEST_MODULE_LOCATION[0]="/kernel/drivers/input/misc"
#EOF
#
#done


%post
/sbin/chkconfig --add lirc
# If we're upgrading, move config files into their new location, if need be
if [ $1 -ge 2 ] ; then
  if [ -e %{_sysconfdir}/lircd.conf -a ! -e %{_sysconfdir}/lirc/lircd.conf ]; then
    mv %{_sysconfdir}/lircd.conf %{_sysconfdir}/lirc/lircd.conf
  fi
  if [ -e %{_sysconfdir}/lircmd.conf -a ! -e %{_sysconfdir}/lirc/lircmd.conf ]; then
    mv %{_sysconfdir}/lircmd.conf %{_sysconfdir}/lirc/lircmd.conf
  fi
fi
/sbin/ldconfig

%preun
if [ $1 -eq 0 ] ; then
  /sbin/service lirc stop || :
  /sbin/chkconfig --del lirc || :
fi
/sbin/ldconfig

%postun
if [ "$1" -ge "1" ]; then
  /sbin/service lirc condrestart || :
fi

%post -n dkms-%{name}
dkms add     -m %{name} -v %{version}-%{release} --rpm_safe_upgrade &&
dkms build   -m %{name} -v %{version}-%{release} --rpm_safe_upgrade &&
dkms install -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --force || :

%preun -n dkms-%{name}
dkms remove  -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --all || :

#%post -n dkms-%{name}-parallel
#dkms add     -m %{name}-parallel -v %{version}-%{release} --rpm_safe_upgrade &&
#dkms build   -m %{name}-parallel -v %{version}-%{release} --rpm_safe_upgrade &&
#dkms install -m %{name}-parallel -v %{version}-%{release} --rpm_safe_upgrade --force || :
#
#%preun -n dkms-%{name}-parallel
#dkms remove  -m %{name}-parallel -v %{version}-%{release} --rpm_safe_upgrade --all || :

#%post -n dkms-%{name}-gpio
#dkms add     -m %{name}-gpio -v %{version}-%{release} --rpm_safe_upgrade &&
#dkms build   -m %{name}-gpio -v %{version}-%{release} --rpm_safe_upgrade &&
#dkms install -m %{name}-gpio -v %{version}-%{release} --rpm_safe_upgrade --force || :
#
#%preun -n dkms-%{name}-gpio
#dkms remove  -m %{name}-gpio -v %{version}-%{release} --rpm_safe_upgrade --all || :


%clean
%{__rm} -rf $RPM_BUILD_ROOT


%files
%defattr(-, root, root)
%doc ANNOUNCE AUTHORS ChangeLog COPYING NEWS README TODO
%doc __docs/*
%{_initdir}/lirc
#/etc/logrotate.d/lircd
%ghost %config(noreplace) %{_sysconfdir}/lirc/lirc*d.conf
%config(noreplace) %{_sysconfdir}/sysconfig/lirc
%{_bindir}/*
%{_sbindir}/*
%{_includedir}/lirc
%{_libdir}/liblirc_*
%{_datadir}/lirc/
%{_datadir}/lirc-remotes/
%{_mandir}/man?/*
%ghost %{_localstatedir}/run/lirc/lirc*

%files -n dkms-%{name}
%defattr(-,root,root)
/usr/src/%{name}-%{version}-%{release}

#%files -n dkms-%{name}-parallel
#%defattr(-,root,root)
#/usr/src/%{name}-parallel-%{version}-%{release}

#%files -n dkms-%{name}-gpio
#%defattr(-,root,root)
#/usr/src/%{name}-gpio-%{version}-%{release}


%changelog
* Fri Dec 27 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.9.0-1
- update to 0.9.0
- remove Patch1 (lirc-0.8.6-standardized-remote-keycodes.patch)
- remove Patch2 (lirc-0.8.4-make-remote-names-all-unique.patch)
- remove Patch100 (lirc-0.8.7-mceusb-GV-MC7_RCKIT.patch)

* Sun Oct 17 2010 Kazutaka HARADA <kazutaka@vinelinux.org> 0.8.7-1
- new upstream release
- update Patch1, 2 and 100
- drop Patch3 (already merged by upstream)

* Fri Feb 05 2010 Shu KONNO <owa@bg.wakwak.com> 0.8.6-3
- rebuilt with python-2.6.4-3

* Wed Dec 23 2009 Kazutaka HARADA <kazutaka@vinelinux.org> 0.8.6-2
- add Patch3 to fix compilation error against kernel-2.6.32

* Sat Nov 14 2009 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.8.6-1
- new upstream release
- drop obsolete patches
- add new patches and configuration files from fedora package
- rewrite spec
- add dkms-lirc sub packages refer to mandriva package
  (but we don't build lirc-paralle and lirc-gpio sub packages)

* Sat Aug 09 2008 Shu KONNO <owa@bg.wakwak.com> 0.6.5-1vl5
- added lirc-0.6.5-config.patch for x86_64
- applied new versioning policy
- spec in utf-8

* Mon Feb 16 2004 Daisuke SUZUKI <daisuke@linux.or.jp> 0.6.5-0vl1
- initial build for Vine Linux

