%bcond_with gtk_update_icon_cache
%bcond_with docs

# biarch support
%define build_compat32 %{?_with_compat32:1}%{!?_with_compat32:0}
%define _query_suffix %{nil}
%if %{build_compat32}
%define _query_suffix -32
%endif

Summary: GTK graphical user interface library
Summary(ja): GTK GUI ライブラリ
Name: gtk4
Version: 4.2.1
Release: 1%{?_dist_release}
Group: system
Vendor: Project Vine
Distribution: Vine Linux

License: LGPL
URL: https://www.gtk.org
%define bin_version 4.0.0
%global shortver %(echo %{version} | cut -d . -f 1,2)
Source0: https://download.gnome.org/sources/gtk/%{shortver}/gtk-%{version}.tar.xz

# for Vine
Patch100: gtk+-3.14.0-vine-default-theme.patch

BuildRoot: %{_tmppath}/gtk-%{version}-root
BuildRequires: cairo-devel
BuildRequires: colord-devel
BuildRequires: cups-devel
BuildRequires: desktop-file-utils
BuildRequires: docbook-style-xsl
BuildRequires: fribidi-devel
BuildRequires: gdk-pixbuf2-devel
BuildRequires: glib2-devel
BuildRequires: gobject-introspection-devel
BuildRequires: gtk-doc >= 1.20
BuildRequires: json-glib-devel
BuildRequires: libepoxy-devel
BuildRequires: libICE-devel
BuildRequires: libXcomposite-devel
BuildRequires: libXcursor-devel
BuildRequires: libXdamage-devel
BuildRequires: libXfixes-devel
BuildRequires: libXi-devel
BuildRequires: libXinerama-devel
BuildRequires: libXrandr-devel
BuildRequires: libXrender-devel
BuildRequires: meson
BuildRequires: pandoc
BuildRequires: pango-devel
BuildRequires: pkgconfig(avahi-gobject)
BuildRequires: pkgconfig(egl)
BuildRequires: pkgconfig(graphene-gobject-1.0)
BuildRequires: pkgconfig(gstreamer-player-1.0)
BuildRequires: pkgconfig(vulkan)
BuildRequires: pkgconfig(wayland-client)
BuildRequires: pkgconfig(wayland-cursor)
BuildRequires: pkgconfig(wayland-egl)
BuildRequires: pkgconfig(wayland-protocols)
BuildRequires: pkgconfig(xkbcommon)
BuildRequires: rest-devel

# required for icon themes apis to work
Requires: hicolor-icon-theme
Requires: libXrandr >= 1.3.0
%if %{with gtk_update_icon_cache}
# enable when GTK4 becomes standard version.
Provides: gtk-update-icon-cache = %{version}-%{release}
%endif
%if ! %{with docs}
Obsoletes: gtk4-docs < %{version}-%{release}
%endif

%description
GTK is a multi-platform toolkit for creating graphical user
interfaces. Offering a complete set of widgets, GTK is suitable for
projects ranging from small one-off tools to complete application
suites.


%package devel
Summary: Development tools for GTK applications.
Summary(ja): GTK アプリケーション開発ツール
Group: programming
Requires: %{name} = %{version}-%{release}
Requires: pango-devel
Requires: atk-devel
Requires: glib2-devel
Requires: gdk-pixbuf2-devel
Requires: libX11-devel, libXcursor-devel, libXinerama-devel
Requires: libXext-devel, libXi-devel, libXrandr-devel
Requires: libXfixes-devel, libXcomposite-devel
Requires: libpng-devel

%description devel
The gtk4-devel package contains the header files and developer
docs for the GTK widget toolkit.


%if %{with docs}
%package docs
Summary: Developer documentation for GTK
Summary(ja): GTK による開発のドキュメント
Group: documentation
Requires: gtk4 = %{version}-%{release}

%description docs
This package contains developer documentation for version 4 of the GTK
widget toolkit.
%endif


#######################################################################
# compat32
%package -n compat32-%{name}
Summary: GTK graphical user interface library
Summary(ja): GTK GUI ライブラリ
Group: system,legacy
Requires: compat32-libXrandr >= 1.3.0

%description -n compat32-%{name}
GTK is a multi-platform toolkit for creating graphical user
interfaces. Offering a complete set of widgets, GTK is suitable for
projects ranging from small one-off tools to complete application
suites.

%package -n compat32-%{name}-devel
Summary: Development tools for GTK applications.
Summary(ja): GTK アプリケーション開発ツール
Group: programming,legacy
Requires: compat32-%{name} = %{version}-%{release}
Requires: %{name}-devel = %{version}
Requires: compat32-libX11-devel, compat32-libXcursor-devel, compat32-libXinerama-devel
Requires: compat32-libXext-devel, compat32-libXi-devel, compat32-libXrandr-devel
Requires: compat32-libXfixes-devel, compat32-libXcomposite-devel
Requires: compat32-libpng-devel

%description -n compat32-%{name}-devel
The gtk4-devel package contains the header files and developer
docs for the GTK GUI toolkit.  


%debug_package


%prep
%setup -q -n gtk-%{version}
%patch100 -p1 -b .vine-default-theme


%build
export CFLAGS='-fno-strict-aliasing -DG_DISABLE_CAST_CHECKS -DG_DISABLE_ASSERT %{build_cflags}'
%meson \
        -Dx11-backend=true \
        -Dwayland-backend=true \
        -Dbroadway-backend=true \
        -Dmedia-ffmpeg=disabled \
        -Dmedia-gstreamer=enabled \
        -Dxinerama=enabled \
        -Dcolord=enabled \
        -Dsassc=disabled \
%if %{with docs}
        -Dgtk_doc=true \
%else
        -Dgtk_doc=false \
%endif
        -Dman-pages=true \
        -Dinstall-tests=false
%meson_build
%if %{with docs}
# Workaround for https://github.com/mesonbuild/meson/issues/8117
%meson_build gtk4-doc:custom
%endif


%install
%meson_install
%find_lang gtk40
%find_lang gtk40-properties

cat gtk40.lang gtk40-properties.lang > all.lang

mkdir -p $RPM_BUILD_ROOT%{_sysconfdir}/gtk-4.0
mkdir -p $RPM_BUILD_ROOT%{_libdir}/gtk-4.0/modules
mkdir -p $RPM_BUILD_ROOT%{_libdir}/gtk-4.0/%{bin_version}/theming-engines

mkdir -p $RPM_BUILD_ROOT%{_libdir}/gtk-4.0/%{bin_version}/immodules


%if %{with gtk_update_icon_cache}
%post
if [ $1 = 1 ]; then
	update-alternatives \
		--install %{_bindir}/gtk-update-icon-cache gtk-update-icon-cache \
			%{_bindir}/gtk4-update-icon-cache 40
fi

%postun 
if [ $1 -eq 0 ]; then
	update-alternatives \
		--remove gtk-update-icon-cache %{_bindir}/gtk4-update-icon-cache
fi

%posttrans
if [ ! -L %{_bindir}/gtk-update-icon-cache ]; then
	rm -f %{_bindir}/gtk-update-icon-cache
	update-alternatives \
		--install %{_bindir}/gtk-update-icon-cache gtk-update-icon-cache \
			%{_bindir}/gtk4-update-icon-cache 40
fi
%endif


%files -f gtk40.lang
%license COPYING
%doc AUTHORS NEWS README.md
%{_bindir}/gtk4-broadwayd
%{_bindir}/gtk4-launch
%{_bindir}/gtk4-update-icon-cache
%{_libdir}/libgtk-4.so.*
%dir %{_libdir}/gtk-4.0
%dir %{_libdir}/gtk-4.0/%{bin_version}
%{_libdir}/gtk-4.0/%{bin_version}/immodules/
%{_libdir}/gtk-4.0/%{bin_version}/media/
%{_libdir}/gtk-4.0/%{bin_version}/printbackends/
%{_libdir}/gtk-4.0/%{bin_version}/theming-engines/
%{_libdir}/gtk-4.0/modules
%{_libdir}/girepository-1.0
%{_datadir}/glib-2.0/schemas/org.gtk.gtk4.Settings.ColorChooser.gschema.xml
%{_datadir}/glib-2.0/schemas/org.gtk.gtk4.Settings.Debug.gschema.xml
%{_datadir}/glib-2.0/schemas/org.gtk.gtk4.Settings.EmojiChooser.gschema.xml
%{_datadir}/glib-2.0/schemas/org.gtk.gtk4.Settings.FileChooser.gschema.xml
%dir %{_datadir}/gtk-4.0
%dir %{_sysconfdir}/gtk-4.0
%{_datadir}/gtk-4.0/emoji/
%{_mandir}/man1/gtk4-broadwayd.1*
%{_mandir}/man1/gtk4-launch.1*
%{_mandir}/man1/gtk4-update-icon-cache.1*

%files devel -f gtk40-properties.lang
%{_libdir}/libgtk-4.so
%{_includedir}/*
%{_libdir}/pkgconfig/*
%{_bindir}/gtk4-builder-tool
%{_bindir}/gtk4-demo
%{_bindir}/gtk4-demo-application
%{_bindir}/gtk4-encode-symbolic-svg
%{_bindir}/gtk4-icon-browser
%{_bindir}/gtk4-print-editor
%{_bindir}/gtk4-query-settings
%{_bindir}/gtk4-widget-factory
%{_datadir}/applications/org.gtk.Demo4.desktop
%{_datadir}/applications/org.gtk.IconBrowser4.desktop
%{_datadir}/applications/org.gtk.PrintEditor4.desktop
%{_datadir}/applications/org.gtk.WidgetFactory4.desktop
%{_datadir}/icons/hicolor/*/apps/org.gtk.Demo4*.svg
%{_datadir}/icons/hicolor/*/apps/org.gtk.IconBrowser4*.svg
%{_datadir}/icons/hicolor/*/apps/org.gtk.PrintEditor4*.svg
%{_datadir}/icons/hicolor/*/apps/org.gtk.WidgetFactory4*.svg
%{_datadir}/gettext/*
%{_datadir}/gir-1.0/*
%{_datadir}/glib-2.0/schemas/org.gtk.Demo4.gschema.xml
%{_datadir}/gtk-4.0/gtk4builder.rng
%{_datadir}/gtk-4.0/valgrind/
%{_datadir}/metainfo/org.gtk.Demo4.appdata.xml
%{_datadir}/metainfo/org.gtk.IconBrowser4.appdata.xml
%{_datadir}/metainfo/org.gtk.PrintEditor4.appdata.xml
%{_datadir}/metainfo/org.gtk.WidgetFactory4.appdata.xml
%{_mandir}/man1/gtk4-builder-tool.1*
%{_mandir}/man1/gtk4-demo.1*
%{_mandir}/man1/gtk4-demo-application.1*
%{_mandir}/man1/gtk4-encode-symbolic-svg.1*
%{_mandir}/man1/gtk4-icon-browser.1*
%{_mandir}/man1/gtk4-query-settings.1*
%{_mandir}/man1/gtk4-widget-factory.1*

%if %{with docs}
%files docs
%{_datadir}/gtk-doc
%endif

# compat32
%if %{build_compat32}
%files -n compat32-%{name}
%{_libdir}/libgtk-4.so.*
%dir %{_libdir}/gtk-4.0
%dir %{_libdir}/gtk-4.0/%{bin_version}
%{_libdir}/gtk-4.0/%{bin_version}/immodules/
%{_libdir}/gtk-4.0/%{bin_version}/media/
%{_libdir}/gtk-4.0/%{bin_version}/printbackends/
%{_libdir}/gtk-4.0/%{bin_version}/theming-engines/
%dir %{_libdir}/gtk-4.0/modules
%dir %{_sysconfdir}/gtk-4.0

%files -n compat32-%{name}-devel
%defattr(-, root, root)
%{_libdir}/lib*.so
%dir %{_libdir}/gtk-4.0
%endif


%changelog
* Sun May 09 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.2.1-1
- new upstream release.

* Sat Apr 10 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.2.0-1
- new upstream release.

* Sun Mar 28 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 4.0.3-1
- new upstream release.

* Mon Mar 08 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.24.26-2
- added "Provides: /usr/bin/gtk-update-icon-cache".

* Mon Mar 08 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.24.26-1
- new upstream release.
- enabled gtk-update-icon-cache.
- added triggers.

* Fri Feb 12 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.24.24-1
- new upstream release.

* Fri Aug 14 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.24.22-1
- new upstream release.

* Wed Jul 29 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.24.21-1
- new upstream release.

* Tue May 05 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.24.20-1
- new upstream release.
- dropped Patch0, 10010, 10019 and 10020.
- dropped Source10001.

* Sat Dec 29 2018 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> 3.22.30-1
- update to 3.22.30
- dropped Patch10019.
- imported Patch10019 and 10020 from CentOS.

* Mon Mar 26 2018 IWAI, Masaharu <iwaim.sub@gmail.com> 3.22.10-1
- update to 3.22.10
- sync CentOS 7 - 3.22.10-5.el7_4
 - add ja.po (Source10001)
 - add patches (Patch10018, 10019)

* Thu Jul 14 2016 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.20.6-1
- new upstream release

* Sat Dec 19 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.18.6-1
- new upstream release

* Fri Nov 20 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.18.5-1
- new upstream release

* Fri Nov 13 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.18.4-1
- new upstream release

* Thu Oct 29 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.18.2-1
- new upstream release

* Sat Oct 10 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.16.7-1
- new upstream release

* Sun Jul 26 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.16.6-1
- new upstream release

* Fri Jul 10 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.16.5-1
- new upstream release

* Thu Jun 11 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.16.4-1
- new upstream release

* Thu May 14 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.16.3-1
- new upstream release

* Wed Apr 15 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.16.2-1
- new upstream release

* Sat Mar 28 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.16.0-1
- new upstream release
- add BuildRequires: libepoxy-devel

* Sun Mar 01 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.14.9-1
- new upstream release

* Sun Feb 01 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.14.8-1
- new upstream release

* Mon Jan 12 2015 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.14.7-1
- new upstream release

* Mon Dec 22 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.14.6-1
- new upstream release

* Sun Nov 16 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.14.5-1
- new upstream release
- add BuildRequires: gtk2-devel, rest-devel, json-glib-devel

* Sun Oct 26 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.14.4-1
- new upstream release
- update Patch100 (gtk+-3.14.0-vine-default-theme.patch)

* Wed May 14 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.12.2-1
- new upstream release

* Sun Apr 13 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.12.1-1
- new upstream release

* Sat Mar 29 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.12.0-1
- new upstream release
- update Patch100 (gtk+-3.12.0-vine-default-theme.patch)

* Sat Feb 08 2014 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.10.7-1
- new upstream release

* Sat Dec 07 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.10.6-1
- new upstream release

* Sat Nov 30 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.10.5-1
- new upstream release

* Sat Oct 26 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.10.2-1
- new upstream release
- update Patch0 (gtk3-3.10.0-gtk-widget-size-allocate.patch)
- remove Patch1 (gtk3-3.8.2-immodule.patch)

* Fri Sep 06 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.4-1
- new upstream release

* Tue Aug 13 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.2-2
- add Patch1 (gtk3-3.8.2-immodule.patch)

* Sat May 18 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.2-1
- new upstream release

* Fri Apr 26 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.8.1-1
- new upstream release

* Tue Jan 08 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.6.4-1
- new upstream release

* Fri Jan 04 2013 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.6.3-1
- new upstream release

* Sun Nov 11 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.6.2-1
- new upstream release

* Tue Oct 16 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.6.1-1
- new upstream release

* Wed Sep 26 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.6.0-1
- new upstream release
- add BuildRequires: at-spi2-atk-devel

* Mon Jul 16 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.4.4-1
- new upstream release

* Sat May 12 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.4.3-1
- new upstream release

* Sun May 06 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.4.2-1
- new upstream release

* Sun Apr 22 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.4.1-1
- new upstream release
- update Patch100 (gtk+-3.4.0-vine-default-theme.patch)

* Sun Mar 18 2012 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.2.4-1
- new upstream release

* Fri Dec 23 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.2.3-1
- new upstream release

* Wed Nov 16 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.2.2-1
- new upstream release
- remove Patch1

* Sun Oct 16 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.2.1-1
- new upstream release
- add Patch1 (gtk3-3.2.1-bug658772.patch)

* Wed Sep 28 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.2.0-1
- new upstream release

* Fri Sep 23 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.92-1
- new upstream release

* Tue Sep 06 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.18-1
- new upstream release

* Sat Sep 03 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.16-1
- new upstream release

* Tue Aug 23 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.12-1
- new upstream release
- add Patch0 (gtk3-3.1.12-gtk-widget-size-allocate.patch)

* Sun Aug 14 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.10-2
- fix %%files

* Sat Jul 30 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.1.10-1
- new upstream release
- add BuildRequires: colord-devel

* Sun Jun 26 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.11-1
- new upstream release

* Sun Apr 24 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.9-1
- new upstream release

* Sat Apr 09 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.8-1
- new upstream release

* Sun Apr 03 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.7-1
- new upstream release

* Sun Mar 27 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.6-1
- new upstream release

* Wed Mar 23 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.4-1
- new upstream release

* Sat Mar 19 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.3-1
- new upstream release

* Sun Mar 13 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.2-1
- new upstream release

* Tue Feb 22 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.1-1
- new upstream release

* Fri Feb 18 2011 Yoji TOYODA <bsyamato@sea.plala.or.jp> 3.0.0-1
- initial build for Vine Linux

