%{!?python3_sitelib: %global python3_sitelib %(python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")}

%global _udevrulesdir /lib/udev/rules.d

Summary:	The Linux Infrared Remote Control package.
Summary(ja):	赤外線リモートコントロールパッケージ
Name:		lirc
Version:	0.9.4a
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
Source4:	99-remote-control-lirc.rules

Patch1:		0001-Changing-effective-user-default.patch

# Vine patch

BuildRequires:	perl
BuildRequires:	libusb1-devel, python-devel
BuildRequires:	automake libtool
BuildRequires:	alsa-lib-devel
BuildRequires:  libXt-devel
BuildRequires:  libxslt
BuildRequires:  python3
## 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	devel
Summary:	Development files for LIRC
Summary(ja):	LIRCを用いた開発用のファイル
Group:		Development/Libraries
Requires:	lirc = %{version}-%{release}

%description    devel
LIRC is a package that allows you to decode and send infra-red and
other signals of many (but not all) commonly used remote controls.
Included applications include daemons which decode the received
signals as well as user space applications which allow controlling a
computer with a remote control.  This package includes files for
developing applications that use LIRC.


%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

%patch1 -p1
sed -i -e 's|/usr/local/etc/|/etc/|' contrib/irman2lirc


%build
autoreconf -if
%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
#%{__install} -m 644 -D %{SOURCE2} $RPM_BUILD_ROOT/etc/logrotate.d/lircd
%{__install} -Dpm 644 %{SOURCE3} $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/lirc

cd $RPM_BUILD_ROOT%{_datadir}/lirc/contrib
chmod 755 irman2lirc
cd $OLDPWD
rm $RPM_BUILD_ROOT%{_libdir}/*.la
rm $RPM_BUILD_ROOT%{_libdir}/lirc/plugins/*.la

install -pm 755 contrib/irman2lirc $RPM_BUILD_ROOT%{_bindir}
install -Dpm 644 contrib/60-lirc.rules \
    $RPM_BUILD_ROOT%{_udevrulesdir}/60-lirc.rules
install -Dpm 644 %{SOURCE4} \
    $RPM_BUILD_ROOT%{_udevrulesdir}/99-remote-control-lirc.rules
cp -a %{SOURCE1} README.fedora


## 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 \
	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


%pre
getent group lirc >/dev/null || groupadd -r lirc
getent passwd lirc >/dev/null || \
    useradd -r -g lirc -d /var/log/lirc -s /sbin/nologin \
        -c "LIRC daemon user, runs lircd." lirc
usermod -a -G dialout lirc &> /dev/null || :
usermod -a -G lock lirc &> /dev/null || :
usermod -a -G input lirc &> /dev/null || :
exit 0

%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)
%license COPYING
%doc ANNOUNCE AUTHORS ChangeLog NEWS README TODO
%doc __docs/*
%{_initdir}/lirc
#/etc/logrotate.d/lircd
%dir %{_sysconfdir}/lirc
%dir %{_sysconfdir}/lirc/lircd.conf.d
%ghost %config(noreplace) %{_sysconfdir}/lirc/*.conf
%ghost %config(noreplace) %{_sysconfdir}/lirc/irexec.lircrc
%ghost %config(noreplace) %{_sysconfdir}/lirc/lircd.conf.d/*
%config(noreplace) %{_sysconfdir}/sysconfig/lirc
%{_bindir}/*
%{_sbindir}/*
%{_libdir}/*.so.*
%{_libdir}/lirc
%{_datadir}/lirc/
%{_docdir}/lirc
%{_mandir}/man?/*
%{_localstatedir}/lib/lirc
%{_udevrulesdir}/*
%{python3_sitelib}/lirc

%files devel
%{_includedir}/lirc/
%{_includedir}/*.h
%{_libdir}/*.so
%{_libdir}/pkgconfig/*.pc

%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
* Sat Jul 16 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.9.4-1
- updated to 0.9.4.
- dropped Patch0.
- added a subpackage: lirc-devel.

* 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

