%define prereq_ge()     %(LC_ALL="C" rpm -q --queryformat 'Requires(post):%%{NAME} >= %%{VERSION}' %1 | grep -v "is not")
%define emacsen_pkgdir /usr/lib/emacsen-common/packages

Summary:      colorize emacsens' window
Name:         color-mate
Version:      10.6.4
Release:      1%{?_dist_release}
Group:        Applications/Editors/Emacs
License:      distributable
Url:          http://www.netlab.is.tsukuba.ac.jp/~yokota/izumi/color_mate/
Source0:      color-mate-%{version}.tar.gz
Source1:      cm_select.sh
Source2:      emacs-color.sh
Patch0:       color-mate-fontset.patch
Patch1:       color-mate-10.6.3-color-mate-fontset-emacs.patch
Patch2:	      color-mate-10.6.3-color-mate-fontset-xemacs.patch
Patch3:       color-mate-face-nound.patch
Patch4:       color-mate-SunnyDay-LCD.patch
Patch5:       color-mate-10.6.3-tail.patch

Source10:     color-mate-install.sh
Source11:     color-mate-remove.sh

BuildArch:    noarch
Buildroot:    %{_tmppath}/%{name}-%{version}-root

Requires:       emacsen
BuildRequires:  emacsen-common
%prereq_ge    emacsen-common
Requires(post): make
Obsoletes:    color-mate-emacs, color-mate-xemacs

Vendor:       Project Vine
Distribution: Vine Linux

%description
Color-Mate is a colorize tool for emacs/xemacs.

%description -l ja
Color-Mate とは、 emacs/xemacs のカラー表示機能を使ってＸウィンドウ版
emacs/xemacs 画面を見やすくするものです。


%prep
%setup -q
%patch0 -p0
%patch1 -p1
%patch2 -p1 
%patch3 -p0
%patch4 -p1
%patch5 -p1

%build

#just adding annoying file to the rpm filelist
./configure

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

mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/color-mate
#mkdir -p ${RPM_BUILD_ROOT}/%{_libdir}/emacsen-common/packages/install
#mkdir -p ${RPM_BUILD_ROOT}/%{_libdir}/emacsen-common/packages/remove
mkdir -p ${RPM_BUILD_ROOT}/%{emacsen_pkgdir}/install
mkdir -p ${RPM_BUILD_ROOT}/%{emacsen_pkgdir}/remove

# install el files
cp -ar Makefile* configure* *.el *.pl install-sh* kanakan-cursor contrib theme/\
	${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/color-mate

# install contrib
mkdir -p ${RPM_BUILD_ROOT}%{_bindir}
install -m 755 %{SOURCE1} ${RPM_BUILD_ROOT}%{_bindir}/cm_select
install -m 755 %{SOURCE2} ${RPM_BUILD_ROOT}%{_bindir}/emacs-color
# pushd ${RPM_BUILD_ROOT}%{_bindir}/
# ln -s emacs-color xemacs-color
# popd

# prepare docs
mv contrib/README README.cm_select

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

%_installemacsenscript color-mate %{SOURCE10}

%_removeemacsenscript  color-mate %{SOURCE11}


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


%post

## bytecompile el and install elc

if [ "$1" = 2 ] ; then

%_emacsenPackageRemove color-mate

fi

%_addemacsenlist color-mate

%_emacsenPackageInstall color-mate


%preun

if [ "$1" = 0 ] ; then

%_emacsenPackageRemove color-mate

%_removeemacsenlist color-mate

fi


%files
%defattr(-,root,root)
%doc Q_and_A.color-mate QuickStart.color-mate README.color-mate*
%doc Customize* ChangeLog Dot*
%doc kanakan-cursor/org-doc/* kanakan-cursor/README* contrib/
%{_bindir}/cm_select
%{_bindir}/emacs-color
#%{_bindir}/xemacs-color
%{_datadir}/emacs/site-lisp/color-mate/
#/usr/lib/emacsen-common/packages/*/*
%{emacsen_pkgdir}/*/*


%changelog
* Fri Apr 20 2012 Munehiro Yamamoto <munepi@vinelinux.org> 10.6.4-1
- new upstream release
- dropped supporting xemacs 

* Sun Sep 21 2008 Shu KONNO <owa@bg.wakwak.com> 10.6.3-1vl5
- applied new versioning policy, spec in utf-8
- added macro %%emacsen_pkgdir

* Mon Sep 11 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 10.6.3-0vl3
- changed Group to Appliations/Editors/Emacs <BTS:VineLinux:163>

* Sun Aug 13 2006 IWAI, Masaharu <iwai@alib.jp> 10.6.3-0vl2
- update color-mate-install.sh for Emacs 22
- using Licenes tag
- add tail option patch ( Patch5 )

* Wed Apr  9 2003 IWAI Masaharu <iwai@alib.jp> 10.6.3-0vl1
- version up to 10.6.3
- update color-mate-fontset-emacs.patch (Patch1)
- update color-mate-fontset-xemacs.patch (Patch2)

* Fri Mar 29 2002 Jun Nishii <jun@vinelinux.org> 10.1.1-0vl8
- fix color-mate-{install,remove}.sh

* Fri Mar 29 2002 Jun Nishii <jun@vinelinux.org> 10.1.1-0vl7
- install missing .X files
- use symlink for color-xemacs
- update cm_select

* Sun Dec 16 2001 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 10.1.1-0vl6
- install script (SOURCE10) modified a little

* Sun Dec 16 2001 MATSUBAYASHI Kohji <shaolin@vinelinux.org> 10.1.1-0vl5
- emacsen-common aware

* Sun Dec 03 2000 Lisa Sagami <czs14350@mb.infoweb.ne.jp>
- 10.1.1-0vl4
- fixed description
- added BuildRequires and %%{emacs} / %%{xemacs} for each package to be
  built on anti-BuildRequired host (both set to be 1 by default). 
- cp -a for egg-cursor.el to work around with emacs's murmur :-)

* Wed Oct 11 2000 Jun Nishii <jun@vinelinux.org>
- 10.1.1-0vl3
- with egg-cursor

* Wed Sep 20 2000 Jun Nishii <jun@vinelinux.org>
- 10.1.1-0vl2
- modify emacs-color 

* Fri Sep 15 2000 Jun Nishii <jun@vinelinux.org>
- 9.1.1-0vl1
- enable to set default fontset in .emacs
- obsletes SunnyDay-LCD 12
- added cm_select in bins 
- added emacs-color, xemacs-color

* Mon Sep 11 2000 T.R. Kobayashi <tkoba@ike-dyn.ritsumei.ac.jp>
- 10.0.1-8
- added SunnyDay-LCD 12 dots fontset theme 

* Fri Feb 11 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 10.0.1-7
- added %defattr(-,root,root) 
- added %clean section

* Wed Jan 26 2000 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rhythmaning.org>
- 10.0.1-6
- fixed SunnyDay-LCD.el for "wrong type argument" problem

* Fri Dec  3 1999 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rins.st.ryukoku.ac.jp>
- 10.0.1-5
- %files xemacs section modified for correct load-path
  to /usr/lib/xemacs/site-packages/lisp/color-mate

* Wed Dec  1 1999 MATSUBAYASHI 'Shaolin' Kohji <shaolin@rins.st.ryukoku.ac.jp>
- change Group to Applications/Editors/EmacsLisp

* Wed Nov 17 1999 Jun NISHII <jun@vinelinux.org>
- build for Vine-2.0 
