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
%define use_qt6 1
%define use_clang 1
%define use_lld 1
# supposedly, there are crashes under Qt5 with LTO enabled
# but building with Qt6 by itself seems to lead to crashes anyway
%if 0%{?use_qt6}
%global use_lto 1
%else
%global use_lto 0
%endif
%define __builder ninja

Name:             melonds
Summary:          Nintendo DS emulator
Version:          0.9.5+257~git20240514.5ab8161
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
%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(gtk+-3.0)
BuildRequires:    pkgconfig(sdl2)
BuildRequires:    pkgconfig(wayland-client)
BuildRequires:    pkgconfig(wayland-egl) 
BuildRequires:    pkgconfig(wayland-egl-backend)
BuildRequires:    pkgconfig(wayland-protocols)
BuildRequires:    pkgconfig(wayland-server)
BuildRequires:    libopenssl-devel
BuildRequires:    libzstd-devel
BuildRequires:    update-desktop-files
%if 0%{?use_qt6}
BuildRequires:    qt6-gui-private-devel
BuildRequires:    cmake(Qt6Gui)
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 -n %{_localname}-%{version}
%autosetup -p1
sed -i '1s|^|include_directories("/usr/include/wayland")\n\n|' src/frontend/qt_sdl/CMakeLists.txt

%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} -fpermissive"
#export UCXXFLAGS="${UCFLAGS} -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} -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_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
%defattr(-,root,root,-)
%doc README.md
%license LICENSE
%{_bindir}/%{_localname}
%{_datadir}/applications/net.kuribo64.melonDS.desktop
%{_datadir}/icons/hicolor/*/apps/net.kuribo64.melonDS.png

%changelog
openSUSE Build Service is sponsored by