# The naming scheme in non-Mandriva-based distros
%if 0%{!?mklibname:1}
%define mklibname(ds)  lib%{1}%{?2:%{2}}%{-s:-static}%{-d:-devel}
%endif
%if 0%{!?mkrel:1}
%define mkrel(c) %{1}%{?dist}
%endif

%define         major        3
%define         libname      %mklibname %{name} %{major}
%define         develname    %mklibname %{name} -d
%define         staticname   %mklibname %{name} -d -s
%if %major == 2
%define         srcname      SDL%{major}_sound
%else
%define         srcname      SDL_sound
%endif

Name:           sdl%{major}_sound
Version:        3.0.0
Release:        %mkrel 0.git20250312.1
Summary:        An abstract SDL%{major} sound-file decoder
License:        zlib
Group:          System/Libraries
Url:            https://www.icculus.org/SDL_sound/
%dnl Source0:        https://github.com/icculus/SDL_sound/releases/download/v%{version}/SDL%{major}_sound-%{version}.tar.gz
Source0:        https://github.com/icculus/SDL_sound/archive/refs/heads/main.zip#/SDL_sound-main.zip
#Patch0:         sdl2_sound-1.0.4-includedir.patch

BuildRequires:  cmake
BuildRequires:  gcc
BuildRequires:  unzip
BuildRequires:  doxygen
BuildRequires:  pkgconfig(sdl%{major})
BuildRequires:  pkgconfig(flac)
BuildRequires:  pkgconfig(libmikmod)
BuildRequires:  pkgconfig(libmodplug)
BuildRequires:  pkgconfig(vorbis)
BuildRequires:  pkgconfig(speex)
BuildRequires:  pkgconfig(physfs)

%if %major == 2
Conflicts:      SDL_sound < 1.0.4
%elif %major == 3
Conflicts:      sdl2_sound < 2.0.6
%endif

%description
SDL%{major}_sound is SDL_sound but with a SDL%{major} backend. This is a library
that handles the decoding of several popular sound file formats, such
as .WAV and .MP3. It is meant to make the programmer's sound playback
tasks simpler. The programmer gives SDL%{major}_sound a file-name, or feeds it
data directly from one of many sources, and then reads the decoded
waveform data back at her leisure. If resource constraints are a
concern, SDL%{major}_sound can process sound data in programmer-specified
blocks. Alternately, SDL%{major}_sound can decode a whole sound file and hand
back a single pointer to the whole waveform. SDL%{major}_sound can also handle
sample rate, audio format, and channel conversion on-the-fly and
behind-the-scenes.


%package -n %{libname}
Summary:        SDL%{major}_sound main library
Group:          System/Libraries

%description -n %{libname}
SDL%{major}_sound main library.


%package -n %{develname}
Summary:        Development files for SDL%{major}_sound applications
Group:          Development/C
Requires:       %{libname} = %{version}-%{release}
Provides:       SDL%{major}_sound-devel = %{version}-%{release}
Provides:       lib%{name}-devel = %{version}-%{release}
Provides:       %{name}-devel = %{version}-%{release}

%description -n %{develname}
Development files for SDL%{major}_sound applications.


%package -n %{staticname}
Summary:        Static development files for SDL%{major}_sound libraries
Group:          Development/C
Requires:       %{develname} = %{version}-%{release}
Provides:       %{name}-static-devel = %{version}-%{release}

%description -n %{staticname}
Static development files for SDL%{major}_sound libraries.


%prep
%autosetup -p1 -n %{srcname}-main

%build
%cmake -DCMAKE_STATIC_LIBS:BOOL=ON \
       -DCMAKE_SHARED_LIBS:BOOL=ON \
       -DSDLSOUND_DECODER_MIDI:BOOL=ON
%cmake_build

doxygen docs/Doxyfile

%install
%cmake_install

# Add namespaces to man pages (livna bug #1181)
cp -a docs/man/man3 man3
pushd man3
mv actual.3 Sound_Sample::actual.3
mv author.3 Sound_DecoderInfo::author.3
mv buffer.3 Sound_Sample::buffer.3
mv buffer_size.3 Sound_Sameple::buffer_size.3
mv channels.3 Sound_AudioInfo::channels.3
mv decoder.3 Sound_Sample::decoder.3
mv description.3 Sound_DecoderInfo::description.3
mv desired.3 Sound_Sample::desired.3
mv extensions.3 Sound_DecoderInfo::extensions.3
mv flags.3 Sound_Sample::flags.3
mv format.3 Sound_AudioInfo::format.3
mv major.3 Sound_Version::major.3
mv minor.3 Sound_Version::minor.3
mv opaque.3 Sound_Sample::opaque.3
mv patch.3 Sound_Version::patch.3
mv rate.3 Sound_AudioInfo::rate.3
mv url.3 Sound_DecoderInfo::url.3
popd

mkdir -p %{buildroot}%{_mandir}
mv man3 %{buildroot}%{_mandir}

%files
%license LICENSE.txt
%doc docs/CREDITS.txt
%{_bindir}/*

%files -n %{libname}
%license LICENSE.txt
%doc docs/CREDITS.txt README.md
%{_libdir}/libSDL%{major}_sound.so.%{major}{,.*}

%files -n %{develname}
%doc docs/html/
%{_libdir}/lib*.so
%if %major < 2
%{_includedir}/SDL%{major}/SDL_sound.h
%else
%{_includedir}/SDL%{major}_sound/SDL_sound.h
%endif
%{_libdir}/cmake/SDL%{major}_sound/
%if %major < 3
%{_libdir}/pkgconfig/SDL%{major}_sound.pc
%else
%{_libdir}/pkgconfig/sdl%{major}-sound.pc
%endif
%{_mandir}/man3/*.3*

%files -n %{staticname}
%{_libdir}/lib*.a