%define build_compat32 %{?_with_compat32:1}%{!?_with_compat32:0}

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

%define qt3_ver 3.3.8
%define qt4_ver 4.8.6

# build qt3 immodule ("--without qt3" to disable qt3)
%bcond_without qt3
%define _qt3_version 3.3.8
%define _qt3_prefix  %{_libdir}/qt-%{_qt3_version}
%define _qt3_plugindir %{_qt3_prefix}/plugins

# build qt4 immodule ("--without qt4" to disable qt4)
%bcond_without qt4
# Qt4 version auto-detection -- inagaki
%define _qt4_version %(pkg-config --modversion --silence-errors Qt 2>/dev/null || echo %{qt4_ver})
%define _qt4_prefix %(pkg-config --variable prefix --silence-errors Qt 2>/dev/null || echo %{_libdir}/qt4)
%define _qt4_plugindir %(pkg-config --variable plugindir --silence-errors Qt 2>/dev/null || echo %{_qt4_prefix}/plugins)


Summary: yet another IM client of SCIM
Summary(ja): もう一つ別の SCIM IM クライアント
Name: %{name}
Version: %{version}
Release: %{release}

Group: System Environment/Libraries
License: GPL/LGPL
URL: http://www.scim-im.org/projects/scim_bridge

Vendor: Project Vine
Distribution: Vine Linux

Source0: http://jaist.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
Patch6: scim-bridge-0.4.16-fix-gtk-key-snooper.patch
Patch7: scim-bridge-0.4.16-fixes-null-imengine.patch

Patch100: scim-bridge-0.4.16-header.patch

BuildRoot: %{_tmppath}/%{name}-%{version}-root
BuildRequires: scim-devel >= 1.4
BuildRequires: pkgconfig >= 0.9.0
BuildRequires: gtk2-devel >= 2.14.0

Requires: scim >= 1.4

%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 
BuildRequires:  libXmu-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

## to build compat32 for x86_64 architecture support
%package -n compat32-%{name}-gtk
Summary:        SCIM Bridge GTK IM Module
Summary(ja):    SCIM Bridge GTK IM モジュール
Group:          System Environment/Libraries
Requires:       %{name} = %{version}-%{release}
Requires:       compat32-gtk2 >= 2.14.0
Requires(post): gtk2 >= 2.14.0
Requires(postun): gtk2 >= 2.14.0

%description -n compat32-%{name}-gtk
This package provides the SCIM Bridge GTK IM module.

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

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

%description -n compat32-%{name}-qt
This package provides the SCIM Bridge Qt IM module.

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

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

%description -n compat32-%{name}-qt4
This package provides the SCIM Bridge Qt4 IM module.

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


%prep
%setup -q
%patch0 -p1 -b .0-fix-gdm
%patch1 -p1
%patch2 -p1
%patch3
%patch4 -p1
%patch5 -p1
pushd client-gtk
%patch6 -p0
popd
%patch7 -p1

%patch100 -p1

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

%configure --disable-static \
%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 %{?_smp_mflags}

%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

%post -n compat32-%{name}-gtk
%{_bindir}/gtk-query-immodules-2.0-32 > %{_sysconfdir}/gtk-2.0/i386/gtk.immodules

%postun -n compat32-%{name}-gtk
%{_bindir}/gtk-query-immodules-2.0-32 > %{_sysconfdir}/gtk-2.0/i386/gtk.immodules

%files
%defattr(-,root,root)
%license COPYING doc/LICENSE*
%doc AUTHORS ChangeLog NEWS README
%{_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

## to build compat32 for x86_64 architecture support
%if %{build_compat32}
%files -n compat32-%{name}-gtk
%defattr(-,root,root)
%{_libdir}/gtk-2.0/immodules/im-scim-bridge.so

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

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


%changelog
* Fri Jul  8 2016 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 0.4.16-19
- rebuilt with new toolchain.

* Sun Jan 25 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> 0.4.16-18
- fixed compat32 Requires

* Mon Dec 30 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 0.4.16-17
- rebuild with VineSeed environment
- add Patch100 (scim-bridge-0.4.16-header.patch)

* Tue Jan 10 2012 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-16
- rebuilt with qt4-4.8.0

* Tue Mar  8 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-15
- rebuilt with qt4-4.7.2

* Sat Feb  5 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-14
- added BR: libXmu-devel to qt package

* Sun Jan 30 2011 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-13
- rebuilt with qt4-4.7.1

* Sat Oct 09 2010 Munehiro Yamamoto <munepi@vinelinux.org> 0.4.16-12
- added compat32-* packages for x86_64 architecture support

* Thu Jul 29 2010 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 0.4.16-11
- rebuilt with qt4-4.6.3

* Tue Jun 22 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> 0.4.16-10
- used %{?_smp_mflags} macro on build
- deleted in unused log in changelog
  - Patch8 was none, forgot to delete...

* Fri May 14 2010 Toshiharu Kudoh <toshi.kd2@gmail.com> 0.4.16-9
- added Patch6,7 from Fedora development
  - to fix Text input in firefox becomes increasingly sluggish (Patch6)
  - to fix Process /usr/bin/scim-bridge was killed by signal 11 (Patch7)
- added configure --disable-static option

* 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