File pcsx2-magicgate-patched.spec of Package pcsx2-magicgate-patched

#
# spec file for package pcsx2
#
# Copyright (c) 2015 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# 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 http://bugs.opensuse.org/
#

%define use_clang 1
%define use_lld 1
# viable only on x86_64… when clang doesn't mess it up and produce segfaulting binaries… or is it ?
%ifarch %ix86 %arm
%define use_clang 1
%define use_lto 0
%else
# Qt/PIC clang LTO bug may prevent that for now. also there is some linking bug with libpcap
%define use_lto 1
%endif
# it's not PCSX2 without absolute ass-backwards anti-user idiocy by design
# the eternal competition in the worst-maintained F/OSS on the planet between it, Khronos and web standards
# see https://github.com/PCSX2/pcsx2/issues/6939 and https://github.com/PCSX2/pcsx2/issues/6115
# and https://github.com/PCSX2/pcsx2/issues/6917 & https://github.com/PCSX2/pcsx2/commit/05bed05afeac6e5d5412886feac5f2e2984135e5
# see https://aur.archlinux.org/packages/pcsx2-git for some snots and crutches
%define qt_ui 1
# revision c07c942659ccf758d118bfcdff5df076c3e4c36c / 1.7.2759+2~git20220522.c07c94265 is the last known to work
%define gtk3_ui 1
%define opencl 0
%define dumbname PCSX2
%define dumbername Pcsx2
%define realname pcsx2
Name:          pcsx2-magicgate-patched
License:       GPL-3.0
Version:       1.7.0.20230201T104408
Release:       0
URL:           http://pcsx2.net/
Summary:       Sony PlayStation 2 Emulator
Group:         System/Emulators/Other
Source:        %{realname}-%{version}.tar.xz
Patch0:        pcsx2_rapidyaml-fix.patch
#Patch1:        pcsx2_issue4294.patch
#Patch2:        pcsx2-static_cast.patch
%if 0%{?use_clang}
BuildRequires: clang-devel
#BuildRequires: npth-devel
%if 0%{?use_lld}
BuildRequires: lld
%else
BuildRequires: llvm-gold
BuildRequires: binutils-gold
%endif
%else
BuildRequires: gcc-c++
BuildRequires: binutils-gold
%endif
#BuildRequires: ninja
BuildRequires: boost-devel
BuildRequires: cmake
BuildRequires: cmake(ryml)
#BuildRequires: glibc-devel
BuildRequires: fdupes
BuildRequires: libaio-devel
BuildRequires: imgui-devel
BuildRequires: pkgconfig(libusb-1.0)
# non-free library
#BuildRequires: libCg-devel
BuildRequires: libjpeg-devel
BuildRequires: openSUSE-release
%if 0%{?opencl}
BuildRequires: opencl-headers
BuildRequires: opencl-cpp-headers
BuildRequires: pkgconfig(OpenCL)
%endif
BuildRequires: pkgconfig(bzip2)
BuildRequires: pkgconfig(gl)
BuildRequires: pkgconfig(egl)
%if 0%{?suse_version} > 1600	
BuildRequires:    fmt-9-devel
%else
BuildRequires:    fmt-devel
%endif
BuildRequires: pkgconfig(glew)
BuildRequires: pkgconfig(libcurl)
BuildRequires: pkgconfig(liblzma)
BuildRequires: pkgconfig(libpcap)
BuildRequires: pkgconfig(libsparsehash)
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(libudev)
#BuildRequires: pkgconfig(sdl)
BuildRequires: pkgconfig(sdl2)
BuildRequires: pkgconfig(xcb-proto)
BuildRequires: pkgconfig(x11)
BuildRequires: pkgconfig(samplerate)
BuildRequires: pkgconfig(soundtouch)
BuildRequires: png++-devel
BuildRequires: portaudio-devel
BuildRequires: pkgconfig(alsa)
BuildRequires: pkgconfig(libpulse)
BuildRequires: pkgconfig(jack)
#BuildRequires: pkgconfig(openal)
# https://github.com/PCSX2/pcsx2/pull/3686
BuildRequires: pkgconfig(yaml-cpp)
BuildRequires: pkgconfig(libzip)
BuildRequires: pkgconfig(libzstd)
BuildRequires: pkgconfig(zlib)
BuildRequires: pkgconfig(harfbuzz)
BuildRequires: pkgconfig(vulkan)
BuildRequires: glslang-devel
BuildRequires: libzip-tools
BuildRequires: libzstd-devel-static
%if 0%{?qt_ui}
#BuildRequires: wxQt-devel
#BuildRequires: wxWidgets-any-devel >= 3.0
BuildRequires: qt6-gui-private-devel
BuildRequires: pkgconfig(Qt6Core)
BuildRequires: pkgconfig(Qt6Concurrent)
BuildRequires: pkgconfig(Qt6Gui)
BuildRequires: pkgconfig(Qt6OpenGL)
BuildRequires: pkgconfig(Qt6Multimedia)
BuildRequires: pkgconfig(Qt6Linguist)
BuildRequires: pkgconfig(Qt6Network)
BuildRequires: pkgconfig(Qt6Widgets)
%else
%if 0%{?gtk3_ui}
BuildRequires: wxGTK3-devel
BuildRequires: wxWidgets-any-devel >= 3.0
BuildRequires: pkgconfig(gtk+-3.0)
%else
BuildRequires: wxWidgets-3_0-devel
BuildRequires: pkgconfig(gtk+-2.0)
%endif
%endif
# mix of SDL 1 and 2 libraries can crash wxWidgets
#Conflicts:     plugin-sound_sdlu-3_0
Conflicts:     %{realname}
Recommends:    %{realname}-lang = %{version}
%ifnarch x86_64
Obsoletes:     %{realname}-32bit
%endif
BuildRoot:     %{_tmppath}/%{name}-%{version}-build

%description
Sony PlayStation 2 emulator. Requires a BIOS image in ~/.config/%{dumbname}/bios (will be created when you first run
PCSX2) or in a directory of your choosing. Check http://www.pcsx2.net/guide.php#Bios for details on which files
you need and how to obtain them.

%{lang_package}

%prep
%autosetup -p1 -n %{realname}-%{version}
# DO NOT EVER force march=native that randomly creates binaries with unexpected instructions !
%ifarch x86_64
sed -i -e 's:-march=native:-march=x86-64-v2:g' cmake/BuildParameters.cmake
sed -i -e 's:-msse -msse2:-mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul:g' cmake/BuildParameters.cmake
%else
sed -i -e 's:-march=native:-march=x86-64:g' cmake/BuildParameters.cmake
sed -i -e 's:-mfpmath=sse::g' cmake/BuildParameters.cmake
%endif
# oh, don't be prissy, built with GTK3 and SDL2
sed -i -e "s:FATAL_ERROR:WARNING:g" \
	cmake/BuildParameters.cmake \
	cmake/ApiValidation.cmake

# this useless check likes to shit itself
sed -i '/check_function_exists/d' cmake/FindPCAP.cmake

#for file in $(grep -iRl '#include "PrecompiledHeader.h"' pcsx2); do
#	sed -i -e 's:#include "PrecompiledHeader.h"::g' "${file}"
#done

# it craps out on wayland
sed -i -e 's:Exec=.*:Exec=env GDK_BACKEND=x11 QT_QPA_PLATFORM=xcb MESA_NO_ERROR=1 %{realname}:' linux_various/PCSX2.desktop.in


%build
# this macro needs 'BuildRequires: memory-constraints'
#limit_build -m 2000
ulimit -Sn 4000
# this might be needed to avoid random builds with forced AVX2 which die on older CPUs
# but adding this forces SSE2 version of GPU plugin that is broken under clang
#  -DDISABLE_ADVANCE_SIMD=TRUE \
# it's likely because those geniuses hardcode "-march=native" too…
# -fno-strict-aliasing -fvisibility=hidden ?
export UCFLAGS="${UCFLAGS} -fPIC -fno-strict-aliasing -O3 -march=x86-64-v2 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
%ifarch x86_64
export UCFLAGS="${UCFLAGS} -mtune=generic"
%endif
export ULDFLAGS="-fPIC"
# -Wl,--gc-sections -Wl,--icf=safe ?
export ULDFLAGS="${ULDFLAGS} -Wl,--gc-sections -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 -D_GNU_SOURCE -Wno-argument-outside-range"
#export UCFLAGS="${UCFLAGS} -fexceptions -relocatable-pch -faligned-allocation"
export UCXXFLAGS="${UCFLAGS}"
#export UCXXFLAGS="${UCXXFLAGS} -fpermissive -fcxx-exceptions"
export HOST="$(${CC} -print-target-triple)"
%if 0%{?use_lld}
export ULDFLAGS="${ULDFLAGS} -fuse-ld=lld"
%ifarch %ix86 %arm
export ULDFLAGS="${ULDFLAGS} -Wl,-z,notext"
%endif
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 -fvect-cost-model=cheap -fsimd-cost-model=cheap -fpredictive-commoning"
export UCXXFLAGS="${UCFLAGS} -fpermissive"
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}"
mkdir build && cd build
cmake \
  -DUSE_PCH=OFF -DENABLE_PCH=OFF \
  -DENABLE_PRECOMPILED_HEADERS=OFF \
  -DSKIP_PRECOMPILE_HEADERS=ON \
  -DUSE_PRECOMPILED_HEADERS=OFF \
  -DCMAKE_INSTALL_PREFIX='%{_prefix}' \
  -DCMAKE_BUILD_TYPE='RelWithDebInfo' \
  -DPACKAGE_MODE=TRUE \
  -DENABLE_TESTS=FALSE \
  -DHAVE_PF_RING=TRUE \
  -DDISABLE_PCSX2_WRAPPER=TRUE \
  -DXDG_STD=TRUE \
  -DREBUILD_SHADER=TRUE \
  -DPLUGIN_DIR='%{_libdir}/%{dumbname}' \
  -DGAMEINDEX_DIR='%{_datadir}/%{dumbname}' \
  -DDOC_DIR='%{_docdir}/%{dumbname}' \
  -DBIN_DIR='%{_bindir}' \
  -DGSDX_LEGACY=FALSE \
  -DGLSL_API=TRUE \
  -DEGL_API=TRUE \
  -DUSE_OPENGL=TRUE \
  -DUSE_VULKAN=TRUE \
  -DWAYLAND_API=TRUE \
  -DCUBEB_API=TRUE \
%if 0%{?opencl}
  -DOPENCL_API=TRUE \
%endif
  -DDISABLE_BUILD_DATE=TRUE \
  -DSDL2_API=TRUE \
  -DEXTRA_PLUGINS=TRUE \
%if 0%{?qt_ui}
  -DPACKAGE_MODE=FALSE \
  -DQT_BUILD=TRUE \
  -DGTK2_API=FALSE \
%else
  -DPACKAGE_MODE=TRUE \
%if 0%{?gtk3_ui}
  -DGTK2_API=FALSE \
%else
  -DGTK2_API=TRUE \
%endif
%endif
%if 0%{?use_lto}
  -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON \
%else
  -DUSE_LTO=FALSE \
  -DLTO_PCSX2_CORE=OFF \
  -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=OFF \
%endif
  -DCMAKE_C_COMPILER="${CC}" \
  -DCMAKE_CXX_COMPILER="${CXX}" \
  -DCMAKE_LINKER="${LD}" \
  -DOPTIMIZATION_FLAG="-fPIC -O3" \
  -DCMAKE_C_FLAGS="${CFLAGS}" \
  -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
  -DCMAKE_EXE_LINKER_FLAGS="${LDFLAGS}" \
  -DUSER_CMAKE_C_FLAGS="${UCFLAGS}" \
  -DUSER_CMAKE_CXX_FLAGS="${UCXXFLAGS}" \
  -DUSER_CMAKE_LD_FLAGS="${ULDFLAGS}" \
  .. || cat CMakeFiles/CMakeError.log
%cmake_build

%install
# actually install this broken crap
%if 0%{?qt_ui}
  mkdir -pv %{buildroot}%{_bindir} %{buildroot}%{_datadir}/%{dumbname} %{buildroot}%{_datadir}/applications %{buildroot}%{_datadir}/pixmaps
  # move all the garbo from its dump
  #mv -v bin/* %{buildroot}%{_datadir}/%{dumbname}/
  # commit filthy heresy
  mv -v build/pcsx2-qt/pcsx2-qt %{buildroot}%{_datadir}/%{dumbname}/
  mv -v build/pcsx2-qt/resources %{buildroot}%{_datadir}/%{dumbname}/
  # symlink the myopic binary from datadir into bindir
  ln -sv %{_datadir}/%{dumbname}/%{realname}-qt %{buildroot}%{_bindir}/%{realname}
  # prefer newer, crisper icon
  if [ -f "%{buildroot}%{_datadir}/%{dumbname}/resources/icons/AppIconLarge.png" ]; then
      ln -sv ../%{dumbname}/resources/icons/AppIconLarge.png %{buildroot}%{_datadir}/pixmaps/%{dumbname}.png
  else
      cp -v linux_various/%{dumbname}.xpm %{buildroot}%{_datadir}/pixmaps/
  fi
  # search for desktop-file
  if [ -f "%{buildroot}%{_datadir}/%{dumbname}/%{dumbname}.desktop" ]; then
      mv -v %{buildroot}%{_datadir}/%{dumbname}/%{dumbname}.desktop %{buildroot}%{_datadir}/applications/
  else
      cp -v linux_various/%{dumbname}.desktop.in %{buildroot}%{_datadir}/applications/%{dumbname}.desktop
      sed -i -e 's:Categories=.*:Categories=System;Emulator;:' %{buildroot}%{_datadir}/applications/%{dumbname}.desktop
  fi
  # dump useless docs into the right place
  if [ ! -d "%{buildroot}%{_datadir}/doc/%{dumbername}" ]; then
      mkdir -p %{buildroot}%{_docdir}/packages
      mv -v bin/docs %{buildroot}%{_docdir}/packages/%{name}-%{version}
  fi
%else
%cmake_install
%endif

if [ -d "%{buildroot}%{_datadir}/doc/%{dumbername}" ]; then
        mkdir -p %{buildroot}%{_docdir}/packages || echo "too bad"
        mv %{buildroot}%{_datadir}/doc/%{dumbername} %{buildroot}%{_docdir}/packages/%{name}-%{version}
fi

if [ -d "%{buildroot}%{_datadir}/%{dumbname}/resources/locale" ]; then
        mkdir -p %{buildroot}%{_datadir} || echo "too bad"
        mv -v %{buildroot}%{_datadir}/%{dumbname}/resources/locale %{buildroot}%{_datadir}/
fi

# move translations to main language dir if there isn't a sublang or delete
# translations not supported by distro at all
for i in $(ls %{buildroot}%{_datadir}/locale | grep _); do
  new=$(echo $i | sed "s:_.*::g")
  if [ ! -d %{_datadir}/locale/$i ]; then
    if [ -d %{_datadir}/locale/$new ]; then
      mv %{buildroot}%{_datadir}/locale/$i %{buildroot}%{_datadir}/locale/$new
    else
      rm -rf %{buildroot}%{_datadir}/locale/$i
    fi
  fi
done
for lang in $(ls %{buildroot}%{_datadir}/locale); do
    mkdir -p %{buildroot}%{_datadir}/locale/${lang}/LC_MESSAGES
    mv -v %{buildroot}%{_datadir}/locale/${lang}/*.mo %{buildroot}%{_datadir}/locale/${lang}/LC_MESSAGES/
done

#install -D -m 644 %{SOURCE1} -t %{buildroot}%{_sysconfdir}/udev/rules.d/
%fdupes -s %{buildroot}
%find_lang pcsx2 || echo "too bad"
%find_lang pcsx2-qt || echo "too bad"
%if !0%{?qt_ui}
%find_lang pcsx2_Main || echo "too bad"
%find_lang pcsx2_Iconized || echo "too bad"

%files lang -f pcsx2_Main.lang -f pcsx2_Iconized.lang
%endif

%files
%defattr(-,root,root)
#%{_sysconfdir}/udev/rules.d/99-direct-access-to-sixaxis-gamepad.rules
%caps(cap_net_raw=eip cap_net_admin=eip) %{_bindir}/%{realname}
#{_bindir}/%{realname}*
#{_libdir}/%{dumbname}
%{_datadir}
%{_datadir}/%{dumbname}
%{_datadir}/applications/%{dumbname}.desktop
%{_datadir}/pixmaps/%{dumbname}.*
%dir %{_docdir}/packages
%{_docdir}/packages/%{name}-%{version}
%if !0%{?qt_ui}
%{_mandir}/man?/%{dumbname}.*
#{_datadir}/locale/*/LC_MESSAGES/*.mo
%endif

%changelog
openSUSE Build Service is sponsored by