%global _syslibdir %{_libdir}
%global _prefix /opt/rx

Summary: Utilities to generate, maintain and access the AppStream database
Name:    rx-appstream
Version: 1.0.2
Release: 2%{?dist}

# lib LGPLv2+, tools GPLv2+
License: GPL-2.0-or-later AND LGPL-2.1-or-later
#URL:     http://www.freedesktop.org/wiki/Distributions/AppStream
URL:     https://github.com/ximion/appstream
Source0: http://www.freedesktop.org/software/appstream/releases/AppStream-%{version}.tar.xz

# upstream patches
# https://github.com/PackageKit/PackageKit/issues/720
Patch0:  utils-explicitly-set-format-style-when-installing-catalog-metadata.patch


# upstreamable patches


# needed for cmake auto-provides
BuildRequires: cmake
BuildRequires: meson >= 0.62
BuildRequires: gettext
BuildRequires: git-core
BuildRequires: gperf
BuildRequires: intltool
BuildRequires: itstool
BuildRequires: libstemmer-devel
BuildRequires: pkgconfig(cairo)
BuildRequires: pkgconfig(freetype2)
BuildRequires: pkgconfig(fontconfig)
BuildRequires: pkgconfig(gdk-pixbuf-2.0)
#BuildRequires: pkgconfig(gi-docgen) >= 2021.1
BuildRequires: rx-glib2-devel >= 2.62
BuildRequires: pkgconfig(libcurl)
BuildRequires: pkgconfig(librsvg-2.0) >= 2.48
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(libzstd)
BuildRequires: pkgconfig(pango)
BuildRequires: pkgconfig(Qt5Core) >= 5.15
BuildRequires: pkgconfig(Qt6Core) >= 6.2.4
BuildRequires: pkgconfig(xmlb) >= 0.3.14
BuildRequires: pkgconfig(yaml-0.1)
# lrelease
BuildRequires: qt6-linguist
BuildRequires: sed
BuildRequires: xmlto

Requires: appstream-data
Requires: rx-libxmlb
Requires: rx-glib2
Requires: rx-librsvg2

%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}
# -vala subpackage removed in F30
Obsoletes: appstream-vala < 0.12.4-3
Provides: appstream-vala = %{version}-%{release}
Provides: appstream-devel  = %{version}-%{release}
Conflicts: appstream-devel

%description devel
%{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}
Provides: appstream-compose-devel  = %{version}-%{release}
Conflicts: appstream-compose-devel

%description compose-devel
%{summary}.

%package qt
Summary: Qt6 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(Qt6Core) >= 6.2.4
Provides: cmake(AppStreamQt)  = %{version}-%{release}
Conflicts: appstream-qt-devel

%description qt-devel
%{summary}.

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

%package qt5-devel
Summary:  Development files for %{name}-qt bindings
Requires: %{name}-qt5%{?_isa} = %{version}-%{release}
Requires: pkgconfig(Qt5Core) >= 5.15
Provides: cmake(AppStreamQt5)  = %{version}-%{release}
Provides: appstream-qt-devel  = %{version}-%{release}
Conflicts: appstream-qt-devel

%description qt5-devel
%{summary}.


%prep
%autosetup -n AppStream-%{version} -S git_am


%build
export LDFLAGS="-L%{_prefix}/%{_lib} -Wl,-rpath=%{_prefix}/%{_lib} -lrsvg-2 -L%{_prefix}/glib2/%{_lib} -Wl,-rpath=%{_prefix}/glib2/%{_lib} ${LDFLAGS}"
export PKG_CONFIG_PATH=%{_prefix}/%{_lib}/pkgconfig:%{_prefix}/glib2/%{_lib}/pkgconfig${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}

sed -i "s/'libcurl', version: '>= 7.62'/'libcurl'/" meson.build


%{meson} \
 -Dcompose=true \
 -Dqt=true \
 -Dqt-versions=5,6 \
 -Dvapi=true \
 -Dsystemd=false \
 -Dgir=false \
 -Dapidocs=false


%{meson_build}


%install
%{meson_install}

mkdir -p %{buildroot}/var/cache/swcatalog/{icons,gv,xml}
touch %{buildroot}/var/cache/swcatalog/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

mkdir -p %{buildroot}%{_syslibdir}/cmake
ln -sf %{_libdir}/cmake/AppStreamQt %{buildroot}%{_syslibdir}/cmake/AppStreamQt
ln -sf %{_libdir}/cmake/AppStreamQt5 %{buildroot}%{_syslibdir}/cmake/AppStreamQt5

%check
%{meson_test} ||:


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

%transfiletriggerin -- %{_datadir}/swcatalog/xml
%{_bindir}/appstreamcli refresh --force >& /dev/null ||:

%transfiletriggerpostun -- %{_datadir}/swcatalog/xml
%{_bindir}/appstreamcli refresh --force >& /dev/null ||:

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

%files devel
%{_includedir}/appstream/
%{_libdir}/libappstream.so
%{_libdir}/pkgconfig/appstream.pc
#dir %{_datadir}/gir-1.0/
#{_datadir}/gir-1.0/AppStream-1.0.gir
#dir %{_datadir}/vala
#dir %{_datadir}/vala/vapi
#{_datadir}/vala/vapi/appstream.deps
#{_datadir}/vala/vapi/appstream.vapi
%{_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
# Maybe this should be split out? -- ngompa
%{_datadir}/installed-tests/appstream/metainfo-validate.test

%files compose
%{_libexecdir}/appstreamcli-compose
%{_mandir}/man1/appstreamcli-compose.1*
%{_libdir}/libappstream-compose.so.0
%{_libdir}/libappstream-compose.so.%{version}
#{_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
#dir %{_datadir}/gtk-doc/
#dir %{_datadir}/gtk-doc/html/
#{_datadir}/gtk-doc/html/appstream-compose

%files qt
%{_libdir}/libAppStreamQt.so.3
%{_libdir}/libAppStreamQt.so.%{version}

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

%files qt5
%{_libdir}/libAppStreamQt5.so.3
%{_libdir}/libAppStreamQt5.so.%{version}

%files qt5-devel
%{_includedir}/AppStreamQt5/
%{_syslibdir}/cmake/AppStreamQt5
%{_libdir}/cmake/AppStreamQt5/
%{_libdir}/libAppStreamQt5.so

