SUMMARY="C library for reading and writing files containing sampled sound"
DESCRIPTION="
libsndfile is a library of C routines for reading and writing \
files containing sampled audio data.
"
HOMEPAGE="http://www.mega-nerd.com/libsndfile"
COPYRIGHT="
	1999-2011 Erik de Castro Lopo
"
LICENSE="GNU LGPL v2.1"
SOURCE_URI="http://www.mega-nerd.com/libsndfile/files/libsndfile-$portVersion.tar.gz"
CHECKSUM_SHA256="59016dbd326abe7e2366ded5c344c853829bebfd1702ef26a07ef662d6aa4882"
REVISION="3"
ARCHITECTURES="x86_gcc2 x86 x86_64"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

PATCHES="libsndfile-$portVersion.patchset"

PROVIDES="
	libsndfile$secondaryArchSuffix = $portVersion compat >= 1
	cmd:sndfile_cmp$secondaryArchSuffix
	cmd:sndfile_concat$secondaryArchSuffix
	cmd:sndfile_convert$secondaryArchSuffix
	cmd:sndfile_deinterleave$secondaryArchSuffix
	cmd:sndfile_info$secondaryArchSuffix
	cmd:sndfile_interleave$secondaryArchSuffix
	cmd:sndfile_metadata_get$secondaryArchSuffix
	cmd:sndfile_metadata_set$secondaryArchSuffix
	cmd:sndfile_play$secondaryArchSuffix
	cmd:sndfile_regtest$secondaryArchSuffix
	cmd:sndfile_salvage$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix = $portVersion compat >= 1
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libflac$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	"
BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libflac$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:find
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	libtoolize --force --copy --install
	aclocal -I M4
	autoconf
	automake
	if [ $effectiveTargetArchitecture = x86_gcc2 ]; then
		export CFLAGS=-O1
	fi
	runConfigure ./configure
	make $jobArgs
}

INSTALL()
{
	make install
	
	# remove libtool library files
	rm $libDir/libsndfile.la
	
	prepareInstalledDevelLibs libsndfile
	fixPkgconfig
	
	# The pkgconfig files reference other libraries using the wrong paths, which
	# creates a lot of confusion. Fix them so correct paths are used.
	local develPackageName="${portName}_devel-$portFullVersion"
	local packageLinksDir=$(dirname $portPackageLinksDir)
	local linksDir="$packageLinksDir/${develPackageName}/devel~libflac$secondaryArchSuffix/$relativeDevelopLibDir"
	sed -i -e "s,^\(Libs.private.*\)-L.* \(-lFLAC.*\)$,\1-L$linksDir \2," \
		$developLibDir/pkgconfig/sndfile.pc
	linksDir="$packageLinksDir/${develPackageName}/devel~libvorbis$secondaryArchSuffix/$relativeDevelopLibDir"
	sed -i -e "s,^\(Libs.private.* -lFLAC .*\) -L.* \(-lvorbis.*\)$,\1-L$linksDir \2," \
		$developLibDir/pkgconfig/sndfile.pc

	# devel package
	packageEntries devel \
		$developDir
}

# ----- devel package -------------------------------------------------------

PROVIDES_devel="
	libsndfile${secondaryArchSuffix}_devel = $portVersion compat >= 1
	devel:libsndfile$secondaryArchSuffix = $portVersion compat >= 1
	"
REQUIRES_devel="
	libsndfile$secondaryArchSuffix == $portVersion base
	devel:libflac$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	"
