# The naming scheme in non-Mandriva-based distros
%if 0%{!?mklibname:1}
%define mklibname(ds)  lib%{1}%{?2:%{2}}%{-s:-static}%{-d:-devel}
%endif
%if 0%{!?mkrel:1}
%define mkrel(c) %{1}%{?dist}
%endif

%if 0%{?centos} || 0%{?epel}
%bcond_with anthy
%bcond_with dict
%bcond_with m17n
%else
%bcond_without anthy
%bcond_without dict
%bcond_without m17n
%endif

# CentOS 10 doesn't include GTK 2. More distros will likely follow.
%if 0%{?centos} < 10
%bcond_without gtk2
%else
%bcond_with gtk2
%endif

%if 0%{?centos} || 0%{?epel} || 0%{?fedora} || 0%{?suse_version} || "%{_vendor}" == "openEuler"
%bcond_with qt5
%else
%bcond_without qt5
%endif

%if 0%{?centos} || 0%{?epel} || 0%{?fedora} || (0%{?mageia} && 0%{?mageia} < 9) || 0%{?suse_version} || "%{_vendor}" == "openEuler"
%bcond_with qt6
%else
%bcond_without qt6
%endif

%if 0%{?centos} || 0%{?epel} || 0%{?fedora} || 0%{?suse_version}
%bcond_with xim
%else
%bcond_without xim
%endif

%if 0%{?mageia}
%bcond_without eb
%else
%bcond_with eb
%endif


%define anthy_version	8622
%define m17n_lib_version	1.3.4

%define uim_major	8
%define libname_orig	lib%{name}
%define libname		%mklibname %{name} %{uim_major}
%define develname	%mklibname %{name} -d

%define custom_major	2
%define libcustom_orig	libuim-custom
%define libcustom	%mklibname uim-custom %{custom_major}

%define gcroots_major	0
%define libgcroots_orig	libgcroots
%define libgcroots	%mklibname gcroots %{gcroots_major}

%define scm_major	0
%define libscm		%mklibname uim-scm %{scm_major}

%if %{with gtk2}
# This should probably be changed, as GTK 2 is rarely used anymore.
%global default_toolkit gtk
%else
%global default_toolkit gtk3
%endif

Name:		uim
Summary:	Multilingual input method library
Version:	1.9.0
Release:	%mkrel 1.3
Group:		System/Internationalization
# uim itself is licensed under BSD
# scm/py.scm, helper/eggtrayicon.[ch], qt/pref-kseparator.{cpp,h}
#   and qt/chardict/chardict-kseparator.{cpp,h} is licensed under LGPLv2+
# pixmaps/*.{svg,png} is licensed under BSD or LGPLv2
License:	BSD and LGPLv2+ and (BSD or LGPLv2)
URL:		https://github.com/uim/uim
Source0:	https://github.com/uim/uim/releases/download/%{version}/uim-%{version}.tar.bz2
Patch0:		uim-1.8.9-no-plasma5-applet.patch
Patch1:		uim-emacs-utf8.patch
# From Fedora to get it to compile in rawhide
Patch2:         uim-ftbfs.patch

# Build system
BuildRequires:	autoconf
BuildRequires:	automake
BuildRequires:	ed
BuildRequires:	intltool
BuildRequires:	libtool
# Basic input methods
%if %{with m17n}
BuildRequires:	m17n-db
BuildRequires:	m17n-lib-devel >= %{m17n_lib_version}
%endif
%if %{with anthy}
BuildRequires:	pkgconfig(anthy) >= %{anthy_version}
%endif
# Console frontend (uim-fep)
BuildRequires:	pkgconfig(libedit)
BuildRequires:	pkgconfig(ncurses)
# XIM frontend
BuildRequires:	pkgconfig(ice)
BuildRequires:	pkgconfig(x11)
BuildRequires:	pkgconfig(xext)
# GTK 2 frontend
%if %{with gtk2}
BuildRequires:	pkgconfig(gdk-x11-2.0)
BuildRequires:	pkgconfig(gtk+-2.0) >= 2.4.0
BuildRequires:	pkgconfig(xext)
%endif
# GTK 3 frontend
BuildRequires:	pkgconfig(gtk+-3.0)
# Qt 5 frontend
%if %{with qt5}
BuildRequires:	cmake
BuildRequires:	(extra-cmake-modules or cmake(ECM) or cmake(ecm))
Buildrequires:	cmake(KF5Plasma)
BuildRequires:	pkgconfig(Qt5Core)
BuildRequires:	pkgconfig(Qt5Gui)
BuildRequires:	pkgconfig(Qt5Qml)
BuildRequires:	pkgconfig(Qt5Quick)
BuildRequires:	pkgconfig(Qt5Widgets)
BuildRequires:	pkgconfig(Qt5X11Extras)
%endif
# Qt 6 frontend
%if %{with qt6}
BuildRequires:	pkgconfig(Qt6Core)
BuildRequires:	pkgconfig(Qt6Gui)
BuildRequires:  pkgconfig(Qt6Platform)
BuildRequires:	pkgconfig(Qt6Widgets)
%endif
# Extras
BuildRequires:  pkgconfig(expat)
BuildRequires:  pkgconfig(libffi)
BuildRequires:	pkgconfig(libnotify) >= 0.4
BuildRequires:  pkgconfig(libcurl)
BuildRequires:  pkgconfig(sqlite3)
%if %{with eb}
BuildRequires:  eb-devel
%endif

Requires:	%{libname} = %{version}
Requires:       uim-%{default_toolkit}
%if %{with anthy}
Requires:	anthy >= %{anthy_version}
%endif
%if %{with m17n}
Requires:	m17n-lib >= %{m17n_lib_version}
%endif
Requires:	skkdic

%if %{with anthy}
Provides:	uim-anthy
%endif
%if %{with m17n}
Provides: uim-m17nlib
%endif
Provides: uim-prime, uim-skk

%description
Uim is a multilingual input method library. Uim's project goal is
to provide secure and useful input method for all languages.

%if %{with gtk2}
%package	gtk
Summary:	GNOME helper for uim
Group:		System/Internationalization
Requires:	%{name} = %{version}
Requires:	gtk+2
Provides:	uim-applet-gtk
Provides:	uim-applet = %{version}

%description	gtk
GNOME helper for uim. It contains some apps like toolbar,
system tray, applet, candidate window for Uim library.
%endif

%package	gtk3
Summary:	GNOME3 helper for uim
Group:		System/Internationalization
Requires:	%{name} = %{version}
Requires:	gtk+3
Provides:	uim-applet-gtk3
Provides:	uim-applet = %{version}

%description	gtk3
GNOME3 helper for uim. It contains some apps like toolbar,
system tray, applet, candidate window for Uim library.

%if %{with qt5}
%package	qt5
Summary:	Qt5 helper for uim
Group:		System/Internationalization
Requires:	%{name} = %{version}
Requires:	qtbase5-common
Provides:	uim-qt5immodule = %{version}-%{release}
Provides:	uim-applet-plasma5

%description	qt5
A plugin for using UIM on qt5-immodule and also provides the helper
programs.
%endif

%if %{with qt6}
%package	qt6
Summary:	Qt6 helper for uim
Group:		System/Internationalization
Requires:	%{name} = %{version}
Requires:	qtbase6-common
Provides:	uim-qt6immodule = %{version}-%{release}
Provides:	uim-applet-plasma6

%description	qt6
A plugin for using UIM on qt6-immodule and also provides the helper
programs.
%endif

%package	base
Summary:	Misc files needed by UIM library
Group:		System/Internationalization

%description	base
Misc files needed by UIM library.

%package -n	%{libname}
Summary:	UIM library
Group:		System/Internationalization
Provides:	%{libname_orig} = %{version}-%{release}
Requires:	uim-base

%description -n	%{libname}
UIM library.

%package -n	%{develname}
Summary:	Headers of uim for development
Group:		Development/C
Requires:	%{libname} = %{version}
Provides:	%{name}-devel = %{version}-%{release}
Provides:	%{libname_orig}-devel = %{version}-%{release}

%description -n	%{develname}
Headers of %{name} for development.

%package -n	%{libcustom}
Summary:	Custom library for UIM
Group:		System/Internationalization
Provides:	%{libcustom_orig} = %{version}-%{release}

%description -n	%{libcustom}
Custom library for UIM.

%package -n	%{libgcroots}
Summary:	Gcroots library for UIM
Group:		System/Internationalization
Provides:	%{libgcroots_orig} = %{version}-%{release}

%description -n	%{libgcroots}
This library abstracts architecture-dependent parts of garbage collector
roots acquisition such as register windows of SPARC and register stack
backing store of IA-64.

With this library, one can easily write one's own garbage collector with a
small footprint, some application-specific optimizations, for just learning or
testing experimental ideas.

%package -n	%{libscm}
Summary:	Scm library for UIM
Group:		System/Internationalization

%description -n	%{libscm}
Scm library for UIM.

%prep
%autosetup -p1

%build
%configure \
   --disable-static \
   --disable-rpath \
%if %{with anthy}
   --with-anthy \
   --with-anthy-utf8 \
%endif
   --with-curl \
%if %{with eb}
   --with-eb \
   --with-eb-conf=%{_libdir}/eb.conf \
%endif
   --with-expat \
   --with-ffi \
%if %{with m17n}
   --with-m17nlib \
%endif
   --with-sqlite3 \
   --without-canna \
   --without-prime \
   --without-scim \
%if ! %{with gtk2}
   --without-gtk2 \
%endif
   --without-qt4 \
   --without-qt4-immodule \
   --disable-kde4-applet \
%if %{with qt5}
   --with-qt5 \
   --with-qt5-immodule \
%else
   --without-qt5 \
   --without-qt5-immodule \
%endif
%if %{with qt6}
   --with-qt6 \
   --with-qt6-immodule \
%else
   --without-qt6 \
   --without-qt6-immodule \
%endif
%if %{with dict}
   --enable-dict \
%endif
   --enable-notify=stderr,libnotify \
   --enable-pref \
   --disable-gnome-applet \
   --disable-gnome3-applet \
   --disable-kde-applet \
   --enable-default-toolkit=%{default_toolkit} \
   --disable-warnings-into-error

%make_build

%install
%make_install

# remove docs for sigscheme (they should be installed by %%doc)
rm -rf %{buildroot}%{_datadir}/doc/sigscheme

%find_lang %{name}

%files -f %{name}.lang
%doc AUTHORS README
%doc sigscheme/doc/*
%license COPYING
%{_bindir}/uim-el*-agent
%{_bindir}/uim-fep*
%{_bindir}/uim-help
%{_bindir}/uim-module-manager
%{_bindir}/uim-sh
%if %{with xim}
%{_bindir}/uim-xim
%endif
%if %{with m17n}
%{_bindir}/uim-m17nlib-relink-icons
%endif
%{_datadir}/applications/*
%{_datadir}/emacs/site-lisp/uim-el/*.el
%if %{with xim}
%{_mandir}/man1/*
%endif
%{_datadir}/uim
%{_libdir}/uim/notify/

%if %{with gtk2}
%files gtk
%license COPYING
%{_bindir}/uim-input-pad-ja
%if %{with dict}
%{_bindir}/uim-dict-gtk
%endif
%{_bindir}/uim-im-switcher-gtk
%{_bindir}/uim-pref-gtk
%{_bindir}/uim-toolbar-gtk
%{_bindir}/uim-toolbar-gtk-systray
%{_libexecdir}/uim-candwin-gtk
%{_libexecdir}/uim-candwin-horizontal-gtk
%{_libexecdir}/uim-candwin-tbl-gtk
%{_libdir}/gtk-2.0/*/immodules/*.so
%endif

%files gtk3
%license COPYING
%if %{with dict}
%{_bindir}/uim-dict-gtk3
%endif
%{_bindir}/uim-im-switcher-gtk3
%{_bindir}/uim-input-pad-ja-gtk3
%{_bindir}/uim-pref-gtk3
%{_bindir}/uim-toolbar-gtk3
%{_bindir}/uim-toolbar-gtk3-systray
%{_libdir}/gtk-3.0/*/immodules/im-uim.so
%{_libexecdir}/uim-candwin-gtk3
%{_libexecdir}/uim-candwin-tbl-gtk3
%{_libexecdir}/uim-candwin-horizontal-gtk3

%if %{with qt5}
%files qt5
%license COPYING
%if %{with dict}
%{_bindir}/uim-chardict-qt5
%endif
%{_bindir}/uim-im-switcher-qt5
%{_bindir}/uim-pref-qt5
%{_bindir}/uim-toolbar-qt5
%{_libexecdir}/uim-candwin-qt5
%{_qt5_plugindir}/platforminputcontexts/*.so
%endif

%if %{with qt6}
%files qt6
%license COPYING
%if %{with dict}
%{_bindir}/uim-chardict-qt6
%endif
%{_bindir}/uim-im-switcher-qt6
%{_bindir}/uim-pref-qt6
%{_bindir}/uim-toolbar-qt6
%{_libexecdir}/uim-candwin-qt6
%{_qt6_plugindir}/platforminputcontexts/*.so
%endif

%files base
%{_libexecdir}/uim-helper-server
%{_libdir}/uim/plugin/
%{_datadir}/locale/*/LC_MESSAGES/uim.mo

%files -n %{libname}
%license COPYING
%{_libdir}/libuim.so.%{uim_major}{,.*}

%files -n %{libgcroots}
%license COPYING
%{_libdir}/libgcroots.so.%{gcroots_major}{,.*}

%files -n %{libcustom}
%license COPYING
%{_libdir}/libuim-custom.so.%{custom_major}{,.*}

%files -n %{libscm}
%license COPYING
%{_libdir}/libuim-scm.so.%{scm_major}{,.*}

%files -n %{develname}
%doc AUTHORS README
%{_includedir}/*
%{_libdir}/lib*.*
%{_libdir}/pkgconfig/*.pc