File rpcs3.spec of Package rpcs3

#
# spec file for package rpcs3
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define projectname rpcs3
%global flavor @BUILD_FLAVOR@%nil
%define v3 0
%define z3 0
%if "%flavor" == "v3"
%define v3 1
%endif
%if "%flavor" == "z3"
%define z3 1
%endif

# clang crashes during compilation
%global use_clang 1
%global use_lld 1
# LTO is permanently broken here
%global use_lto 0

Version:        0.0.32~git20240530
Release:        0
%if "%{flavor}" != ""
Name:           rpcs3%{?flavor:-}%{?flavor}
Provides:       rpcs3 = %{version}-%{release}
%else
Name:           rpcs3
%endif

Summary:        PS3 emulator/debugger
License:        GPL-2.0-only
URL:            https://rpcs3.net
Source0:        %{projectname}-%{version}.tar.xz
Source1:        intel-ittapi.tar.xz
Patch1:         fix-test-files.patch
Patch2:         fix-toolbar-color.patch
Patch100:       rpcs3-PR15473.patch
BuildRequires:  memory-constraints

BuildRequires:  llvm-devel
%if 0%{?use_clang}
BuildRequires:  clang-devel
#BuildRequires: npth-devel
%if 0%{?use_lld}
BuildRequires:  lld
%else
BuildRequires:  binutils-gold
BuildRequires:  llvm-gold
%endif
%else
BuildRequires:  binutils-gold
BuildRequires:  gcc-c++ >= 9
%endif

BuildRequires:  ccache
BuildRequires:  cereal-devel
BuildRequires:  gdb
#BuildRequires:  git
BuildRequires:  cmake(Z3)
BuildRequires:  cmake(x86-64) >= 3.14.1
BuildRequires:  pkgconfig(hidapi-hidraw)
BuildRequires:  pkgconfig(hidapi-libusb)
BuildRequires:  pkgconfig(libcurl)
BuildRequires:  pkgconfig(libedit)
BuildRequires:  pkgconfig(libevdev)
BuildRequires:  pkgconfig(libpng)
BuildRequires:  pkgconfig(libudev)
BuildRequires:  pkgconfig(libusb-1.0)
BuildRequires:  pkgconfig(pugixml)
BuildRequires:  pkgconfig(x11)
BuildRequires:  pkgconfig(yaml-cpp)
BuildRequires:  pkgconfig(zlib)
#BuildRequires:  ocaml-ocamlbuild-devel
BuildRequires:  python3-Pygments
BuildRequires:  -post-build-checks
BuildRequires:  python3-PyYAML
BuildRequires:  python3-ruamel.yaml.clib
BuildRequires:  stb-devel
BuildRequires:  xxhash-devel

#graphics backend dependencies:
#-------------------------------------------------
#opengl:
BuildRequires:  pkgconfig(gl)
BuildRequires:  pkgconfig(glew) >= 1.13.0
BuildRequires:  pkgconfig(glu)
BuildRequires:  pkgconfig(libglvnd)
BuildRequires:  pkgconfig(sdl2)

#vulkan:
BuildRequires:  pkgconfig(vulkan) >= 1.1.126
BuildRequires:  glslang-devel
BuildRequires:  shaderc-devel
BuildRequires:  spirv-tools-devel
#BuildRequires:  Mesa-libVulkan-devel
#BuildRequires:  -post-build-checks
#-------------------------------------------------

#audio backend dependencies:
#-------------------------------------------------
##alsa:
BuildRequires:  pkgconfig(alsa)

##pulseaudio:
BuildRequires:  pkgconfig(libpulse)
BuildRequires:  pkgconfig(libpulse-mainloop-glib)
BuildRequires:  pkgconfig(libpulse-simple)

##openal:
BuildRequires:  pkgconfig(openal)

##jack:
BuildRequires:  pkgconfig(jack)
#-------------------------------------------------

#ffmpeg dependencies
BuildRequires:  pkgconfig(libavcodec) < 61.0.0
BuildRequires:  pkgconfig(libavformat) < 61.0.0
BuildRequires:  pkgconfig(libavutil) < 59.0.0
BuildRequires:  pkgconfig(libswscale) < 8.1.0

#qt dependencies
BuildRequires:  qt6-base-private-devel
BuildRequires:  qt6-gui-private-devel
BuildRequires:  cmake(Qt6LinguistTools)
BuildRequires:  pkgconfig(Qt6Concurrent)
BuildRequires:  pkgconfig(Qt6Core)
BuildRequires:  pkgconfig(Qt6DBus)
BuildRequires:  pkgconfig(Qt6Multimedia)
BuildRequires:  pkgconfig(Qt6MultimediaWidgets)
BuildRequires:  pkgconfig(Qt6Network)
BuildRequires:  pkgconfig(Qt6OpenGL)
BuildRequires:  pkgconfig(Qt6Qml)
BuildRequires:  pkgconfig(Qt6Svg)
BuildRequires:  pkgconfig(Qt6Widgets)

ExclusiveArch:  x86_64

Requires(post): hicolor-icon-theme
Requires(post): update-desktop-files
Requires(postun): hicolor-icon-theme
Requires(postun): update-desktop-files

# Xbox One/Series controller wireless driver
Recommends:     xpadneo

#v3 handling
%if 0%{?v3:1}
Conflicts:      rpcs3
%endif
%if 0%{?z3:1}
Conflicts:      rpcs3
%endif

%description
An open-source PlayStation 3 emulator/debugger written in C++.

%prep
%autosetup -p1 -a 1 -n %{projectname}-%version

#sed -i -e 's:-fexceptions:-fno-exceptions:g' rpcs3/Emu/CMakeLists.txt
# no one asked for your opinion
sed -i -e 's:NOT FOUND_LTO EQUAL -1:FOUND_LTO EQUAL 666:' CMakeLists.txt

#Generate Version Strings
#GIT_VERSION=$(echo %{version} | sed 's|.*git|~git|g')
GIT_VERSION=$(echo %{version})

echo "// This is a generated file.

#define RPCS3_GIT_VERSION \"$GIT_VERSION\"
#define RPCS3_GIT_BRANCH \"master\"
#define RPCS3_GIT_FULL_BRANCH \"RPCS3/rpcs3/master\"

// If you don't want this file to update/recompile, change to 1.

#define RPCS3_GIT_VERSION_NO_UPDATE 1
" > %{projectname}/git-version.h

rm -v CMakeCache.txt || echo "no trash to remove for cmake not to complain about"

%build
# this macro needs 'BuildRequires: memory-constraints'
%limit_build -m 2047
ulimit -Sn 4000
#export UCFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -fno-strict-aliasing"
export UCFLAGS="${UCFLAGS} -w -fPIC -O3 -I%{_includedir}/wayland"
%if %{v3}
export UCFLAGS="${UCFLAGS} -march=x86-64-v3 -mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
%endif
%if %{z3}
export UCFLAGS="${UCFLAGS} -march=znver3 -mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
%endif
%ifarch x86_64 %ix86
#export UCFLAGS="${UCFLAGS} -march=x86-64 -mtune=generic -mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
%endif
#export ULDFLAGS="-fPIC -Wl,--gc-sections -Wl,-O1 -Wl,--icf=safe"
%if !0%{?use_lld}
export ULDFLAGS="${ULDFLAGS} -fuse-ld=gold -Wl,--sort-common -Wl,-O1"
export LD=ld.gold
alias ld=gold
%endif
%if 0%{?use_clang}
export CC=clang
export CXX=clang++
export UCFLAGS="${UCFLAGS} -v -fbracket-depth=1024 -fconstexpr-depth=1024"
%ifarch x86_64
#export UCFLAGS="${UCFLAGS} -fglobal-isel"
%endif
#export UCFLAGS="${UCFLAGS} -D_GNU_SOURCE -fexceptions -faligned-allocation"
export UCXXFLAGS="${UCFLAGS}"
#export UCXXFLAGS="${UCXXFLAGS} -fcxx-exceptions"
export HOST="$(${CC} -print-target-triple)"
%if 0%{?use_lld}
export UCFLAGS="${UCFLAGS} -fuse-ld=lld"
export ULDFLAGS="${ULDFLAGS} -fuse-ld=lld"
export LD="lld"
alias ld=ld.lld
%endif
%if 0%{?use_lto}
%if 0%{?use_lld}
%global _lto_cflags -flto=thin
%global _lto_ldlags -flto=thin -Wl,--plugin-opt=O3 %{?jobs:-Wl,--threads=%{jobs}}
%else
%global _lto_cflags -flto=thin
%global _lto_ldlags -flto=thin
%endif
%else
%global _lto_cflags %nil
%global _lto_ldlags %nil
%endif
%else
export CC=gcc
export CXX=g++
export UCFLAGS="${UCFLAGS} -ftree-parallelize-loops=4 -ftree-vectorize -fpredictive-commoning"
export UCXXFLAGS="${UCFLAGS}"
export HOST="%{_target_platform}"
%if 0%{?use_lto}
%global _lto_cflags -fuse-linker-plugin %_lto_cflags -ffat-lto-objects -flto-odr-type-merging
%global _lto_ldlags -fuse-linker-plugin -flto=2
%else
%global _lto_cflags %nil
%global _lto_ldlags %nil
%endif
%endif
export TARGET="${HOST}"
export UCFLAGS="${UCFLAGS} %_lto_cflags"
export UCXXFLAGS="${UCXXFLAGS} %_lto_cflags"
export ULDFLAGS="${ULDFLAGS} %_lto_cflags %_lto_ldlags"
# override OBS defaults ?
export CFLAGS="${UCFLAGS}"
export CXXFLAGS="${UCXXFLAGS}"
export LDFLAGS="${ULDFLAGS}"

## llvm intel-ittapi workarounds

# Work around git revision issues
sed -i -e 's:FATAL_ERROR:WARNING:g' 3rdparty/llvm/llvm/llvm/lib/ExecutionEngine/IntelJITEvents/CMakeLists.txt || echo "probably no LLVM source for static linking is present"

# Fix paths
mv intel-ittapi ittapi && mkdir intel-ittapi && mv ittapi intel-ittapi/
export ITTAPI_DIR="$(pwd)/intel-ittapi"

mkdir ../%{projectname}_build
cd ../%{projectname}_build
# BUILD_RUST_LIBS=ON ? -DENABLE_EXCEPTIONS=ON ?
# use BUILD_LLVM=ON when system one is not supported
# FIXME: you should use the %%cmake macros
%__cmake ../%{projectname}-%{version} \
        -DITTAPI_SOURCE_DIR="${ITTAPI_DIR}" \
        -DUSE_PCH=OFF \
        -DENABLE_PCH=OFF \
        -DSKIP_PRECOMPILE_HEADERS=ON \
        -DUSE_PRECOMPILED_HEADERS=OFF \
        -DUSE_SYSTEM_CURL=ON \
        -DUSE_SYSTEM_FFMPEG=ON \
        -DUSE_SYSTEM_LIBPNG=ON \
        -DUSE_SYSTEM_LIBUSB=ON \
        -DUSE_SYSTEM_SDL=ON \
        -DUSE_SDL=ON \
        -DUSE_SYSTEM_ZLIB=ON \
        -DUSE_NATIVE_INSTRUCTIONS=OFF \
        -DOpenGL_GL_PREFERENCE="GLVND" \
	-DCMAKE_C_COMPILER="${CC}" \
	-DCMAKE_CXX_COMPILER="${CXX}" \
	-DCMAKE_LINKER="${LD}" \
	-DCMAKE_C_FLAGS="${CFLAGS}" \
	-DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
        -DCMAKE_EXE_LINKER_FLAGS="${CFLAGS} ${LDFLAGS}" \
        -DCMAKE_MODULE_LINKER_FLAGS="${LDFLAGS}" \
        -DCMAKE_SHARED_LINKER_FLAGS="${LDFLAGS}" \
        -DCMAKE_INSTALL_PREFIX="%{_prefix}" \
        -DCMAKE_INSTALL_LIBEXEC="%{_libexecdir}" \
        -DCMAKE_BUILD_TYPE="RelWithDebInfo" \
        -DUSE_CCACHE=ON \
        -DCMAKE_SKIP_RPATH="YES" \
        -DSPIRV_WERROR=OFF \
        -DBUILD_TESTS=OFF

%make_jobs

%install
cd ../%{projectname}_build
%make_install

%post
%desktop_database_post
%icon_theme_cache_post

%postun
%desktop_database_postun
%icon_theme_cache_postun

%files
%doc README.md
%license LICENSE

%attr(755, root, root) %{_bindir}/%{projectname}*
%{_datadir}/applications/*.desktop
%{_datadir}/icons/hicolor/*/apps/%{projectname}.*
%{_datadir}/%{projectname}
%{_datadir}/metainfo/%{projectname}.metainfo.xml

%changelog
openSUSE Build Service is sponsored by