#Global macro or variable
%global __provides_exclude_from ^%{_libdir}/gtk-2.0
%define gtk_bin_version 2.10.0
%global enable_immodules_package 0

#Basic Information
Name:            gtk2
Version:         2.24.33
Release:         6
Summary:         GTK+ graphical user interface library
License:         LGPLv2+
URL:             http://www.gtk.org
Source:          http://download.gnome.org/sources/gtk+/2.24/gtk+-%{version}.tar.xz
Source2:         im-cedilla.conf

# Use Python 3 in gtk-builder-convert
# Accepted upstream: https://gitlab.gnome.org/GNOME/gtk/merge_requests/1080
# https://bugzilla.gnome.org/show_bug.cgi?id=583273
Patch1:  icon-padding.patch
# https://bugzilla.gnome.org/show_bug.cgi?id=599618
Patch2:  tooltip-positioning.patch
# https://bugzilla.gnome.org/show_bug.cgi?id=611313
Patch3: window-dragging.patch

#Dependency
BuildRequires:   pkgconfig(glib-2.0) >= 2.28.0 pkgconfig(atk) >= 2.28.0
BuildRequires:   pkgconfig(pango) >= 1.20 pkgconfig(gdk-pixbuf-2.0) >= 2.21.0
BuildRequires:   pkgconfig(cairo) >= 1.6  pkgconfig(gobject-introspection-1.0) >= 0.9.3
BuildRequires:   pkgconfig(xi) pkgconfig(xrandr) pkgconfig(xrender) pkgconfig(xcursor)
BuildRequires:   pkgconfig(xinerama) pkgconfig(xcomposite) pkgconfig(xdamage)
BuildRequires:   gettext libxslt python3-devel
BuildRequires:   gtk-doc automake autoconf libtool pkgconfig 
%if 0%{?openEuler}
BuildRequires:	 cups-devel
%endif

Requires:        hicolor-icon-theme gtk-update-icon-cache
Requires:        gdk-pixbuf2-modules glib2 >= 2.28.0 atk >= 1.29.2 pango >= 1.20
Requires:        libXrandr >= 1.2.99.4-2
Requires(post):  libtiff >= 3.6.1

# Conflicts with packages containing theme engines
# built against the 2.4.0 ABI
Conflicts:       gtk2-engines < 2.7.4-7
Conflicts:       libgnomeui < 2.15.1cvs20060505-2
Conflicts:       redhat-artwork < 0.243-1

Provides:        gail = %{version}-%{release}
Obsoletes:       gail < 2.13.0-1

%description
GTK+ is a library for creating graphical user interfaces. The library
is created in C programming language. The GTK+ is also called the GIMP
Toolkit. Originally, the library was created while developing the GIMP
image manipulation program.

%if %{enable_immodules_package}
%package         immodules
Summary:         Input methods for GTK+
Requires:        gtk2 = %{version}-%{release}
# for /etc/X11/xinit/xinput.d
Requires:        imsettings

%description     immodules
The gtk2-immodules package contains standalone input methods that are shipped
as part of GTK+.
%endif

%package         immodule-xim
Summary:         XIM support for GTK+
Requires:        gtk2 = %{version}-%{release}

%description     immodule-xim
The gtk2-immodule-xim package contains XIM support for GTK+.


%package         devel
Summary:         Development files for GTK+
Requires:        gtk2 = %{version}-%{release}
Requires:        pango-devel >= 1.20 gdk-pixbuf2-devel cairo-devel >= 1.6
Requires:        atk-devel >= 1.29.2 glib2-devel >= 2.28.0
Requires:        libX11-devel libXcursor-devel libXinerama-devel
Requires:        libXext-devel libXi-devel libXrandr-devel
Requires:        libXfixes-devel libXcomposite-devel
Requires:        pkgconfig

Provides:        gail-devel = %{version}-%{release}
Obsoletes:       gail-devel < 2.13.0-1
Provides:        gtk2-devel-doc = %{version}-%{release}
Obsoletes:       gtk2-devel-doc < %{version}-%{release}

%description     devel
This package contains the libraries, header files and developer documentation
that are needed for writing applications with the GTK+ widget toolkit.

%package         help
Summary:         Developer documentation for GTK+
Requires:        gtk2 = %{version}-%{release}

%description     help
This package contains developer documentation for the GTK+ widget toolkit.

#Build sections
%prep
%autosetup -n gtk+-%{version} -p1

%build
export CFLAGS='-fno-strict-aliasing %optflags'
(if ! test -x configure; then NOCONFIGURE=1 ./autogen.sh; CONFIGFLAGS=--enable-gtk-doc; fi;
 %configure $CONFIGFLAGS \
         --enable-man            \
         --with-xinput=xfree     \
         --enable-debug          \
	 %if !0%{?openEuler}
	 --disable-cups
	 %endif
)
sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
%make_build

%install
make install DESTDIR=%{buildroot}        \
             RUN_QUERY_IMMODULES_TEST=false

echo ".so man1/gtk-query-immodules-2.0.1" > %{buildroot}%{_mandir}/man1/gtk-query-immodules-2.0-%{__isa_bits}.1

%find_lang gtk20
%find_lang gtk20-properties

mkdir -p tmpdocs
cp -aR docs/tutorial/html tmpdocs/tutorial
cp -aR docs/faq/html tmpdocs/faq
mkdir -p tmpdocs/examples
for dir in $(find examples/* -type d); do
    cp -aR $dir tmpdocs/examples
done

mv %{buildroot}%{_bindir}/gtk-query-immodules-2.0 %{buildroot}%{_bindir}/gtk-query-immodules-2.0-64

# Install input  method frameworks conf
mkdir -p %{buildroot}%{_sysconfdir}/X11/xinit/xinput.d
cp %{SOURCE2} %{buildroot}%{_sysconfdir}/X11/xinit/xinput.d

# Use python3 shebang instead of ambiguous python
pathfix.py -pn -i %{__python3} %{buildroot}%{_bindir}/gtk-builder-convert

# rm unpackaged files
rm %{buildroot}%{_libdir}/*.la
rm %{buildroot}%{_libdir}/gtk-2.0/*/*.la
rm %{buildroot}%{_libdir}/gtk-2.0/%{gtk_bin_version}/*/*.la
rm %{buildroot}%{_bindir}/gtk-update-icon-cache
rm %{buildroot}%{_mandir}/man1/gtk-update-icon-cache.1*

touch %{buildroot}%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules.cache

mkdir -p %{buildroot}%{_libdir}/gtk-2.0/modules
mkdir -p %{buildroot}%{_libdir}/gtk-2.0/immodules
mkdir -p %{buildroot}%{_libdir}/gtk-2.0/%{gtk_bin_version}/filesystems

%transfiletriggerin -- %{_libdir}/gtk-2.0/immodules/ %{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/
gtk-query-immodules-2.0-64 --update-cache

%transfiletriggerpostun -- %{_libdir}/gtk-2.0/immodules/ %{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/
gtk-query-immodules-2.0-64 --update-cache

#Install and uninstall scripts
%pre

%preun

%ldconfig_scriptlets

#Files list
%files -f gtk20.lang
%doc AUTHORS NEWS README
%license COPYING
%{_bindir}/gtk-query-immodules-2.0-64
%{_libdir}/libgtk-x11-2.0.so.*
%{_libdir}/libgdk-x11-2.0.so.*
%{_libdir}/libgailutil.so.*
%{_libdir}/girepository-1.0
%dir %{_libdir}/gtk-2.0
%dir %{_libdir}/gtk-2.0/%{gtk_bin_version}
%{_libdir}/gtk-2.0/%{gtk_bin_version}/engines
%{_libdir}/gtk-2.0/%{gtk_bin_version}/filesystems
%dir %{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules
%{_libdir}/gtk-2.0/%{gtk_bin_version}/printbackends
%{_libdir}/gtk-2.0/modules
%{_libdir}/gtk-2.0/immodules
%ghost %{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules.cache
%dir %{_datadir}/gtk-2.0
%{_datadir}/themes/Default
%{_datadir}/themes/Emacs
%{_datadir}/themes/Raleigh
%if !%{enable_immodules_package}
%exclude %{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/*.so
%exclude %{_sysconfdir}/X11/xinit/xinput.d/im-cedilla.conf
%exclude %config(noreplace) %{_sysconfdir}/gtk-2.0/im-multipress.conf
%endif

%if %{enable_immodules_package}
%files immodules
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-am-et.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-cedilla.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-cyrillic-translit.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-inuktitut.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-ipa.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-multipress.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-thai.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-ti-er.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-ti-et.so
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-viqr.so
%{_sysconfdir}/X11/xinit/xinput.d/im-cedilla.conf
%dir %{_sysconfdir}/gtk-2.0
%config(noreplace) %{_sysconfdir}/gtk-2.0/im-multipress.conf
%endif

%files immodule-xim
%{_libdir}/gtk-2.0/%{gtk_bin_version}/immodules/im-xim.so

%files devel -f gtk20-properties.lang
%{_libdir}/lib*.so
%{_libdir}/gtk-2.0/include
%{_libdir}/pkgconfig/*
%{_bindir}/gtk-builder-convert
%{_bindir}/gtk-demo
%{_datadir}/gtk-2.0/demo
%{_datadir}/aclocal/*
%{_datadir}/gir-1.0
%{_includedir}/*

%files help
%{_datadir}/gtk-doc
%doc tmpdocs/tutorial
%doc tmpdocs/faq
%doc tmpdocs/examples
%{_mandir}/man1/gtk-query-immodules-2.0*
%{_mandir}/man1/gtk-builder-convert.1.gz

%changelog
* Sat Jun 11 2022 wangkeorng <wangkeorng@h-partners.com> - 2.24.33-6
- delete autosetup macro in changelog

* Sat May 7 2022 dongyuzhen <dongyuzhen@h-partners.com> - 2.24.33-5
- fix changelog

* Fri Jan 14 2022 wangkerong <wangkerong@huawei.com> - 2.24.33-4
- Other distros disable cups

* Fri Jul 30 2021 chenyanpanHW <chenyanpan@huawei.com> - 2.24.33-3
- DESC: delete -Sgit from autosetup, and delete BuildRequires git

* Wed Mar 10 2021 yanan <yanan@huawei.com> - 2.24.33-2
- use multi-thread to build

* Fri Jan 29 2021 jinzhimin <jinzhimin2@huawei.com> - 2.24.33-1
- upgrade to 2.24.33

* Fri Feb 28 2020 xiaoweiwei <xiaoweiwei5@huawei.com> - 2.24.32-7
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:disable immodules package

* Mon Feb 24 2020 hexiujun <hexiujun1@huawei.com> - 2.24.32-6
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:Port gtk2-devel's gtk-builder-convert to Python 3

* Thu Jan 9 2020 openEuler Buildteam <buildteam@openeuler.org> - 2.24.32-5
- Type:enhancement
- ID:NA
- SUG:NA
- DESC:delete Patches

* Sat Sep 14 2019 openEuler Buildteam <buildteam@openeuler.org> - 2.24.32-4
- Package init
