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

%define Wnn8Exists() %([ -f /usr/lib/wnn8/ja_JP/wnnenvrc ] && echo 1 || echo 0)

Name:          wnn7egg
Version:       1.02
Release:       7%{?_dist_release}
License:       GPL
Source0:       http://www.omronsoft.co.jp/SP/unix/wnn7s/support/modules/wnn7-elisp-el-%{version}-1.tgz
Source1:       %{name}-install.sh
Source2:       %{name}-remove.sh
Source3:       %{name}-init.el
Source4:       vine-default-%{name}.el

## Required files from Wnn8 for Linux/BSD FAQ
## http://www.omronsoft.co.jp/SP/pcunix/wnn8/faq/03clients.html
Source10: eggrc-wnn7_for-wnn8

## from http://www.jpl.org/ftp/pub/misc/emcws-22.1-20071010.gz
Source11: busyu.el

## 母音過不足補正機能は余計なお世話！（腫瘍：しゅよう -> しゅうよう）
Patch10: eggrc-wnn7-boinkabusoku-nil.patch

## for emacs23
## from ftp://ftp.jpl.org/pub/elisp/wnn7-elisp-el-1.02-1.patch.gz
## (http://www.jpl.org/ftp/pub/elisp/wnn7-elisp-el-1.02-1.patch.gz)
Patch100: wnn7-elisp-el-1.02-1.patch.gz
## http://www.m17n.org/mlarchive/mule-ja/200703/msg00018.html
#Patch101: wnn7egg-emacs23.patch

URL:           http://www.omronsoft.co.jp/SP/unix/wnn7s/support/wnn7egg_v102s.html
Group:         Applications/Editors/Emacs
BuildRoot:     %{_tmppath}/%{name}-%{version}-root
Summary:       wnn7egg - Japanese input client of Wnn7 for Emacs
Summary(ja):   wnnななたまご - Wnn7 対応 Emacs 用日本語入力クライアント
BuildArch:     noarch

# %if %Wnn8Exists
# Requires:      wnn8-server
# %else
# Requires:      wnn7-server
# %endif
PreReq:        emacsen
%prereq_ge     emacsen-common
BuildRequires: emacsen-common

%description
EGG for Wnn7, called "wnn-nana-tamago" is Japanese Input Method for Emacsen. 
It is based on Tamago ver.3 (v3.09) and incorporated the communication library 
part of Tamago Ver.4. This only can use with Jserver of Wnn7. 

This package includes eggrc-wnn7 placed on Wnn8 for Linux/BSD FAQ 
  http://www.omronsoft.co.jp/SP/pcunix/wnn8/faq/03clients.html
and busyu.el of emcws-22.1-20071010.gz. 
This eggrc-wnn7 is customized for user's dictionaries of Wnn8, # '
so if you install Wnn8 on your system, this package sets up for Wnn8. 
This busyu.el requires to search BUSYU. 
Also this package changes to (wnn7-set-boin-kabusoku nil) for eggrc-wnn7. 
Further, you do NOT need the path of wnn7egg for your .emacs.el. 


%description -l ja
wnn7egg「wnnななたまご」は，「たまご第 3 版」v3.09 をベースに
「たまご第 4 版」の通信，ライブラリ部を組み込んだ，Wnn7 の為の
専用クライアントです．

このパッケージには，Wnn8 for Linux/BSD FAQ 
  http://www.omronsoft.co.jp/SP/pcunix/wnn8/faq/03clients.html
に置いてある eggrc-wnn7 と 
emcws-22.1-20071010.gz から busyu.el を同封しております． 
eggrc-wnn7 は，辞書を Wnn8 用に修正されており，
もし Wnn8 がインストールされていると，Wnn8 向けに設定がされます．
busyu.el がないと，部首検索などができません．
また，母音過不足補正機能を有効にしない変更を施しています．
なお，.emacs.el に wnn7egg のパスを通す設定などは一切不要です．


%prep
%setup -q -n wnn7/elisp/emacs20

%{__cp} -af %{SOURCE3} .
%{__cp} -af %{SOURCE4} .
%{__cp} -af %{SOURCE10} .
%{__cp} -af %{SOURCE11} .
%{__cp} -af ../README .

%patch10 -p0
pushd ../../..
%patch100 -p0 -b .emacs23-0
#% patch101 -p0 -b .emacs23-1
popd

%build


%install

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

mkdir -p ${RPM_BUILD_ROOT}%{_datadir}/emacs/site-lisp/%{name}
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}%{_infodir}


#
# install el files
#

%{__cp} eggrc-wnn7* ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{name}/
%{__cp} *.el README ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{name}/
%{__cp} -r its-v309 ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{name}/
%{__install} -m 644 %{name}-init.el \
    ${RPM_BUILD_ROOT}/%{_datadir}/emacs/site-lisp/%{name}/

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

%_installemacsenscript %{name} %{SOURCE1}

%_removeemacsenscript  %{name} %{SOURCE2}


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


%post
#
# bytecompile and install
#

if [ "$1" = 2 ] ; then

%_emacsenPackageRemove %{name}

fi

%_addemacsenlist %{name}

%_emacsenPackageInstall %{name}

%preun

if [ "$1" = 0 ]; then

%_emacsenPackageRemove %{name}

%_removeemacsenlist %{name}

fi


%files
%defattr(-,root,root)
%{_datadir}/emacs/site-lisp/%{name}/
%{_libdir}/emacsen-common/packages/install/%{name}
%{_libdir}/emacsen-common/packages/remove/%{name}


%changelog
* Wed May 06 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-7
- updated wnn7egg-install.sh
  - *-init.el: changed from hard copy to symbolic link 
    on /etc/emacs-XX.YY/site-start.d
- fixed wnn7egg-remove.sh
  - removed variable PIXMAPDIR

* Thu Apr 23 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-6
- added vine-default-wnn7egg.el
- updated wnn7egg-init.el

* Tue Feb 24 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-5
- dropped ExclusiveArch

* Sun Feb 22 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-4
- added ExclusiveArch: %%{ix86} x86_64
- re-applied wnn7-elisp-el-1.02-1.patch.gz: corrected in %%prep

* Sat Feb 07 2009 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-3
- applied wnn7-elisp-el-1.02-1.patch.gz

* Sun Sep 7 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-2
- spec in utf-8

* Sat Mar 22 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vl5
- used %{?_dist_release}

* Sat Mar 15 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vl2
 - delete %%if %%Wnn8Exists Requires: wnn8-server %%else Requires: wnn7-server %%endif

* Sat Mar 15 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vl1.1
- delete Vendor: none, Distribution: none 
 * Sat Mar 15 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vl1
 - initial build for VineSeed

* Sun Mar 9 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vlmp4
- define Wnn8Exists
- Setup Wnn8 for wnn7egg-install.sh

* Tue Feb 5 2008 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vlmp3
- rebuild for VineSeed

* Sun Oct 28 2007 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vlmp2
- add eggrc-wnn7-boinkabusoku-nil.patch (wnn7-set-boin-kabusoku nil); default: t

* Mon Oct 15 2007 Munehiro Yamamoto <munepi@cg8.so-net.ne.jp> 1.02-1vlmp1
- initial release for Vine Linux 4.1
