%define _noVersionedDependencies        1
%define prereq_ge()  %(LC_ALL="C" rpm -q --queryformat 'PreReq:%%{NAME} >= %%{VERSION}' %1| grep -v "is not")

%define       origver       8.0.0
%define       origname      riece

Summary:      Riece is emacs based irc client
Summary(ja):  Riece は Emacsen 上で動作する IRC のクライアント
Name:         %{origname}
Version:      %{origver}
Release:      1%{?_dist_release}

Source0:      http://dl.sv.gnu.org/releases/riece/%{name}-%{version}.tar.gz
Source1:      %{name}-install.sh
Source2:      %{name}-remove.sh
Source3:      %{name}-init.el

License:      GPL
Group:        Applications/Editors/Emacs
BuildRoot:    %{_tmppath}/%{name}-%{version}-root
BuildArch:    noarch

Requires(post): emacsen
Requires(post): /sbin/install-info
Requires(preun): emacsen
Requires(preun): /sbin/install-info

%prereq_ge emacsen-common
%prereq_ge flim

%description
Riece is a user interface for IRC (Internet Relay Chat). You should spell it
with the first letter capitalized and pronounce it as /ri:s/.

The features of Riece are as follows:
 * Several IRC servers may be used at the same time.
 * Many features built upon the extension mechanism called add-on.
   Currently 30 such add-ons are available.
 * Installation is easy. Riece doesn't depend on other packages.
 * Setup is easy. Automatically save/restore the configuration.
 * Step-by-step instructions are included.
 * Mostly compliant with the latest IRC client protocol (RFC2812). 

#'

%description -l ja
Riece は IRC (Internet Relay Chat) の世界でチャットを楽しむためのユーザインタ
ーフェースです。Riece は「りーす」と読みます。

Riece の主な特長は以下の通りです。
 * 複数の IRC サーバに同時に接続可能
 * アドオンにより機能の追加や取り外しが容易
 * 他の elisp パッケージに依存しないため、インストールが簡単
 * 設定が簡単で、前回起動時の設定を記録・復元する仕組みを提供
 * 段階的な操作説明書が附属
 * 最新の IRC のクライアントプロトコル (RFC2812) に準拠

%prep
%setup -q


%build
%configure

%install
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}
[ "${RPM_BUILD_ROOT}" != "/" ] && mkdir -p ${RPM_BUILD_ROOT}

mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{origname}
mkdir -p ${RPM_BUILD_ROOT}%{emacsen_pkgdir}/install
mkdir -p ${RPM_BUILD_ROOT}%{emacsen_pkgdir}/remove
mkdir -p ${RPM_BUILD_ROOT}%{_infodir}


#
# install el files
# 

cp -a lisp/* ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{origname}

#
#  build & install info
#

make DESTDIR=${RPM_BUILD_ROOT} install-info


#
# install  script( bytecompile el and install elc , remove )   
#

%_installemacsenscript %{origname} %{SOURCE1} 

%_removeemacsenscript  %{origname} %{SOURCE2}


#
# install info file
# 

mkdir -p ${RPM_BUILD_ROOT}%{_infodir}


#
# install site-start script
# 

install %{SOURCE3} ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{origname}


## remove unpackaged files
%__rm ${RPM_BUILD_ROOT}%{_infodir}/dir


%pre
if (grep -q "Riece: (liece)" /usr/share/info/dir) ; then
  cp /usr/share/info/dir /usr/share/info/dir.rpmsave
  grep -v "Riece: (liece)" /usr/share/info/dir.rpmsave > /usr/share/info/dir
  rm -f /usr/share/info/dir.rpmsave
fi

%post 
#
# bytecompile and install 
#

if [ "$1" = 2 ]; then

%_emacsenPackageRemove %{origname}

fi


%_addemacsenlist %{origname}

%_emacsenPackageInstall %{origname}


/sbin/install-info %{_infodir}/riece-ja.info.gz %{_infodir}/dir \
    --entry="* Riece: (riece-ja).  IRC Client On Emacsen" --section="Emacs" ||:

%preun

if [ "$1" = 0 ]; then

%_emacsenPackageRemove %{origname}

%_removeemacsenlist %{origname}

/sbin/install-info --delete %{_infodir}/riece-ja.info.gz %{_infodir}/dir \
    --entry="* Riece: (riece-ja).  IRC Client On Emacsen" --section="Emacs" ||:

fi


%clean
[ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}


%files
%defattr(-,root,root)
%doc AUTHORS COPYING ChangeLog* INSTALL NEWS* README*

%{_datadir}/emacs/site-lisp/%{origname}
%{emacsen_pkgdir}/install/%{origname}
%{emacsen_pkgdir}/remove/%{origname}
%{_infodir}/%{origname}-*.info*
 

%changelog
* Thu Dec  1 2011 Munehiro Yamamoto <munepi@vinelinux.org> 8.0.0-1
- new upstream release

* Wed Feb 23 2011 Munehiro Yamamoto <munepi@vinelinux.org> 7.0.3-1
- new upstream release
- dropped riece-7.0.0-check-make-local-hook.patch

* Sun Dec 05 2010 Munehiro Yamamoto <munepi@vinelinux.org> 7.0.0-2
- applied riece-7.0.0-check-make-local-hook.patch

* Wed Nov 03 2010 Munehiro Yamamoto <munepi@vinelinux.org> 7.0.0-1
- new upstream release

* Mon Jan 04 2010 Munehiro Yamamoto <munepi@vinelinux.org> 6.1.0-1
- new upstream release

* Wed May 06 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 5.0.0-2
- updated riece-install.sh
  - *-init.el: changed from hard copy to symbolic link 
    on /etc/emacs-XX.YY/site-start.d

* Sat May 02 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 5.0.0-1
- new upstream release

* Tue Oct 14 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 3.1.0-1
- applied new versioning policy
- spec in UTF-8

* Thu Sep 14 2006 Daisuke SUZUKI <daisuke@linux.or.jp> 3.1.0-0vl1
- new upstream release

* Wed Sep 13 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.0-0vl4
- fixed %post script <BTS:VineLinux:177>

* Tue Sep 12 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 2.0.0-0vl3
- changed Group to Appliations/Editors/Emacs <BTS:VineLinux:163>
- s/Copyright/License/

* Sat Sep 10 2005 Daisuke SUZUKI <daisuke@linux.or.jp> 2.0.0-0vl2
- change BuildArch to noarch

* Fri Sep  9 2005 Daisuke SUZUKI <daisuke@linux.or.jp> 2.0.0-0vl1
- initial build

