%global git_date  20250302
%global git_hash  186f3a3
## Version is from latest tags from github
%global git_ver  3.16.1

%global rel  4
%global src_name  %{name}-%{git_date}-%{git_hash}.tar.xz

Name:       gamescope
Version:    %{git_ver}^%{git_date}g%{git_hash}
Release:    %{rel}%{?dist}
Source:     %{url}/%{src_name}
Summary:        Micro-compositor for video games on Wayland

License:        BSD
URL:        https://github.com/ValveSoftware/gamescope
# Create stb.pc to satisfy dependency('stb')
Source1:        stb.pc
#Source2:        https://github.com/Joshua-Ashton/reshade/archive/%{reshade_commit}/reshade-%{reshade_shortcommit}.tar.gz

#Patch:          0001-cstdint.patch
# Allow to use system wlroots
# We use/package rest from the forks, I've tried to verify that wlroots match relevant commits
# We'll hold on rebases of gamescope if tags diverge in the future
#Patch:          Allow-to-use-system-wlroots.patch
#Patch:          Switch-wlroots-to-the-new-pc-filename.patch
#Patch:          Add-pixman-dependency.patch

BuildRequires:  meson >= 0.54.0
BuildRequires:  ninja-build
BuildRequires:  cmake git
BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  glm-devel
BuildRequires:  google-benchmark-devel
BuildRequires:  libXmu-devel
BuildRequires:  libXcursor-devel
#BuildRequires:  pkgconfig(libdisplay-info)
BuildRequires:  pkgconfig(x11)
BuildRequires:  pkgconfig(xdamage)
BuildRequires:  pkgconfig(xcomposite)
BuildRequires:  pkgconfig(xrender)
BuildRequires:  pkgconfig(xext)
BuildRequires:  pkgconfig(xfixes)
BuildRequires:  pkgconfig(xxf86vm)
BuildRequires:  pkgconfig(xtst)
BuildRequires:  pkgconfig(xres)
BuildRequires:  pkgconfig(libdrm)
BuildRequires:  pkgconfig(vulkan)
BuildRequires:  pkgconfig(wayland-scanner)
BuildRequires:  pkgconfig(wayland-server)
BuildRequires:  pkgconfig(wayland-protocols) >= 1.17
BuildRequires:  pkgconfig(xkbcommon)
BuildRequires:  pkgconfig(sdl2)
BuildRequires:  pkgconfig(libpipewire-0.3)
BuildRequires:  pkgconfig(libavif)
#BuildRequires:  pkgconfig(wlroots-0.18)
#BuildRequires:  pkgconfig(libliftoff) < 0.6
BuildRequires:  pkgconfig(libcap)
BuildRequires:  pkgconfig(libeis-1.0)
BuildRequires:  pkgconfig(libdecor-0)
BuildRequires:  pkgconfig(hwdata)
BuildRequires:  spirv-headers-devel
# Enforce the the minimum EVR to contain fixes for all of:
# CVE-2021-28021 CVE-2021-42715 CVE-2021-42716 CVE-2022-28041 CVE-2023-43898
# CVE-2023-45661 CVE-2023-45662 CVE-2023-45663 CVE-2023-45664 CVE-2023-45666
# CVE-2023-45667
BuildRequires:  stb_image-devel >= 2.28^20231011gitbeebb24-12
# Header-only library: -static is for tracking per guidelines
BuildRequires:  stb_image-static
BuildRequires:  stb_image_resize-devel
BuildRequires:  stb_image_resize-static
BuildRequires:  stb_image_write-devel
BuildRequires:  stb_image_write-static
#BuildRequires:  vkroots-devel
BuildRequires:  /usr/bin/glslangValidator
# wlroots
BuildRequires:  pkgconfig(pixman-1)
BuildRequires:  pkgconfig(lcms2)
BuildRequires:  pkgconfig(libudev)
BuildRequires:  pkgconfig(libseat)
BuildRequires:  pkgconfig(libinput)
BuildRequires:  pkgconfig(xwayland)
BuildRequires:  pkgconfig(xcb-ewmh)
BuildRequires:  pkgconfig(xcb-errors)
BuildRequires:  pkgconfig(luajit)

# libliftoff hasn't bumped soname, but API/ABI has changed for 0.2.0 release
#Requires:       libliftoff%{?_isa}
Requires:       xorg-x11-server-Xwayland
Recommends:     mesa-dri-drivers
Recommends:     mesa-vulkan-drivers

%description
%{name} is the micro-compositor optimized for running video games on Wayland.

%prep
##%%autosetup -p1 -a2 -N
%autosetup -n %{name} -p1
# Install stub pkgconfig file
mkdir -p pkgconfig
cp %{SOURCE1} pkgconfig/stb.pc

# Replace spirv-headers include with the system directory
sed -i 's^../thirdparty/SPIRV-Headers/include/spirv/^/usr/include/spirv/^' src/meson.build

# Push in reshade from sources instead of submodule
#rm -rf src/reshade && mv reshade-%{reshade_commit} src/reshade

%autopatch -p1

%build
export PKG_CONFIG_PATH=pkgconfig
%meson -Dpipewire=enabled -Denable_openvr_support=false -Ddrm_backend=enabled \
# -Dforce_fallback_for=[]

%meson_build

%install
%meson_install --skip-subprojects

%files
%license LICENSE
%doc README.md
%{_bindir}/gamescope
%{_bindir}/gamescopectl
%{_bindir}/gamescopereaper
%{_bindir}/gamescopestream
%{_libdir}/libVkLayer_FROG_gamescope_wsi_*.so
%{_datadir}/vulkan/implicit_layer.d/VkLayer_FROG_gamescope_wsi.*.json
%{_datadir}/%{name}/scripts/*

%changelog
%autochangelog