%define name scim-bridge
%define version 0.4.16
%define release 8%{?_dist_release}

# build qt3 immodule ("--without qt3" to disable qt3)
%bcond_without qt3
# ugly hack for Qt3 version auto-detection -- inagaki
%define _qt3_notfound %(eval "rpm -q qt-devel > /dev/null"; echo $?)
%if %{_qt3_notfound}
%define _qt3_version 3.3.8
%else
%define _qt3_version %(rpm -q --queryformat "%%{version}" qt-devel)
%endif
%define _qt3_prefix  %{_libdir}/qt-%{_qt3_version}
%define _qt3_plugindir %{_qt3_prefix}/plugins

# build qt4 immodule ("--without qt4" to disable qt4)
%bcond_without qt4
# ugly hack for Qt4 version auto-detection -- inagaki
%define _qt4_notfound %(eval "pkg-config --exists Qt"; echo $?)
%if %{_qt4_notfound}
%define _qt4_version 4.6.1
%define _qt4_prefix  %{_libdir}/qt-%{_qt4_version}
%define _qt4_plugindir %{_qt4_prefix}/plugins
%else
%define _qt4_version %(pkg-config --modversion --silence-errors Qt)
%define _qt4_prefix %(pkg-config --variable prefix --silence-errors Qt)
%define _qt4_plugindir %(pkg-config --variable plugindir --silence-errors Qt)
%endif

Summary: yet another IM client of SCIM
Summary(ja): もう一つ別の SCIM IM クライアント
Name: %{name}
Version: %{version}
Release: %{release}
Source0: http://1jaist.dl.sourceforge.net/sourceforge/scim/%{name}-%{version}.tar.gz

# Patch from Fedora 10
Patch0: scim-bridge-0.4.15-fix-gdm.patch
Patch1: scim-bridge-0.4.15-bz461373.patch

# Patch from Mandriva 2009
Patch2: bug-351920-should-return-retval.patch
Patch3:	scim-bridge-0.4.15.2-linkage.patch

# Patch from Fedora development
Patch4: scim-bridge-0.4.15-EOF.patch

Patch5: scim-bridge-0.4.15-hotkey-help.patch

URL: http://www.scim-im.org/projects/scim_bridge
License: GPL/LGPL
Group: System Environment/Libraries
BuildRoot: %{_tmppath}/%{name}-%{version}-root
Prefix: %{_prefix}
Requires: scim >= 1.4
BuildRequires: scim-devel >= 1.4
BuildRequires: pkgconfig >= 0.9.0
BuildRequires: gtk2-devel >= 2.14.0

%description
Scim-bridge is yet another IM client of SCIM.
The im-module of scim-bridge communicates with scim via socket.

%description -l ja
scim-bridge は、もう一つ別の SCIM IM クライアントです。
scim-bridge の im-module はソケット経由で SCIM と通信します。

%package gtk
Summary:        SCIM Bridge GTK IM Module
Summary(ja):    SCIM Bridge GTK IM モジュール
Group:          System Environment/Libraries
Requires:       %{name} = %{version}-%{release}
Requires:       gtk2 >= 2.14.0
Requires(post): gtk2 >= 2.14.0
Requires(postun): gtk2 >= 2.14.0
Obsoletes:      %{name} <= 0.1.7

%description gtk
This package provides the SCIM Bridge GTK IM module.

%description -l ja gtk
このパッケージには SCIM Bridge の GTK IM モジュールが含まれています。

%if !%{without qt3}
%package qt
Summary:        SCIM Bridge Qt IM Module
Summary(ja):    SCIM Bridge Qt IM モジュール
Group:          System Environment/Libraries
Requires:       %{name} = %{version}-%{release}
Requires:       qt = %{_qt3_version}
BuildRequires:  qt-devel 

%description qt
This package provides the SCIM Bridge Qt IM module.

%description -l ja qt
このパッケージには SCIM Bridge の Qt IM モジュールが含まれています。
%endif

%if !%{without qt4}
%package qt4
Summary:        SCIM Bridge Qt4 IM Module
Summary(ja):    SCIM Bridge Qt4 IM モジュール
Group:          System Environment/Libraries
Requires:       %{name} = %{version}-%{release}
Requires:       qt4 = %{_qt4_version}
BuildRequires:  qt4-devel

%description qt4
This package provides the SCIM Bridge Qt4 IM module.

%description -l ja qt4
このパッケージには SCIM Bridge の Qt4 IM モジュールが含まれています。
%endif

%prep
%setup -q
%patch0 -p1 -b .0-fix-gdm
%patch1 -p1
%patch2 -p1
%patch3
%patch4 -p1
%patch5 -p1

%build
%if !%{without qt3}
export QT3_PREFIX=%{_qt3_prefix}
%endif
%if !%{without qt4}
export QT4_PREFIX=%{_qt4_prefix}
%endif

%configure \
%if %{without qt3}
        --disable-qt3-immodule \
%else
        --enable-qt3-immodule \
%endif
%if %{without qt4}
        --disable-qt4-immodule \
%else
        --enable-qt4-immodule \
%endif
        --enable-gtk2-immodule

%__make

%install
%__rm -rf %{buildroot}
#%%makeinstall moduledir=%{buildroot}%{_libdir}/gtk-2.0/immodules
%__make DESTDIR=%{buildroot} install

# remove unneeded files
%__rm -f %{buildroot}%{_libdir}/gtk-2.0/immodules/*.{a,la}
%__rm -f %{buildroot}%{_qt3_plugindir}/inputmethods/*.{a,la}
%__rm -f %{buildroot}%{_qt4_plugindir}/inputmethods/*.{a,la}

%clean
%__rm -rf %{buildroot}

%post gtk
%{_bindir}/gtk-query-immodules-2.0 > %{_sysconfdir}/gtk-2.0/%{_arch}/gtk.immodules

%postun gtk
%{_bindir}/gtk-query-immodules-2.0 > %{_sysconfdir}/gtk-2.0/%{_arch}/gtk.immodules

%files
%defattr(-,root,root)
%doc AUTHORS COPYING ChangeLog NEWS README doc/LICENSE*
%{_bindir}/scim-bridge

%files gtk
%defattr(-,root,root)
%{_libdir}/gtk-2.0/immodules/im-scim-bridge.so

%if !%{without qt3}
%files qt
%defattr(-,root,root)
%{_qt3_plugindir}/inputmethods/*.so
%endif

%if !%{without qt4}
%files qt4
%defattr(-,root,root)
%{_qt4_plugindir}/inputmethods/*.so
%endif

%changelog
* Sun Jan 31 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-8
- updated Qt version detection macros to build properly

* Fri Jan 22 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-7
- rebuilt with qt4-4.6.1

* Sun Nov 22 2009 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-6
- rebuilt with qt4-4.5.3

* Tue Oct 13 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> 0.4.16-5
- cleaned up spec
- renumbered patch
- added Patch5 from Fedora

* Wed Sep 02 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4.16-4
- rebuild with qt4-4.5.2

* Mon Apr 27 2009 Shu KONNO <owa@bg.wakwak.com> 0.4.16-3
- dropt qt3rel/qt4rel part of Requires in subpackages qt, qt4

* Sun Apr 26 2009 Shu KONNO <owa@bg.wakwak.com> 0.4.16-2
- rebuild with qt-3.3.8-3vl5, because scim-bridge-qt requires "Rq: qt = %{qt3ver}-%{qt3rel}"

* Sun Apr 19 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> 0.4.16-1
- new upstream release
- dropt Pacth3,4,5 (these patches are merged)

* Fri Apr 17 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> 0.4.15.2-2
- spec in UTF-8
- fixed description in scim-bridge-qt4
- added patch6,7 (import Fedora, Mandriva patches)

* Mon Feb 2 2009 Toshiharu Kudoh <toshi.kd2@gmail.com> 0.4.15.2-1
- new upstream release
- added patch0,1,2,3,4,5 (import Fedora, Mandriva, scim-devel patches)

* Wed Oct 08 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4.15-4
- rebuild with qt4-4.4.2

* Fri Oct 03 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4.15-3
- add qt4 immodule
  - build gtk,qt3,qt4 immodule by default

* Sat Sep 27 2008 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4.15-2
- rebuild with gtk+-2.14

* Sat Apr 05 2008 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.4.15-1
- new upstream release
- apply new versioning policy

* Fri Jan 18 2008 IWAI, Masaharu <iwai@alib.jp> 0.4.14-0vl2
- drop unnecessary BuildRequires for qt3-immodule package
- fix typo: 0.4.14-0vl1 changelog <BTS:VineLinux:#592>

* Wed Jan  9 2008 IWAI, Masaharu <iwai@alib.jp> 0.4.14-0vl1
- new upstream release
- drop unnecessary Qt fix patch ( Patch0 ): upstream merged
- update BuildRequires
  - drop doxygen
  - add XOrg-gl-devel for building qt3-immodule
  - move libmng-devel for building qt3-immodule

* Tue Oct 09 2007 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.4.13-0vl2
- rebuild for Vine Linux 4.2.

* Tue Oct 09 2007 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.4.13-0vl3
- add patch0 to fix symbol lookup error with qt3.

* Wed Sep 26 2007 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.4.13-0vl0
- rebuild for Vine Linux 4.2.

* Sat Sep 15 2007 Kazutaka HARADA <kazutaka@dc4.so-net.ne.jp> 0.4.13-0vl1
- new upstrm release
- detect qt version at build time.
- add --disable-qt4-immodule configure option.
- add BuildRequires libmng-devel.

* Thu May 10 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4.12-0vl2
- rebuild with libstdc++34

* Thu May 03 2007 Daisuke SUZUKI <daisuke@linux.or.jp> 0.4.12-0vl1
- new upstream release

* Tue Dec 19 2006 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> 0.4.8-0vl2
- change License to GPL/LGPL
- add doc/LICENSE.* as documents

* Mon Dec 18 2006 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> 0.4.8-0vl1
- new upstream release
- add BuildRequires: doxygen, qt-devel
- add new sub-packages:
  - gtk: GTK IM module (obsoletes: %%{name} <= 0.1.7)
  - qt:  Qt IM module

* Wed May 10 2006 IWAI, Masaharu <iwai@alib.jp> 0.1.7-0vl1
- new upstream release
- add documents
- running gtk-query-immodules-2.0 in post and postun scripts
- add PreReq: gtk2 > 2.2

* Fri Apr 21 2006 IWAI, Masaharu <iwai@alib.jp> 0.1.6-0vl1
- new upstream release

* Thu Apr  6 2006 IWAI, Masaharu <iwai@alib.jp> 0.1.4-0vl1
- initial release

