%global debug_package %{nil}

Name:           xsidplay
Version:        2.1.9
Release:        35%{?dist}
Vendor:         xsidplay2.sf.net
License:        GPL
Summary:        XSidPlay SID Music Player
Group:          sound
Source0:        https://downloads.sourceforge.net/xsidplay2/%{name}-%{version}.tar.bz2
Patch1:         https://0x0.st/H-VA.patch#/xsidplay_diff_r288-r294_RAW.patch
Patch2:         https://0x0.st/Hqlp.patch#/xsidplay_diff_r295-r298_RAW.patch
BuildRequires:  autoconf cmake gcc-c++ libstdc++-devel qt5-qtbase-devel
BuildRequires:  SDL-devel alsa-lib-devel pulseaudio-libs-devel
BuildRequires:  libsidplayfp-devel
BuildRequires:  devscripts

%description
XSIDPLAY2 is a QT based music player for SID music. It's based onto
Michael Schwendt's XSIDPLAY, the historical SID player for Linux,
actually no more developed by the author.

%prep
%setup -q -n %{name}-%{version}
%patch -P1 -p3
%patch -P2 -p3

%build
%set_build_flags
sed -i 's|#SET(CMAKE_CXX_FLAGS " -O2|SET(CMAKE_CXX_FLAGS " -O2|' CMakeLists.txt
sed -i 's|SET(CMAKE_CXX_FLAGS " -O2 -H -fPIC")|SET(CMAKE_CXX_FLAGS " -H -fPIC -std=c++11 %{build_cxxflags} -fdata-sections -ffunction-sections %{build_ldflags} -Wl,-s,--gc-sections")|' CMakeLists.txt
sed -i 's|SET(CMAKE_CXX_FLAGS " -g -O0  -H|#SET(CMAKE_CXX_FLAGS " -g -O0  -H|' CMakeLists.txt
sed -i 's| -g -| -|' CMakeLists.txt
sed -i 's|option (WITH_TSID "Use TSID library" ON)|#option (WITH_TSID "Use TSID library" ON)|' CMakeLists.txt
sed -i 's|option (SID_WITH_SIDPLAY1 "UseSidplay1 library" ON)|#option (SID_WITH_SIDPLAY1 "UseSidplay1 library" ON)|' CMakeLists.txt
# fix redeclaration error
sed -i 's|#ifndef SID_WITH_SIDPLAY1|#ifdef SID_WITH_SIDPLAY1|' src/MainDialog.cpp
# set cmake (min) 3.5
sed -i 's|required(VERSION 2.8)|required(VERSION 3.5)|' CMakeLists.txt
./compile.sh

%install
mkdir -p %buildroot{%_bindir,%_datadir/%name,%_datadir/applications,%_datadir/fonts,%_datadir/pixmaps}
cp -a build/src/%name AUTHORS COPYING ChangeLog README sidid.cfg sidid.nfo %buildroot%_datadir/%name
cp -a %name.desktop %buildroot%_datadir/applications/%name.desktop
cp -a %name.xpm %buildroot%_datadir/pixmaps/%name.xpm
cp -a src/fonts/C64_Pro_Mono-STYLE.ttf %buildroot%_datadir/fonts/C64_Pro_Mono-STYLE.ttf
hardening-check -v build/src/%name

cat > %buildroot%_bindir/%name << EOF
#!/bin/bash
cd %_datadir/%name
./%name "\$@"
EOF

%files
%defattr(644, root, root, 755)
%_datadir/%name/*
%attr(755,root,root) %_bindir/%name
%attr(755,root,root) %_datadir/%name/%name
%_datadir/applications/%name.desktop
%_datadir/pixmaps/%name.xpm
%_datadir/fonts/*

%changelog
* Fri Mar 29 2024 samoht0 <https://copr.fedorainfracloud.org/coprs/samoht0/> 2.1.9
- history cleanup
* Sat May 27 2023 samoht0 <https://copr.fedorainfracloud.org/coprs/samoht0/> 2.1.9
- backport svn changes (r296-r298) using a patch