%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.25
Release:        2%{?_dist_release}

License:	LGPLv2+ and GPLv2+ and BSD
Group:          System Environment/Libraries
URL:            http://www.mega-nerd.com/libsndfile/

Source0:	http://www.mega-nerd.com/libsndfile/%{name}-%{version}.tar.gz
Patch0:		%{name}-1.0.25-system-gsm.patch
Patch1:		libsndfile-1.0.25-zerodivfix.patch

# security fix
Patch100:	libsndfile-1.0.21_CVE-2011-2696.patch
Patch101:	libsndfile-1.0.25-cve2014_9496.patch

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

Vendor:		Project Vine
Distribution:	Vine Linux

%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: Development/Libraries
Requires: %{name} = %{version}-%{release}
Requires: pkgconfig

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


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

%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: Development/Libraries
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.


%prep
%setup -q 
%patch0 -p1
%patch1 -p1 -b .zerodivfix

# security fix
%patch100 -p1 -b .CVE-2011-2696
%patch101 -p1 -b .cve2014_9496

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
rm -rf $RPM_BUILD_ROOT
make install DESTDIR=$RPM_BUILD_ROOT

rm -rf html
cp -pr $RPM_BUILD_ROOT%{_datadir}/doc/libsndfile1-dev html
rm -rf $RPM_BUILD_ROOT%{_datadir}/doc/libsndfile1-dev

rm -f $RPM_BUILD_ROOT%{_libdir}/lib*.la


# 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

%clean
rm -rf $RPM_BUILD_ROOT

%post -p /sbin/ldconfig

%postun -p /sbin/ldconfig

# compat32
%if %{build_compat32}
%post -n compat32-%{name} -p /sbin/ldconfig

%postun -n compat32-%{name} -p /sbin/ldconfig
%endif

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

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

# 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
* 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
