# 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

%define pname RetroArch

Summary:   libretro is an API that exposes generic audio/video/input callbacks.
Name:      retroarch
Version:   1.20.0
Release:   %mkrel 1
License:   GPLv3+
Group:     Emulators          
URL:       https://www.libretro.org/
Source0:   https://github.com/libretro/RetroArch/archive/v%{version}/%{pname}-%{version}.tar.gz 
Patch0:    retroarch-mbedtlsv3-support.diff
Patch1:    retroarch-newer-glslang.diff
# RetroArch's included SPEC file for Sailfish OS uses v%%{version} for %%{release}, so provide that as well.
Provides:  %{name} = %{version}-v%{version}

# Build requirements
# Support for reading zipped ROMs
BuildRequires: pkgconfig(zlib)
# Input support
BuildRequires: pkgconfig(libudev)
# Truetype font support
BuildRequires: pkgconfig(freetype2)
BuildRequires: pkgconfig(fontconfig)
# Audio support
BuildRequires: pkgconfig(alsa)
BuildRequires: pkgconfig(jack) >= 0.120.1
%if "%{_target_cpu}" != "i686"
# "Checking function alcOpenDevice in -lopenal ... no" in i686, so users of
# such architectures will just have to deal with no OpenAL support (there are
# faster audio drivers anyway).
BuildRequires: pkgconfig(openal)
%endif
BuildRequires: pkgconfig(libpulse)
BuildRequires: pkgconfig(libpipewire-0.3)
# SDL support
# We could use SDL1 instead of SDL2, but these days, distros use sdl12-compat for SDL1 (that is,
# still use SDL2 behind-the-scenes).
BuildRequires: pkgconfig(sdl2) >= 2.0.0
# USB support
BuildRequires: pkgconfig(libusb-1.0) >= 1.0.13
# Camera support
BuildRequires: pkgconfig(libv4l2)
# Recording support
BuildRequires: pkgconfig(libavcodec) >= 57
BuildRequires: pkgconfig(libavformat) >= 57
BuildRequires: pkgconfig(libavdevice) >= 57
BuildRequires: pkgconfig(libswresample) >= 2
BuildRequires: pkgconfig(libavutil) >= 55
BuildRequires: pkgconfig(libswscale) >= 4
# FLAC support
BuildRequires: pkgconfig(flac)
# X support
BuildRequires: pkgconfig(x11)
BuildRequires: pkgconfig(xext)
BuildRequires: pkgconfig(xinerama)
BuildRequires: pkgconfig(xscrnsaver)
BuildRequires: pkgconfig(xcb)
BuildRequires: pkgconfig(xv)
BuildRequires: pkgconfig(xxf86vm)
BuildRequires: pkgconfig(xproto)
# Wayland support
BuildRequires: pkgconfig(xkbcommon) >= 0.3.2
BuildRequires: pkgconfig(wayland-egl) >= 10.1.0
BuildRequires: pkgconfig(wayland-cursor) >= 1.12
BuildRequires: pkgconfig(wayland-protocols) >= 1.31
BuildRequires: pkgconfig(wayland-scanner) >= 1.15
BuildRequires: pkgconfig(libdecor-0)
# DRM/KMS support
BuildRequires: pkgconfig(libdrm)
BuildRequires: pkgconfig(gbm) >= 9.0
BuildRequires: pkgconfig(egl)
# SSL support
BuildRequires: ((pkgconfig(mbedtls) >= 2.5.1 and pkgconfig(mbedx509) >= 2.5.1 and pkgconfig(mbedcrypto) >= 2.5.1) or mbedtls-devel)
# glslang support
# Use RedHat's unofficial glslang.pc if the distro has it; use the official cmake build files otherwise.
BuildRequires: ((pkgconfig(glslang)) or (cmake(glslang)) or glslang-devel)
BuildRequires: pkgconfig(SPIRV-Tools)
# OpenGL support
BuildRequires: pkgconfig(egl)
BuildRequires: pkgconfig(gl)
# Vulkan support
BuildRequires: pkgconfig(vulkan)
# Qt support
BuildRequires: pkgconfig(Qt6Concurrent) >= 6.2
BuildRequires: pkgconfig(Qt6Core) >= 6.2
BuildRequires: pkgconfig(Qt6Gui) >= 6.2
BuildRequires: pkgconfig(Qt6Network) >= 6.2
BuildRequires: pkgconfig(Qt6Widgets) >= 6.2

Recommends: espeak
Recommends: gamemode
Recommends: libdecor

%description
libretro is an API that exposes generic audio/video/input callbacks.
A frontend for libretro (such as RetroArch) handles video output, audio output, input and application lifecycle.
A libretro core written in portable C or C++ can run seamlessly on many platforms with very little to no porting effort.

While RetroArch is the reference frontend for libretro, several other projects have used the libretro interface to
include support for emulators and/or game engines. libretro is completely open and free for anyone to use.

This package includes only the frontend. Assets, shaders, emulator cores,
content (e.g.public-domain games), etc. can be downloaded (and updated) from
the frontend.

%package -n %{name}-cg2glsl
Summary: Tool to covert Cg shaders to the glsl format
License: Public Domain
Requires: /usr/bin/env
Requires: python3 >= 3.0.0
# Sorry, the Cg package can't be provided, since it's non-free.
Requires: Cg

%description -n %{name}-cg2glsl
%{summary}. You probably don't need this, considering that there are few shaders written in Cg (NVIDIA's outdated shading language) that haven't been converted to glsl (the shading language used by OpenGL 2.x/OpenGLES 3+) and that most have moved on to glslang (the shading language used by OpenGL 3+ and by Vulkan).

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

%build
export CFLAGS=-g
# Enable necessary features, disable builtin libraries (use newer, more secure system libraries when possible).
# ./configure has to be used directly since RetroArch's homegrown configure scripts chokes on unknown options sent to it.
./configure --build=%{_target_vendor}-%{_target_cpu}-%{_target_os} --prefix=%{_prefix} --bindir=%{_bindir} --datarootdir=%{_datarootdir} --docdir=%{_docdir} --mandir=%{_mandir} --sysconfdir=%{_sysconfdir} \
	--enable-egl --enable-wayland --enable-kms \
	--enable-hid \
%if "%{_target_cpu}" != "i686"
	--enable-al \
%endif
	--enable-opengl_core --enable-vulkan \
	--enable-freetype --disable-stb_font \
	--disable-builtinflac \
	--enable-glslang --disable-builtinglslang \
	--enable-systemmbedtls --disable-builtinmbedtls --disable-builtinbearssl \
	--disable-builtinzlib
%make_build

%install
%make_install

%files
%doc README*.md CONTRIBUTING.md CHANGES.md
%license COPYING
%config /etc/retroarch.cfg
%{_bindir}/retroarch
%{_mandir}/man6/%{name}.6*
%{_datarootdir}/metainfo/com.libretro.RetroArch.metainfo.xml
%{_datarootdir}/applications/com.libretro.RetroArch.desktop
%{_datarootdir}/pixmaps/com.libretro.RetroArch.svg
%exclude %{_docdir}

%files -n %{name}-cg2glsl
%{_bindir}/retroarch-cg2glsl
%{_mandir}/man6/%{name}-cg2glsl.6*