File mesen2.spec of Package mesen2
#
# Spec file for package mesen2
#
# Copyright (c) 2024 SUSE LLC
#
# 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/>.
#
Name: mesen2
Summary: Multi-system emulator (NES, SNES, GB, GBA, PCE, SMS/GG) in C#
Version: 20240703.523b1733
Release: 0
Group: System/Emulators/Other
License: GPL-3.0-or-later
URL: https://forums.nesdev.org/viewtopic.php?t=24391
Source0: %{name}-%{version}.tar.xz
Source1: dotnet-sdk-8.0.301-linux-x64.tar.gz
Source2: dotnet-packages.tar.xz
Source3: dotnet-cache.tar.xz
BuildRequires: clang-devel
#BuildRequires: glibc-devel-static
BuildRequires: chrpath
BuildRequires: libicu-devel
BuildRequires: lld
BuildRequires: llvm-gold
BuildRequires: zip
BuildRequires: xz
BuildRequires: pkgconfig(libevdev)
BuildRequires: pkgconfig(sdl2)
BuildRequires: update-desktop-files
Requires(post): hicolor-icon-theme
Requires(postun): hicolor-icon-theme
Provides: Mesen = %{version}
Provides: Mesen-S = %{version}
Provides: Mesen-X = %{version}
Obsoletes: mesen-s
Obsoletes: mesen-x
# Only x86_64 for now.
ExclusiveArch: x86_64
%define _arch x64
%description
Multi-system emulator abomination in C# (not compatible with Mono) that is needed for
Metroid: HD Custom Edition (https://metroidconstruction.com/hack.php?id=381)
%package debug
Summary: Debug files for %{name}
Requires: %{name} = %{version}
BuildArch: noarch
%description debug
This package contains .NET debug file Mesen.pdb
%prep
%autosetup
# see https://learn.microsoft.com/en-gb/dotnet/core/install/linux-scripted-manual
# and https://aur.archlinux.org/packages/mesen2-git
mkdir dotnet
tar xf "%{SOURCE1}" -C dotnet
tar xf "%{SOURCE2}" -C dotnet
tar xf "%{SOURCE3}" -C dotnet
%build
ulimit -Sn 4000
export SUSE_ASNEEDED=0
export SUSE_ZNOW=0
%global _lto_cflags -flto=thin
%global _lto_ldlags -flto=thin -Wl,--plugin-opt=O3 %{?jobs:-Wl,--threads=%{jobs}}
export CFLAGS="${CFLAGS} -w -fPIC -O3 %{_lto_cflags}"
%ifarch x86_64
export CFLAGS="${CFLAGS} -march=x86-64 -mtune=generic -mssse3 -msse4 -msse4.1 -msse4.2 -mavx -maes -mpclmul"
#export CFLAGS="${CFLAGS} -fglobal-isel"
%endif
export LDFLAGS="-fuse-ld=lld -fPIC -Wl,-O1 -Wl,--gc-sections -Wl,--icf=safe %{_lto_cflags} %{_lto_ldlags}"
export LD="lld"
alias ld=ld.lld
export CC=clang
export CXX=clang++
export CFLAGS="${CFLAGS} -v -fbracket-depth=1024 -fconstexpr-depth=1024"
export CXXFLAGS="${CFLAGS}"
export LDFLAGS="${LDFLAGS} "
export HOST="$(${CC} -print-target-triple)"
# eat the flags, trash!
# '-p:PublishReadyToRunComposite=true' will avoid JIT by supposedly bloating binary's size 2-3x times
# '--self-contained' is required to compile-in entire .NET
sed -i -e "s/MESENFLAGS=/MESENFLAGS=${CFLAGS}/" \
-e "s/LINKOPTIONS :=/LINKOPTIONS := ${LDFLAGS}/" \
-e "s/-flto /-flto=thin /g" \
-e "s/dotnet publish /dotnet publish --no-restore /g" \
-e "s/-p:PublishSingleFile=false/--use-current-runtime -p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true/g" \
-e "s/--no-self-contained true/--self-contained --use-current-runtime -p:EnableCompressionInSingleFile=true/g" \
makefile
# M$' dumb bullshit tries to spy on your build and demands Internet connection
export DOTNET_CLI_TELEMETRY_OPTOUT=1
export DOTNET_ROOT="${PWD}/dotnet"
export PATH="${PATH}:${DOTNET_ROOT}:${DOTNET_ROOT}/tools"
# crutch to avoid the go & rust-style need in Internet connection
cd UI
sed -i "/Dotnet.Bundle/d" UI.csproj
export NUGET_PACKAGES="${DOTNET_ROOT}/packages"
export NUGET_HTTP_CACHE_PATH="${DOTNET_ROOT}/http-cache"
dotnet restore --packages "${DOTNET_ROOT}/packages" -r linux-x64 --use-current-runtime --ignore-failed-sources
cd ..
make %{?jobs:-j %jobs} \
LTO=true \
USE_AOT=true \
SYSTEM_LIBEVDEV=true \
STATICLINK=false
%install
install -d %{buildroot}%{_bindir}
install -Dm 755 bin/linux-x64/Release/linux-x64/publish/Mesen* %{buildroot}%{_bindir}/
chrpath --delete %{buildroot}%{_bindir}/Mesen
# Generate and install "Mesen.desktop"
mkdir -p %{buildroot}/%{_datadir}/applications/
cat > %{buildroot}/%{_datadir}/applications/Mesen.desktop << 'EOF'
[Desktop Entry]
Name=Mesen
GenericName=Multi-system emulator
Comment=Multi-system emulator (NES, SNES, GB, GBA, PCE, SMS/GG) in C#
Exec=Mesen %f
Icon=Mesen
Type=Application
Categories=Game;Emulator;
EOF
# Install icon
install -p -D -m 0644 Linux/appimage/Mesen.48x48.png %{buildroot}/%{_datadir}/icons/hicolor/48x48/apps/Mesen.png
%suse_update_desktop_file -i Mesen
%files
%{_bindir}/Mesen
%{_datadir}/icons/hicolor/48x48/apps/Mesen.png
%{_datadir}/applications/Mesen.desktop
%files debug
%{_bindir}/Mesen.pdb
%changelog