SUMMARY="C library for reading and writing of sampled sound"
DESCRIPTION="libsndfile is a library of C routines for reading and writing \
files containing sampled audio data."
HOMEPAGE="http://libsndfile.github.io/libsndfile/"
COPYRIGHT="1999-2021 Erik de Castro Lopo"
LICENSE="GNU LGPL v2.1"
REVISION="1"
SOURCE_URI="https://github.com/libsndfile/libsndfile/releases/download/$portVersion/libsndfile-$portVersion.tar.bz2"
CHECKSUM_SHA256="a8cfb1c09ea6e90eff4ca87322d4168cdbe5035cb48717b40bf77e751cc02163"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="!x86_gcc2 x86"

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_salvage$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix = $portVersion compat >= 1
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libflac$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libopus$secondaryArchSuffix
	lib:libspeex$secondaryArchSuffix
	lib:libvorbis$secondaryArchSuffix
	"

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libflac$secondaryArchSuffix
	devel:libogg$secondaryArchSuffix
	devel:libopus$secondaryArchSuffix
	devel:libspeex$secondaryArchSuffix
	devel:libvorbis$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	"

BUILD()
{
	if [ $effectiveTargetArchitecture = x86_gcc2 ]; then
		export CFLAGS=-O1
	fi
	cmake $cmakeDirArgs \
		  -DBUILD_SHARED_LIBS=TRUE \
		  .
	make $jobArgs
}

INSTALL()
{
	make install

	prepareInstalledDevelLibs libsndfile
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}
