# Vala/Vapi support ( upstream disabled by default, probably explains why it the build breaks often )
%global vala 1

Name:    appstream
Version: 0.16.1
Release: 2
Summary: Utilities to generate, maintain and access the AppStream database
License: GPLv2+ and LGPLv2+
URL:     https://github.com/ximion/appstream
Source0: https://github.com/ximion/appstream/archive/refs/tags/v%{version}.tar.gz

# https://github.com/ximion/appstream/pull/546/
Patch0:  backport-fix-a-function-declaration-without-prototype-issue.patch

BuildRequires: cmake meson gettext gperf gtk-doc intltool itstool
BuildRequires: libstemmer-devel sed
BuildRequires: pkgconfig(gio-2.0) pkgconfig(gobject-introspection-1.0)
BuildRequires: pkgconfig(libsoup-2.4)
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(lmdb)
BuildRequires: pkgconfig(packagekit-glib2)
BuildRequires: protobuf-lite-devel
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: qt5-linguist
BuildRequires: pkgconfig(yaml-0.1)
BuildRequires: vala
BuildRequires: xmlto
BuildRequires: pkgconfig(cairo)
BuildRequires: pkgconfig(freetype2)
BuildRequires: pkgconfig(fontconfig)
BuildRequires: pkgconfig(gdk-pixbuf-2.0)
BuildRequires: pkgconfig(libcurl)
BuildRequires: pkgconfig(librsvg-2.0)
BuildRequires: pkgconfig(pango)
BuildRequires: pkgconfig(xmlb)
BuildRequires: systemd-devel

%description
AppStream makes it easy to access application information from the
AppStream database over a nice GObject-based interface.

%package devel
Summary:  Development files for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
Obsoletes: appstream-vala < 0.12.4-3
%description devel
Provides: appstream-vala = %{version}-%{release}
%{summary}.

%package compose
Summary: Library for generating AppStream data
Requires: %{name}%{?_isa} = %{version}-%{release}
%description compose
%{summary}.

%package compose-devel
Summary:  Development files for %{name}-compose library
Requires: %{name}-compose%{?_isa} = %{version}-%{release}
Requires: %{name}-devel%{?_isa} = %{version}-%{release}
%description compose-devel
%{summary}.

%package qt
Summary: Qt5 bindings for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
%description qt
%{summary}.

%package qt-devel
Summary:  Development files for %{name}-qt bindings
Requires: %{name}-qt%{?_isa} = %{version}-%{release}
Requires: pkgconfig(Qt5Core)
%description qt-devel
%{summary}.

%prep
%autosetup -n appstream-%{version} -p1

#sed -i -e "s|0.15.2|%{version}|" meson.build
#sed -i '/-Wno-error=deprecated-copy/ s/^/#/g' meson.build

%build
%{meson} \
 -Dcompose=true \
 -Dqt=true \
 -Dvapi=%{?vala:true}%{!?vala:false}

%{meson_build}


%install
%{meson_install}

mkdir -p %{buildroot}/var/cache/app-info/{icons,gv,xmls}
touch %{buildroot}/var/cache/app-info/cache.watch

%find_lang appstream

%if "%{?_metainfodir}" != "%{_datadir}/metainfo"
# move metainfo to right/legacy location
mkdir -p %{buildroot}%{_kf5_metainfodir}
mv %{buildroot}%{_datadir}/metainfo/*.xml \
   %{buildroot}%{_metainfodir}
%endif


%check
%{meson_test} ||:

#%ldconfig_scriptlets
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%posttrans
%{_bindir}/appstreamcli refresh --force >& /dev/null ||:

%transfiletriggerin -- %{_datadir}/app-info/xmls
%{_bindir}/appstreamcli refresh --force >& /dev/null ||:

%transfiletriggerpostun -- %{_datadir}/app-info/xmls
%{_bindir}/appstreamcli refresh --force >& /dev/null ||:

%files -f appstream.lang
%doc AUTHORS
%license COPYING
%{_bindir}/appstreamcli
%{_mandir}/man1/appstreamcli.1*
%config(noreplace) %{_sysconfdir}/appstream.conf
%dir %{_libdir}/girepository-1.0/
%{_libdir}/girepository-1.0/AppStream-1.0.typelib
%{_libdir}/libappstream.so.4*
%{_libdir}/libappstream.so.%{version}
%{_metainfodir}/org.freedesktop.appstream.cli.*.xml
# put in -devel? -- rex
%{_datadir}/gettext/its/metainfo.*
%ghost /var/cache/app-info/cache.watch
%dir /var/cache/app-info/
%dir /var/cache/app-info/icons/
%dir /var/cache/app-info/gv/
%dir /var/cache/app-info/xmls/

%files devel
%{_includedir}/appstream/
%{_libdir}/libappstream.so
%{_libdir}/pkgconfig/appstream.pc
%dir %{_datadir}/gir-1.0/
%{_datadir}/gir-1.0/AppStream-1.0.gir
%if 0%{?vala}
%dir %{_datadir}/vala
%dir %{_datadir}/vala/vapi
%{_datadir}/vala/vapi/appstream.deps
%{_datadir}/vala/vapi/appstream.vapi
%endif
%{_docdir}/appstream/html/
## symlink pointing to ^^, but need to take care, since rpm has
## trouble replacing dirs with symlinks, omit it for now -- rex
%exclude %{_datadir}/gtk-doc/html/appstream
%{_datadir}/installed-tests/appstream/metainfo-validate.test

%ldconfig_scriptlets compose

%files compose
%{_libexecdir}/appstreamcli-compose
%{_mandir}/man1/appstreamcli-compose.1*
%{_libdir}/libappstream-compose.so.0*
%{_libdir}/girepository-1.0/AppStreamCompose-1.0.typelib
%{_metainfodir}/org.freedesktop.appstream.compose.metainfo.xml

%files compose-devel
%{_includedir}/appstream-compose/
%{_libdir}/libappstream-compose.so
%{_libdir}/pkgconfig/appstream-compose.pc
%{_datadir}/gir-1.0/AppStreamCompose-1.0.gir
%{_datadir}/gtk-doc/html/appstream-compose

%ldconfig_scriptlets qt

%files qt
%{_libdir}/libAppStreamQt.so.2*
%{_libdir}/libAppStreamQt.so.%{version}

%files qt-devel
%{_includedir}/AppStreamQt/
%{_libdir}/cmake/AppStreamQt/
%{_libdir}/libAppStreamQt.so

%changelog
* Wed Dec 11 2024 jchzhou <zhoujiacheng@iscas.ac.cn> - 0.16.1-2
- Backport a patch for fixing a function declaration without prototype issue

* Mon Oct 16 2023 misaka00251 <liuxin@iscas.ac.cn> - 0.16.1-1
- Upgrade to 0.16.1

* Mon Jun 20 2022 lin zhang <lin.zhang@turbolinux.com.cn> - 0.15.2-2
- fix build error
- File listed twice libappstream-compose.so.0.15.2
- uppackaged /usr/share/gtk-doc/html/appstream-compose

* Fri Apr 15 2022 lin zhang <lin.zhang@turbolinux.com.cn> - 0.15.2-1
- Update to 0.15.2
- Add appstream.yaml

* Fri Aug 7 2020 weidong <weidong@uniontech.com> - 0.12.11-1
- Initial release for OpenEuler
