%global libmodulemd_version @VERSION@

%if ( 0%{?fedora} && 0%{?fedora} <= 30 ) || ( 0%{?rhel} && 0%{?rhel} <= 7)
%global build_python2 1
%else
%global build_python2 0
%endif

Name:           libmodulemd1
Version:        %{libmodulemd_version}
Release:        0%{?dist}.@DATETIME@
Summary:        Module metadata manipulation library

License:        MIT
URL:            https://github.com/fedora-modularity/libmodulemd
Source0:        %{url}/releases/download/libmodulemd-%{version}/modulemd-%{version}.tar.xz

BuildRequires:  meson >= 0.47
BuildRequires:  pkgconfig
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  pkgconfig(gobject-2.0)
BuildRequires:  pkgconfig(gobject-introspection-1.0)
BuildRequires:  pkgconfig(yaml-0.1)
BuildRequires:  pkgconfig(gtk-doc)
%if %{build_python2}
BuildRequires:  python2-devel
BuildRequires:  python-gobject-base
%endif
BuildRequires:  python3-devel
BuildRequires:  python3-gobject-base
BuildRequires:  python3-babel
BuildRequires:  python2-babel
BuildRequires:  valgrind
BuildRequires:  glib2-doc


# Patches


%description
C Library for manipulating module metadata files.
See https://github.com/fedora-modularity/libmodulemd/blob/master/README.md for
more details.


%if %{build_python2}
%package -n python2-%{name}
Summary: Python 2 bindings for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: python-gobject-base
Requires: python-six
Obsoletes: python2-modulemd < 1.3.4

%description -n python2-%{name}
Python 2 bindings for %{name}
%endif


%package -n python3-%{name}
Summary: Python 3 bindings for %{name}
Requires: %{name}%{?_isa} = %{version}-%{release}
Requires: python3-gobject-base
Requires: %{py3_dist six}
Obsoletes: python3-modulemd < 1.3.4

%description -n python3-%{name}
Python 3 bindings for %{name}


%package devel
Summary:        Development files for libmodulemd
Requires:       %{name}%{?_isa} = %{version}-%{release}
Conflicts:      libmodulemd-devel


%description devel
Development files for libmodulemd.


%prep
%autosetup -p1 -n modulemd-%{libmodulemd_version}


%build
%meson -Ddeveloper_build=false

%if 0%{?rhel} && 0%{?rhel} <= 7
# ALERT!!! PURE HACK FOR EPEL!
# https://bugzilla.redhat.com/show_bug.cgi?id=1546757
sed -r -i -e "/g-ir-scanner/s/-l(gobject-2.0|glib-2.0|yaml)//g" %{_vpath_builddir}/build.ninja
%endif

%meson_build

%check

export LC_CTYPE=C.utf8

%ifarch %{power64}
# Valgrind is broken on ppc64[le] with GCC7:
# https://bugs.kde.org/show_bug.cgi?id=386945
export MMD_SKIP_VALGRIND=1
%endif

%meson_test


%install
%meson_install


%files
%license COPYING
%doc README.md
%{_bindir}/modulemd-validator-v1
%{_libdir}/libmodulemd.so.1*
%dir %{_libdir}/girepository-1.0
%{_libdir}/girepository-1.0/Modulemd-1.0.typelib


%files devel
%{_libdir}/libmodulemd.so
%{_libdir}/pkgconfig/modulemd.pc
%{_includedir}/modulemd/
%dir %{_datadir}/gir-1.0
%{_datadir}/gir-1.0/Modulemd-1.0.gir
%dir %{_datadir}/gtk-doc
%dir %{_datadir}/gtk-doc/html
%{_datadir}/gtk-doc/html/modulemd-1.0/


%files -n python3-libmodulemd1


%if %{build_python2}
%files -n python2-libmodulemd1
%endif


%changelog
