%define build_compat32 %{?_with_compat32:1}%{!?_with_compat32:0}

Summary:        A library to handle various audio file formats.
Summary(ja):    さまざまなフォーマットの音声ファイルを扱うライブラリ
Name:           libsndfile
Version:        1.0.31
Release:        1%{?_dist_release}
Group:          system
Vendor:         Project Vine
Distribution:   Vine Linux

License:        LGPLv2+ and GPLv2+ and BSD
URL:            http://libsndfile.github.io/libsndfile/
Source0:        https://github.com/libsndfile/libsndfile/releases/download/%{version}/libsndfile-%{version}.tar.bz2
Patch0:         %{name}-1.0.25-system-gsm.patch
Patch1:         %{name}-1.0.25-zerodivfix.patch

# security fix

BuildRoot:	%{_tmppath}/%{name}-%{version}-root

BuildRequires:  alsa-lib-devel
BuildRequires:  flac-devel
BuildRequires:  libogg-devel
BuildRequires:  libvorbis-devel
BuildRequires:  pkgconfig
BuildRequires:  sqlite3-devel
BuildRequires:  gsm-devel
BuildRequires:  python3
BuildRequires:  opus-devel

%description
libsndfile is a C library for reading and writing sound files such as
AIFF, AU and WAV files through one standard interface. It can currently
read/write 8, 16, 24 and 32-bit PCM files as well as 32-bit floating
point WAV files and a number of compressed formats.


%package devel
Summary: Libraries, includes, etc to develop libsndfile applications
Summary(ja): libsndfile アプリケーションを開発するためのファイル集
Group: programming
Requires: %{name} = %{version}-%{release}
Requires: pkgconfig

%description devel
Libraries, include files, etc you can use to develop libsndfile applications.


%package utils
Summary: Command Line Utilities for libsndfile
Summary(ja): libsndfileのコマンドラインユーティリティ
Group: multimedia,system
Requires: %{name} = %{version}-%{release}

%description utils
libsndfile is a C library for reading and writing sound files such as
AIFF, AU, WAV, and others through one standard interface.
This package contains command line utilities for libsndfile.


# compat32
%package -n compat32-%{name}
Summary: A library to handle various audio file formats.
Summary(ja): さまざまなフォーマットの音声ファイルを扱うライブラリ
Group: system,legacy

%description -n compat32-%{name}
libsndfile is a C library for reading and writing sound files such as
AIFF, AU and WAV files through one standard interface. It can currently
read/write 8, 16, 24 and 32-bit PCM files as well as 32-bit floating
point WAV files and a number of compressed formats.


%package -n compat32-%{name}-devel
Summary: Libraries, includes, etc to develop libsndfile applications
Summary(ja): libsndfile アプリケーションを開発するためのファイル集
Group: programming,legacy
Requires: compat32-%{name} = %{version}-%{release}
Requires: compat32-pkgconfig
Requires: %{name}-devel = %{version}-%{release}

%description -n compat32-%{name}-devel
Libraries, include files, etc you can use to develop libsndfile applications.


%debug_package


%prep
%autosetup -p1 
rm -r src/GSM610
autoreconf -I m4 -fiv # for system-gsm patch


%build
%configure \
	--disable-dependency-tracking \
	--enable-sqlite \
	--enable-alsa \
	--enable-largefile \
	--disable-static

# Get rid of rpath
sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool

make %{?_smp_mflags}


%install
make install DESTDIR=$RPM_BUILD_ROOT

rm -rf __docs
mkdir __docs
cp -pR $RPM_BUILD_ROOT%{_docdir}/%{name}/* __docs
rm -rf $RPM_BUILD_ROOT%{_docdir}/%{name}
find %{buildroot} -type f -name "*.la" -delete

# fix multilib issues
%if %{__isa_bits} == 64
%define wordsize 64
%else
%define wordsize 32
%endif

mv $RPM_BUILD_ROOT%{_includedir}/sndfile.h \
   $RPM_BUILD_ROOT%{_includedir}/sndfile-%{wordsize}.h

cat > $RPM_BUILD_ROOT%{_includedir}/sndfile.h <<EOF
#include <bits/wordsize.h>

#if __WORDSIZE == 32
# include "sndfile-32.h"
#elif __WORDSIZE == 64
# include "sndfile-64.h"
#else
# error "unexpected value for __WORDSIZE macro"
#endif
EOF


%check
LD_LIBRARY_PATH=$PWD/src/.libs make check


%files
%defattr(-,root,root)
%license COPYING
%doc AUTHORS ChangeLog NEWS README*
%{_libdir}/libsndfile.so.*

%files devel
%defattr(-,root,root)
%doc __docs/*
%{_libdir}/libsndfile.so
%{_includedir}/sndfile.h
%{_includedir}/sndfile.hh
%{_includedir}/sndfile-%{wordsize}.h
%{_libdir}/pkgconfig/sndfile.pc

%files utils
%{_bindir}/*
%{_mandir}/man1/*

# compat32
%if %{build_compat32}
%files -n compat32-%{name}
%defattr(-,root,root)
%{_libdir}/libsndfile.so.*

%files -n compat32-%{name}-devel
%defattr(-,root,root)
%{_includedir}/sndfile-%{wordsize}.h
%{_libdir}/libsndfile.so
%{_libdir}/pkgconfig/sndfile.pc
%endif


%changelog
* Fri Mar 26 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 1.0.31-1
- new upstream release.
- dropped Patch100-111: fixed in upstream.
- dropped ldconfig scriptlets.

* Sat Oct 19 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 1.0.28-2
- removed a comment in %%postun script.

* Thu Oct 17 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 1.0.28-1
- new upstream release.
- dropped Patch100-101.
- imported Patch100-111 from debian.

* Wed Feb 18 2015 Ryoichi INAGAKI <ryo1@toki.waseda.jp> - 1.0.25-2
- added Patch0, 1 and 101 from Fedora
  * Tue Jan 13 2015 Michal Hlavinka <mhlavink@redhat.com> - 1.0.25-14
  - fix CVE-2014-9496: 2 buffer overruns in sd2_parse_rsrc_fork (#1178840)
  - division by zero leading to denial of service in psf_fwrite (#1177254)
  * Sat Nov 12 2011 Ville Skyttä <ville.skytta@iki.fi> - 1.0.25-2
  - Patch to use system libgsm instead of a bundled copy.
- added BR: flac-devel, libogg-devel, libvorbis-devel, pkgconfig,
  sqlite3-devel and gsm-devel

* Mon Apr 29 2013 Toshiharu Kudoh <toshi.kd2@gmail.com> - 1.0.25-1
- new upstream release

* Sun Jul 31 2011 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> - 1.0.21-3
- change spec filename (-vl)

* Sat Jul 30 2011 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> - 1.0.21-2
- add patch100 for fix CVE-2011-2696 (IOF) from debian, thanks.

* Wed Sep 22 2010 MATSUBAYASHI Kohji <shaolin@vinelinux.org> - 1.0.21-1
- new upstream release
- built with rpm-4.8.1-1

* Mon Jun  1 2009 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 1.0.20-1vl5
- new upstream release with security fix (CVE-2009-1788, 1791)
- add patch110 to fix devide by 0 issues
- drop patch100 (is included in new release)
- change configure option to fix new release
- revome "TODO" file from file list

* Sun May 10 2009 NAKAMURA Kenta <kenta@vinelinux.org> 1.0.17-3
- added compat32 package for x86_64 arch support

* Tue Mar 31 2009 Daisuke SUZUKI <daisuke@linux.or.jp> 1.0.17-2
- spec in utf-8
- remove static lib

* Sat Jul 12 2008 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.0.17-1vl5
- applied new versioning policy
- removed lib*.la file from devel package

* Mon Oct 22 2007 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 1.0.17-0vl2
- rebuild for VineSeed

* Mon Oct 22 2007 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 1.0.17-0vl1
- new upstream release

* Mon Oct 22 2007 Satoshi IWAMOTO <satoshi.iwamoto@nifty.ne.jp> 1.0.16-0vl3.1
- add patch100 for fix CVE-2007-4974 (PCM Data Handling Buffer Overflow)
- built for VinePlus 4.x

* Fri Nov 17 2006 KAZUKI SHIMURA <kazuki@ma.ccnw.ne.jp> 1.0.16-0vl3
- add BuildRequires: alsa-lib-devel
- add '--disable-sqlite --disable-flac' options to %%configure

* Mon May 01 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.0.16-0vl2
- rebuilt for VineSeed Plus

* Mon May 01 2006 Ryoichi INAGAKI <ryo1@bc.wakwak.com> 1.0.16-0vl1
- new upstream release
- fixed Japanese summary

* Wed Feb 08 2006 Atsushi SHICHI <ats7@a.email.ne.jp> 1.0.13-1vl1
- initial build for VinePlus/3.0
- modified spec file

* Sun May 15 2005 Erik de Castro Lopo <erikd@mega-nerd.com>
- Add html files to the files section.

* Tue Sep 16 2003 Erik de Castro Lopo <erikd@mega-nerd.com>
- Apply corrections from Andrew Schultz.

* Mon Oct 21 2002 Erik de Castro Lopo <erikd@mega-nerd.com>
- Force installation of sndfile.pc file.

* Thu Jul 6 2000 Josh Green <jgreen@users.sourceforge.net>
- Created libsndfile.spec.in


# end of file