%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
%{!?python_sitearch: %define python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib(1)")}
%define mod_path scim-@PACKAGE_VERSION_MAJOR@.@PACKAGE_VERSION_MINOR@
Name:       scim-python
Version:    @PACKAGE_VERSION@
Release:    1%{?dist}
Summary:    Python wrapper for Smart Common Input Method platform

License:    LGPLv2+
Group:      System Environment/Libraries
URL:        http://code.google.com/p/scim-python/
Source0:    http://scim-python.googlecode.com/files/%{name}-%{version}.tar.gz
Source1:    http://scim-python.googlecode.com/files/pinyin-database-0.1.10.5.tar.bz2
Source2:    http://scim-python.googlecode.com/files/xingma-zhengma-0.1.10.tar.bz2
Source3:    http://scim-python.googlecode.com/files/xingma-wubi86-0.1.10.tar.bz2
Source4:    http://scim-python.googlecode.com/files/xingma-erbi-qingsong-0.1.10.tar.bz2
Source5:    http://scim-python.googlecode.com/files/xingma-cangjie5-0.1.10.tar.bz2

BuildRoot:  %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires:  scim-devel, gettext-devel, libtool, python-devel, pygtk2-devel, perl(XML::Parser)
Requires:   scim, pygtk2

%description
Python wrapper for Smart Common Input Method platform.

%package english
Summary:    Python english IM engine 
Group:      System Environment/Libraries
BuildRequires:  python-enchant
Requires:   %{name} = %{version}-%{release} python-enchant

%description english
This package contains a python english IM engine.

%package pinyin
Summary:    Two python chinese pinyin IM engines 
Group:      System Environment/Libraries
Requires:   %{name} = %{version}-%{release}

%description pinyin
This package contains two python chinese pinyin IM engines.


%package chinese
Summary:    Python chinese IM engines 
Group:      System Environment/Libraries
Requires:   %{name} = %{version}-%{release}
Requires:   %{name}-pinyin = %{version}-%{release}
Requires:   %{name}-xingma-cangjie = %{version}-%{release}
Requires:   %{name}-xingma-erbi = %{version}-%{release}
Requires:   %{name}-xingma-wubi = %{version}-%{release}
Requires:   %{name}-xingma-zhengma = %{version}-%{release}

%description chinese
This package contains some python chinese IM engines.

%package xingma
Summary:    Python XingMa IM engine 
Group:      System Environment/Libraries
Requires:   %{name} = %{version}-%{release}

%description xingma
This package contains a python XingMa IM engine.

%package xingma-cangjie
Summary:    CangJie table for Python XingMa IM engine 
Group:      System Environment/Libraries
Requires:   %{name}-xingma = %{version}-%{release}

%description xingma-cangjie
This package contains a CangJie table for python XingMa IM engine.

%package xingma-erbi
Summary:    ErBi table for Python XingMa IM engine 
Group:      System Environment/Libraries
Requires:   %{name}-xingma = %{version}-%{release}

%description xingma-erbi
This package contains an ErBi table for python XingMa IM engine.

%package xingma-wubi
Summary:    WuBi table for Python XingMa IM engine 
Group:      System Environment/Libraries
Requires:   %{name}-xingma = %{version}-%{release}

%description xingma-wubi
This package contains an ZhengMa table for python XingMa IM engine.

%package xingma-zhengma
Summary:    ZhengMa table for Python XingMa IM engine 
Group:      System Environment/Libraries
Requires:   %{name}-xingma = %{version}-%{release}

%description xingma-zhengma
This package contains an ZhengMa table for python XingMa IM engine.

%prep
%setup -q -a2 -a3 -a4 -a5
cp %{SOURCE1} python/engine/PinYin/

%build
%configure --disable-static --enable-english-writer --enable-pinyin
# make -C po update-gmo
make NO_INDEX=true %{?_smp_mflags}
python python/engine/XingMa/XMCreateDB.py -o -s cangjie5.txt.bz2 -p data/pinyin_table.txt
python python/engine/XingMa/XMCreateDB.py -o -s erbi-qs.txt.bz2 -p data/pinyin_table.txt
python python/engine/XingMa/XMCreateDB.py -o -s wubi.txt.bz2 -p data/pinyin_table.txt
python python/engine/XingMa/XMCreateDB.py -o -s zhengma.txt.bz2 -p data/pinyin_table.txt

%install
rm -rf $RPM_BUILD_ROOT
make NO_INDEX=true DESTDIR=${RPM_BUILD_ROOT} install
rm -f $RPM_BUILD_ROOT%{python_sitearch}/%{mod_path}/scim/_scim.la
rm -f $RPM_BUILD_ROOT%{_libdir}/scim-1.0/1.4.0/SetupUI/zhengjuui.la
install -m 644 cangjie5.db $RPM_BUILD_ROOT%{_datadir}/scim-python/engine/XingMa/tables/
install -m 644 cangjie.png $RPM_BUILD_ROOT%{_datadir}/scim/icons/
install -m 644 erbi-qs.db $RPM_BUILD_ROOT%{_datadir}/scim-python/engine/XingMa/tables/
install -m 644 erbi-qs.png $RPM_BUILD_ROOT%{_datadir}/scim/icons/
install -m 644 wubi.db $RPM_BUILD_ROOT%{_datadir}/scim-python/engine/XingMa/tables/
install -m 644 wubi.png $RPM_BUILD_ROOT%{_datadir}/scim/icons/
install -m 644 zhengma.db $RPM_BUILD_ROOT%{_datadir}/scim-python/engine/XingMa/tables/
install -m 644 zhengma.png $RPM_BUILD_ROOT%{_datadir}/scim/icons/

%find_lang %{name}


%clean
rm -rf $RPM_BUILD_ROOT

%post pinyin
cd /usr/share/scim-python/engine/PinYin
echo "Creating INDEX."
python -c "import PYSQLiteDB; db = PYSQLiteDB.PYSQLiteDB (); db.create_indexes ();"

%post xingma-cangjie
XMCreateDB -i -n %{_datadir}/scim-python/engine/XingMa/tables/cangjie5.db

%post xingma-erbi
XMCreateDB -i -n %{_datadir}/scim-python/engine/XingMa/tables/erbi-qs.db

%post xingma-wubi
XMCreateDB -i -n %{_datadir}/scim-python/engine/XingMa/tables/wubi.db

%post xingma-zhengma
XMCreateDB -i -n %{_datadir}/scim-python/engine/XingMa/tables/zhengma.db


%files -f %{name}.lang
%defattr(-,root,root,-)
%doc AUTHORS COPYING README TODO
%{python_sitearch}/%{mod_path}/
%{python_sitearch}/scim.pth
%{_libdir}/scim-1.0/1.4.0/IMEngine/python.so
%{_libdir}/scim-1.0/1.4.0/Helper/python.so
%{_libdir}/scim-1.0/1.4.0/SetupUI/python.so
%dir %{_datadir}/scim-python/
%dir %{_datadir}/scim-python/engine
%{_datadir}/scim-python/engine/__init__.*
%dir %{_datadir}/scim-python/setupui
%{_datadir}/scim-python/setupui/__init__.*
%dir %{_datadir}/scim-python/helper
%{_datadir}/scim-python/helper/__init__.*
%{_datadir}/scim/icons/scim-python.png

%files english
%defattr(-,root,root,-)
%{_datadir}/scim-python/engine/EnglishWriter
%{_datadir}/scim-python/setupui/EnglishWriter

%files chinese
%defattr(-,root,root,-)

%files pinyin
%defattr(-,root,root,-)
%{_datadir}/scim-python/data/pinyin_table.txt
%{_datadir}/scim-python/engine/PinYin
%{_datadir}/scim-python/helper/PinYinSetup
%{_datadir}/scim-python/helper/ZhengJuSetup

%files xingma
%defattr(-,root,root,-)
%{_bindir}/XMCreateDB
%{_datadir}/scim-python/engine/XingMa/*.py
%{_datadir}/scim-python/engine/XingMa/*.pyc
%{_datadir}/scim-python/engine/XingMa/*.pyo
%{_datadir}/scim-python/engine/XingMa/tables/.keep
%{_datadir}/scim/icons/py-mode.png
%{_datadir}/scim/icons/xm-mode.png

%files xingma-cangjie
%defattr(-,root,root,-)
%{_datadir}/scim-python/engine/XingMa/tables/cangjie5.db
%{_datadir}/scim/icons/cangjie.png

%files xingma-erbi
%defattr(-,root,root,-)
%{_datadir}/scim-python/engine/XingMa/tables/erbi-qs.db
%{_datadir}/scim/icons/erbi-qs.png

%files xingma-wubi
%defattr(-,root,root,-)
%{_datadir}/scim-python/engine/XingMa/tables/wubi.db
%{_datadir}/scim/icons/wubi.png

%files xingma-zhengma
%defattr(-,root,root,-)
%{_datadir}/scim-python/engine/XingMa/tables/zhengma.db
%{_datadir}/scim/icons/zhengma.png


%changelog
* Wed Sep 26 2007 Huang Peng <shawn.p.huang@gmail.com> - 0.1.3-1
- Update to 0.1.3.

* Wed Sep 26 2007 Huang Peng <shawn.p.huang@gmail.com> - 0.1.2-3
- Fix build warning.
- Fix rpmlint checking warning.
- Fix build failed in x86_64 platform.

* Wed Sep 26 2007 Huang Peng <shawn.p.huang@gmail.com> - 0.1.2-2
- Change files: add %%dir %%{_datadir}/scim-python
- Fix build failed in x86_64 platform.

* Wed Sep 26 2007 Huang Peng <shawn.p.huang@gmail.com> - 0.1.2-1
- Update to 0.1.2

* Mon Sep 24 2007 Huang Peng <shawn.p.huang@gmail.com> - 0.0.2-1
- Update to 0.0.2

* Mon Sep 17 2007 Huang Peng <shawn.p.huang@gmail.com> - 0.0.1-1
- Init version
