# The naming scheme in non-Mandriva-based distros
%if 0%{!?mklibname:1}
%define mklibname(ds)  lib%{1}%{?2:%{2}}%{-s:-static}%{-d:-devel}
%endif
%if 0%{!?mkrel:1}
%define mkrel(c) %{1}%{?dist}
%endif

%global oname wlroots
# Version of the .so library
%define abi_ver   0.18

# By using %%{abi_ver} even with the dev packages, it allows more than one
# version of wlroots to be installed at once, so that new versions can be
# installed without breaking old software.
%define libname   %mklibname %{name}
%define develname %mklibname %{name} -d

Name:           %{oname}%{abi_ver}
Version:        0.18.2
Release:        %mkrel 1
Summary:        A modular Wayland compositor library
Group:          System/Libraries

# Source files/overall project licensed as MIT, but
# - LGPLv2.1+
#   * protocol/idle.xml
#   * protocol/server-decoration.xml
# Those files are processed to C-compilable files by the
# `wayland-scanner` binary during build and don't alter
# the main license of the binaries linking with them by
# the underlying licenses.
License:        MIT
URL:            https://gitlab.freedesktop.org/wlroots/wlroots
Source0:        %{url}/-/releases/%{version}/downloads/%{oname}-%{version}.tar.gz
Source1:        %{url}/-/releases/%{version}/downloads/%{oname}-%{version}.tar.gz.sig
# 7BC79407090047CA: Drew DeVault <sir@cmpwn.com>
# https://drewdevault.com/publickey.txt
# 52CB6609B22DA89A: Drew DeVault (sway signing key) <sway@cmpwn.com>
# Imported from http://pgp.mit.edu/pks/lookup?op=vindex&search=0x52CB6609B22DA89A
# Source2:        gpgkey-7BC79407090047CA-52CB6609B22DA89A.gpg
# 0FDE7BE0E88F5E48: emersion <contact@emersion.fr>
Source2:        https://emersion.fr/.well-known/openpgpkey/hu/dj3498u4hyyarh35rkjfnghbjxug6b19#/gpgkey-0FDE7BE0E88F5E48.gpg


# this file is a modification of examples/meson.build so as to:
# - make it self-contained
# - only has targets for examples known to compile well (cf. "examples) global)
#Source3:        examples.meson.build

BuildRequires:  cmake
BuildRequires:  gcc
BuildRequires:  glslang
%if 0%{?gpgverify:1}
BuildRequires:  gnupg2
%endif
BuildRequires:  meson >= 0.59.0
# FIXME: wlroots require `pkgconfig(egl)`, but assumes mesa provides it
# (and uses it's extension header `<EGL/eglmesaext.h>).
# Upstream is working on not needing that: https://github.com/swaywm/wlroots/issues/1899
# Until it is fixed, pull mesa-libEGL-devel manually
# (Mageia note from @shlomif : removing for now)
# BuildRequires:  (mesa-libEGL-devel if libglvnd-devel < 1:1.3.2)
BuildRequires:  pkgconfig(egl) >= 1.5
BuildRequires:  pkgconfig(gbm) >= 17.1.0
BuildRequires:  pkgconfig(glesv2)
BuildRequires:  pkgconfig(hwdata)
BuildRequires:  pkgconfig(lcms2)
BuildRequires:  pkgconfig(libdrm) >= 2.4.122
BuildRequires:  pkgconfig(libdisplay-info)
BuildRequires:  pkgconfig(libinput) >= 1.21.0
BuildRequires:  pkgconfig(libliftoff) >= 0.4.0
BuildRequires:  pkgconfig(libseat) >= 0.2.0
BuildRequires:  pkgconfig(libudev)
BuildRequires:  pkgconfig(pixman-1) >= 0.42.0
BuildRequires:  pkgconfig(vulkan) >= 1.2.182
BuildRequires:  pkgconfig(wayland-client)
BuildRequires:  pkgconfig(wayland-protocols) >= 1.35
BuildRequires:  pkgconfig(wayland-scanner)
BuildRequires:  pkgconfig(wayland-server) >= 1.23
BuildRequires:  pkgconfig(x11-xcb)
BuildRequires:  pkgconfig(xcb)
BuildRequires:  pkgconfig(xcb-errors)
BuildRequires:  pkgconfig(xcb-icccm)
BuildRequires:  pkgconfig(xcb-renderutil)
BuildRequires:  pkgconfig(xkbcommon)
BuildRequires:  pkgconfig(xwayland)

%description
A modular Wayland compositor library.


%package -n     %{libname}
Summary:        A modular Wayland compositor library
Group:          System/Libraries

Obsoletes:      wlroots < 0.12.0-3
Provides:       %{name} = %{version}-%{release}
Obsoletes:      %{oname} < %{version}-%{release}

%description -n %{libname}
A modular Wayland compositor library.


%package -n     %{develname}
Summary:        Development files for %{name}
Group:          Development/X11
Requires:       %{libname} = %{version}-%{release}
# FIXME: See the rationale above for this require; remove when no longer needed
# (Mageia note from @shlomif : removing for now)
# Requires:       (mesa-libEGL-devel if libglvnd-devel < 1:1.3.2)
# not required per se, so not picked up automatically by RPM
Recommends:     pkgconfig(xcb-icccm)
# for examples
Suggests:       gcc
Suggests:       meson >= 0.58.0
Suggests:       pkgconfig(libpng)
Suggests:       pkgconfig(libavutil)
Suggests:       pkgconfig(libavcodec)
Suggests:       pkgconfig(libavformat)
Suggests:       pkgconfig(wayland-egl)

Obsoletes:      wlroots-devel < 0.12.0-3
Provides:       %{name}-devel = %{version}-%{release}

%description -n %{develname}
Development files for %{name}.


%prep
%if 0%{?gpgverify:1}
%{gpgverify} --keyring='%{SOURCE2}' --signature='%{SOURCE1}' --data='%{SOURCE0}'
%endif
%autosetup -p1 -n %{oname}-%{version}


%build
%meson
%meson_build


%install
%meson_install

%check
%meson_test


%files -n %{libname}
%license LICENSE
%doc README.md
%{_libdir}/lib%{oname}-%{abi_ver}.so

%files -n %{develname}
%{_includedir}/%{oname}-%{abi_ver}
%{_libdir}/pkgconfig/%{oname}-%{abi_ver}.pc