File mgba.spec of Package mgba

#
# spec file for package mgba
#
# Copyright (c) 2024 SUSE LLC
# Copyright (c) 2017–2023 Markus S. <kamikazow@opensuse.org>
# Copyright (c) 2015–2017 ROSA Linux
#
# Based on ROSA Linux 2016.1 mGBA package
# https://abf.rosalinux.ru/import/mgba/blob/rosa2016.1/mgba.spec
# spec file classified as "code" and released under MIT License
# "Modern Style with sublicense" per ROSA Contributor License Agreement.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define use_clang 1
%define use_lld 1
%ifarch %ix86 %arm
%define use_lto 0
%else
%define use_lto 1
%endif
# upstream wants qt6... in the future
%define use_qt6 0

%define __builder ninja
Name:           mgba
Version:        0.10.3
Release:        0%{?dist}
Summary:        Game Boy Advance emulator
License:        MPL-2.0
Group:          System/Emulators/Other
URL:            https://mgba.io/
Source0:        %{name}-%{version}.tar.xz
#Source0:        https://github.com/mgba-emu/mgba/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
BuildRequires:  cmake
BuildRequires:  desktop-file-utils
%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
%if 0%{?use_qt6}
BuildRequires:  cmake(Qt6LinguistTools)
BuildRequires:  pkgconfig(Qt6Core)
BuildRequires:  pkgconfig(Qt6Multimedia)
BuildRequires:  pkgconfig(Qt6OpenGL)
BuildRequires:  pkgconfig(Qt6Widgets)
%else
BuildRequires:  cmake(Qt5LinguistTools)
BuildRequires:  pkgconfig(Qt5Core)
BuildRequires:  pkgconfig(Qt5Multimedia)
BuildRequires:  pkgconfig(Qt5OpenGL)
BuildRequires:  pkgconfig(Qt5Widgets)
%endif
BuildRequires:  ffmpeg-devel
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(ImageMagick)
BuildRequires:  pkgconfig(bzip2)
BuildRequires:  pkgconfig(epoxy)
BuildRequires:  pkgconfig(gl)
BuildRequires:  pkgconfig(glu)
BuildRequires:  pkgconfig(ice)
BuildRequires:  pkgconfig(json-c)
BuildRequires:  pkgconfig(libedit)
BuildRequires:  pkgconfig(libelf)
BuildRequires:  pkgconfig(libpng)
BuildRequires:  pkgconfig(libzip)
# pkgconfig(lua/lua5.4/luajit)
BuildRequires:  pkgconfig(lua)
BuildRequires:  pkgconfig(minizip)
BuildRequires:  pkgconfig(sdl2)
BuildRequires:  pkgconfig(sqlite3)
BuildRequires:  pkgconfig(sm)
BuildRequires:  pkgconfig(x11)
BuildRequires:  pkgconfig(zlib)
BuildRequires:  libzip-tools
#BuildRequires:  python3-devel
Requires(post): hicolor-icon-theme
Requires(postun): hicolor-icon-theme
%if 0%{?fedora} || 0%{?centos_version} || 0%{?rhel_version}
BuildRequires:  ninja-build
%undefine _debugsource_packages
%endif
%if 0%{?suse_version}
BuildRequires:  ninja
%endif

%description
mGBA is a new generation of Game Boy Advance emulator with the goal
of being fast enough to run on lower end hardware.
Other goals include accurate enough emulation to provide a development
environment for homebrew software, a good workflow for tool-assist
runners, and a modern feature set for emulators that older emulators
may not support.

%package sdl
Summary:        Game Boy Advance (GBA) emulator (SDL2-based CLI version)
Group:          System/Emulators/Other

%description sdl
Game Boy Advance (GBA) emulator with the goal of being fast enough to run on
lower end hardware than other emulators support, without sacrificing accuracy
or portability. Other goals include accurate enough emulation to provide a
development environment for homebrew software, a good workflow for tool-assist
runners, and a modern feature set for emulators that older emulators may not
support.

This package provides SDL2-based CLI version of mGBA.

%prep
%autosetup
# consequence of thirdparty/sqlite using dl* functions
echo "target_link_libraries(%{name} dl)" >> CMakeLists.txt

%build
# this macro needs 'BuildRequires: memory-constraints'
#limit_build -m 2000
ulimit -Sn 4000
#export UCFLAGS="%{optflags} -fno-omit-frame-pointer"
export UCFLAGS="${UCFLAGS} -w -fPIC -O3"
%ifarch x86_64
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_clang}
export CC=clang
export CXX=clang++
export UCFLAGS="${UCFLAGS} -v"
%ifarch x86_64
export UCFLAGS="${UCFLAGS} -fglobal-isel"
%endif
export UCFLAGS="${UCFLAGS} -fexceptions -fbracket-depth=1024 -fconstexpr-depth=1024 -D_GNU_SOURCE"
#export UCFLAGS="${UCFLAGS} -faligned-allocation"
#export UCXXFLAGS="${UCFLAGS} -fpermissive"
export UCXXFLAGS="${UCFLAGS} -fcxx-exceptions"
%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
export HOST="$(${CC} -print-target-triple)"
%else
export CC=gcc
export CXX=g++
export UCFLAGS="${UCFLAGS} -ftree-parallelize-loops=4 -ftree-vectorize -fpredictive-commoning"
#export UCXXFLAGS="${UCFLAGS} -fpermissive"
export ULDFLAGS="${ULDFLAGS} -fuse-ld=gold -Wl,--sort-common -Wl,-O1"
export LD=ld.gold
alias ld=gold
export HOST="%{_target_platform}"
%endif

%if !0%{?use_lto}
%global _lto_cflags %{nil}
%global _lto_ldlags %{nil}
%else
%if 0%{?use_clang}
%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 -fuse-linker-plugin %{_lto_cflags} -ffat-lto-objects -flto-odr-type-merging
%global _lto_ldlags -fuse-linker-plugin -flto=%{?jobs:%{jobs}}
%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_INSTALL_LIBEXEC="%_libexecdir" \
        -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 \
        -DTHREADS_PREFER_PTHREAD_FLAG=ON \
        -DBUILD_SHARED=ON \
        -DBUILD_STATIC=OFF \
%if 0%{?use_qt6}
        -DQT_V=6 \
%endif
        -DUSE_FFMPEG=ON \
        -DUSE_MAGICK=ON \
        -DUSE_USE_LIBZIP=ON
%cmake_build

%install
%cmake_install

# rather use %%doc and remove leftover file
rm -rf %{buildroot}%{_datadir}/doc/mGBA/ || echo "nothing to delete in %{buildroot}%{_datadir}/doc/mGBA/"
rm -rf %{buildroot}%{_includedir} || echo "nothing to delete in %{buildroot}%{_includedir}"

%post
/sbin/ldconfig
%desktop_database_post
%icon_theme_cache_post

%postun
/sbin/ldconfig
%desktop_database_postun
%icon_theme_cache_postun

%files
%license LICENSE
%doc CHANGES README.md
%{_libdir}/libmgba.*
%{_bindir}/%{name}-qt
%{_datadir}/applications/io.mgba.mGBA.desktop
%dir %{_datadir}/%{name}
%{_datadir}/%{name}/*
%{_datadir}/icons/hicolor/*/apps/io.mgba.mGBA.png
%{_mandir}/man?/mgba-qt.?%{?ext_man}

%files sdl
%{_bindir}/%{name}
%{_mandir}/man?/mgba.?%{?ext_man}

%changelog
openSUSE Build Service is sponsored by