File sameboy.spec of Package sameboy

#
# spec file for package sameboy
#
# Copyright (c) 2022 SUSE LLC
#
# 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 https://bugs.opensuse.org/
#

# default flags set '-flto=auto' which conflicts with '-flto=thin' below
%define _lto_cflags %{nil}

Name:           sameboy
Version:        0.15.5
Release:        0
Summary:        Game Boy and Game Boy Color emulator
License:        MIT
Group:          System/Emulators/Other
URL:            https://sameboy.github.io/
Source:         https://github.com/LIJI32/SameBoy/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Patch0:         0001-Allow-building-with-older-SDL-versions.patch
# gcc is compatible too but upstream recommends clang
# https://github.com/LIJI32/SameBoy/issues/296#issuecomment-705217337
# https://github.com/LIJI32/SameBoy#compilation
BuildRequires:  clang
# lld linker produces xxhash build-id incompatible with old Leap/SLE
%if 0%{?sle_version} > 0 && 0%{?sle_version} <= 150200
BuildRequires:  llvm-gold
%else
BuildRequires:  lld
%endif
BuildRequires:  hicolor-icon-theme
BuildRequires:  pkgconfig(sdl2)
BuildRequires:  rgbds
BuildRequires:  xdg-utils
BuildRequires:  update-desktop-files

%description
SameBoy is an open source Game Boy (DMG) and Game Boy Color (CGB) emulator,
written in portable C. It has an SDL frontend and a libretro core.
It also includes a text-based debugger with an expression evaluator.

https://sameboy.github.io/

%prep
%autosetup -p1 -n SameBoy-%{version}

%build
# we only build x86_64 for old Leap/SLE so we don't need to handle different architectures there
%if 0%{?sle_version} > 0 && 0%{?sle_version} <= 150200
  export CFLAGS='%{optflags} -fpie -flto=thin'
  export LDFLAGS='-O2 -pie -flto=thin'
%else
  # "-fstack-clash-protection" not yet supported by clang on aarch64/Linux
  # use current (as of August 2021) optflags string without that option on arm architectures
  # https://reviews.llvm.org/D96007
  %ifarch %arm aarch64
    %define optflags_clang_arm -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector-strong -funwind-tables -fasynchronous-unwind-tables -Werror=return-type %{?_lto_cflags}
    export CFLAGS='%{optflags_clang_arm} -fpie -flto=thin'
  %else
    # altivec extensions are broken in SDL at the moment (August 2021)
    # ideally they should be disabled in SDL headers on ppc64le
    %ifarch ppc64le
    export CFLAGS='%{optflags} -mno-altivec -fpie -flto=thin'
    %else
    export CFLAGS='%{optflags} -fpie -flto=thin'
    %endif
  %endif
  export LDFLAGS='-fuse-ld=lld -O2 -pie -flto=thin'
%endif


%make_build DATA_DIR=%{_datadir}/%{name}/

%install
%make_install PREFIX=%{_prefix} \
              DATA_DIR=%{_datadir}/%{name}/

%files
%{_bindir}/%{name}
%{_datadir}/%{name}
%{_datadir}/applications/%{name}.desktop
%{_datadir}/icons/hicolor/*/apps/%{name}.png
%{_datadir}/icons/hicolor/*/mimetypes/*-gameboy-*.png
%{_datadir}/mime/packages/sameboy.xml

%changelog
openSUSE Build Service is sponsored by