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

%define origver 5.0.7.1
%define origname tamago-tsunagi

%define rel 1

Summary: EGG Input Method Architecture for Emacsen

Name: %{origname}
Version: %{origver}
Release: %{rel}%{?_dist_release}

Source0: %{name}-%{version}.tar.gz
Source1: %{origname}-install.sh
Source2: %{origname}-remove.sh

Source10: vine-default-%{origname}.el
Source11: %{origname}-init.el

Patch30: tamago-4.0.6-egg-helper-path.patch

License: GPLv2+
Group: Applications/Editors/Emacs
BuildRoot: %{_tmppath}/%{name}-%{version}-root

Requires: emacsen
Requires: emacsen-common
BuildRequires: apel
%prereq_ge apel

Vendor: Project Vine
Distribution: Vine Linux
Packager: iwaim

%description
EGG Emacs24 Input Method Architecture.

%description -l ja
GNU Emacs 24 以降に対応した多言語入力環境を提供します。

%prep
%setup -n %{origname}-%{origver}
%patch30 -p1

%build
%configure

gcc %{optflags} -o helper/egg-helper helper/egg-helper.c

%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

#
# install setting files
#

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

#
# install el files
# 

cp -r eggrc *.el egg its* Makefile \
	$RPM_BUILD_ROOT/usr/share/emacs/site-lisp/%{origname}/

#
# install egg-helper
#
install -d $RPM_BUILD_ROOT%{_libexecdir}
install -m 755 helper/egg-helper $RPM_BUILD_ROOT%{_libexecdir}


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

%_installemacsenscript %{origname} %{SOURCE1} 

%_removeemacsenscript  %{origname} %{SOURCE2}


#
# install info file
# 

mkdir -p ${RPM_BUILD_ROOT}/usr/info


%post 
#
# bytecompile and install 
#

if [ "$1" = 2 ]; then

%_emacsenPackageRemove %{origname}

fi

%_addemacsenlist %{origname}

%_emacsenPackageInstall %{origname}


%preun

if [ "$1" = 0 ]; then

%_emacsenPackageRemove %{origname}

%_removeemacsenlist %{origname}

fi



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


%files
%defattr(-,root,root)
%doc AUTHORS COPYING ChangeLog* NEWS PROBLEMS TODO README.ja.UTF-8.txt doc
%{_datadir}/emacs/site-lisp/%{origname}/
%{emacsen_pkgdir}/install/%{origname}
%{emacsen_pkgdir}/remove/%{origname}
%{_libexecdir}/egg-helper
 

%changelog
* Tue Apr 28 2015 IWAI, Masaharu <iwaim.sub@gmail.com> 5.0.7.1-1
- initial release
