File melonds.spec of Package melonds
#
# Spec file for package melonDS
#
# Copyright © 2019–2022 Markus S. <kamikazow@opensuse.org>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
%define _localname melonDS
# it does not support vulkan, so ENABLE_VKBASALT=1 requires MESA_LOADER_DRIVER_OVERRIDE=zink
# but it does not work under wayland/egl and requires QT_QPA_PLATFORM=xcb QT_XCB_GL_INTEGRATION=xcb_glx
# even though `MESA_LOADER_DRIVER_OVERRIDE=zink eglinfo` works
%define use_wayland 1
%define use_qt6 1
%define use_clang 0
%define use_lld 0
# did they even fix that?
%if 0%{?use_qt6}
%global use_lto 0
%else
%global use_lto 0
%endif
%define __builder ninja
Name: melonds
Summary: Nintendo DS emulator
Version: 1.0rc+14~git20250117.15c3faa2
Release: 0
License: GPL-3.0-or-later
URL: http://melonds.kuribo64.net/
#Source0: https://github.com/Arisotura/melonDS/archive/%{version}.tar.gz#/%{_localname}-%{version}.tar.gz
Source0: %{name}-%{version}.tar.xz
Patch5: melonds_PR2011.patch
Patch8: melonds_PR2060.patch
# this is seem to be quite broken
Patch9: melonds_PR2065.patch
Patch10: melonds_PR2071.patch
Patch11: melonds_PR2088.patch
Patch13: melonds_PR2127.patch
Patch14: melonds_PR2133.patch
Patch15: melonds_PR2216.patch
Patch16: melonds_PR2258.patch
# revert this to load old Castlevania: Dawn of Sorrow saves with bad CRC16
# see https://drastic-ds.com/viewtopic.php?t=4243
Patch999: melonds_CRC16-fix.patch
# this will disable forced reset on console type & BIOS changes and ignore bad states
# making it potentially possible to restore states with corruption
Patch1000: melonds_allow-corruption.patch
%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++
%endif
BuildRequires: binutils
BuildRequires: ninja
BuildRequires: execstack
BuildRequires: cmake >= 3.13
BuildRequires: extra-cmake-modules
BuildRequires: hicolor-icon-theme
BuildRequires: libarchive-devel
BuildRequires: libcurl-devel
BuildRequires: libpcap-devel
BuildRequires: libslirp-devel
BuildRequires: pkgconfig(libenet)
BuildRequires: pkgconfig(sdl2)
%if 0%{?use_wayland}
BuildRequires: pkgconfig(wayland-client)
BuildRequires: pkgconfig(wayland-egl)
BuildRequires: pkgconfig(wayland-egl-backend)
BuildRequires: pkgconfig(wayland-protocols)
BuildRequires: pkgconfig(wayland-server)
%endif
BuildRequires: libopenssl-devel
BuildRequires: update-desktop-files
%if 0%{?use_qt6}
BuildRequires: qt6-gui-private-devel
BuildRequires: cmake(Qt6LinguistTools)
BuildRequires: pkgconfig(Qt6Concurrent)
BuildRequires: pkgconfig(Qt6Core)
BuildRequires: pkgconfig(Qt6DBus)
BuildRequires: pkgconfig(Qt6Multimedia)
BuildRequires: pkgconfig(Qt6Network)
BuildRequires: pkgconfig(Qt6OpenGL)
BuildRequires: pkgconfig(Qt6OpenGLWidgets)
BuildRequires: pkgconfig(Qt6Qml)
BuildRequires: pkgconfig(Qt6Svg)
BuildRequires: pkgconfig(Qt6WaylandClient)
BuildRequires: pkgconfig(Qt6Widgets)
%else
BuildRequires: libQt5PlatformSupport-private-headers-devel
BuildRequires: libqt5-qtbase-private-headers-devel
BuildRequires: cmake(Qt5LinguistTools)
BuildRequires: pkgconfig(Qt5Concurrent)
BuildRequires: pkgconfig(Qt5Core)
BuildRequires: pkgconfig(Qt5DBus)
BuildRequires: pkgconfig(Qt5Multimedia)
BuildRequires: pkgconfig(Qt5Network)
BuildRequires: pkgconfig(Qt5OpenGL)
BuildRequires: pkgconfig(Qt5Qml)
BuildRequires: pkgconfig(Qt5Svg)
BuildRequires: pkgconfig(Qt5WaylandClient)
BuildRequires: pkgconfig(Qt5Widgets)
%endif
%description
melonDS is a Nintendo DS emulator.
Now with compute shader renderer.
%prep
%setup -q
#autosetup -p1
%patch -P5 -p1 -F2
%patch -P8 -p1 -F2
#patch -P9 -p1 -F2
%patch -P10 -p1 -F2
%patch -P11 -p1 -F2
#patch -P13 -p1 -F2
%patch -P14 -p1 -F2
%patch -P999 -p1 -F2 -R
#patch -P1000 -p1 -F2
%if 0%{?use_wayland}
sed -i '1s|^|include_directories("/usr/include/wayland")\n\n|' src/frontend/qt_sdl/CMakeLists.txt
%endif
%build
# this macro needs 'BuildRequires: memory-constraints'
#limit_build -m 3072
ulimit -Sn 4000
# https://wiki.gentoo.org/wiki/Hardened/GNU_stack_quickstart
export UCFLAGS="%{optflags} -w -fPIC -O3"
#export UCFLAGS="${UCFLAGS} -Wa,--noexecstack"
#export UCFLAGS="-fPIC -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -fstack-clash-protection -fno-strict-aliasing"
%ifarch x86_64
export UCFLAGS="${UCFLAGS} -march=x86-64 -mtune=generic -mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
%endif
# don't commit suicide out of shame!
export UCFLAGS="${UCFLAGS} $(pkg-config --cflags wayland-egl)"
export ULDFLAGS="-fPIC -Wl,-O1 -Wl,--icf=safe -Wl,--gc-sections -Wl,--sort-common -Wl,-O1"
#export ULDFLAGS="${ULDFLAGS} -Wl,-z,noexecstack"
%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
%else
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 CPP='clang -E' LD=ld.lld AR=llvm-ar AS=llvm-as NM=llvm-nm OBJCOPY=llvm-objcopy OBJDUMP=llvm-objdump RANLIB=llvm-ranlib
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"
export UCXXFLAGS="${UCFLAGS}"
#export UCXXFLAGS="${UCXXFLAGS} -fpermissive -fcxx-exceptions"
export HOST="$(${CC} -print-target-triple)"
%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 -fpredictive-commoning"
export UCXXFLAGS="${UCFLAGS}"
#export UCXXFLAGS="${UCXXFLAGS} -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=%{?jobs:%{jobs}}
%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}"
%cmake \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-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="${CFLAGS} ${LDFLAGS}" \
-DCMAKE_SHARED_LINKER_FLAGS="${CFLAGS} ${LDFLAGS}" \
-DCMAKE_STATIC_LINKER_FLAGS="" \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DBUILD_SHARED_LIBS=OFF \
-DBUILD_STATIC_LIBS=ON \
%if 0%{?use_wayland}
-DENABLE_WAYLAND=ON \
%else
-DENABLE_WAYLAND=OFF \
%endif
%if 0%{?use_qt6}
-DUSE_QT6=ON \
%else
-DUSE_QT6=OFF \
%endif
%if 0%{?use_lto}
-DINTERPROCEDURAL_OPTIMIZATION=ON \
-DINTERPROCEDURAL_OPTIMIZATION_RELEASE=ON \
-DENABLE_LTO_RELEASE=ON \
-DENABLE_LTO=ON \
%else
-DINTERPROCEDURAL_OPTIMIZATION=OFF \
-DINTERPROCEDURAL_OPTIMIZATION_RELEASE=OFF \
-DENABLE_LTO_RELEASE=OFF \
-DENABLE_LTO=OFF \
%endif
-DENABLE_JIT=ON \
-DENABLE_OGLRENDERER=ON
%cmake_build
%install
%cmake_install
execstack -c %{buildroot}/%{_bindir}/%{_localname}
%files
%doc README.md
%license LICENSE
%{_bindir}/%{_localname}
%{_datadir}/applications/net.kuribo64.melonDS.desktop
%{_datadir}/icons/hicolor/*/apps/net.kuribo64.melonDS.png
%changelog