SUMMARY="The free lossless audio codec"
DESCRIPTION="FLAC stands for Free Lossless Audio Codec, an audio format \
similar to MP3, but lossless, meaning that audio is compressed in FLAC \
without any loss in quality. This is similar to how Zip works, except with \
FLAC you will get much better compression because it is designed specifically \
for audio, and you can play back compressed FLAC files in your favorite player \
(or your car or home stereo) just like you would an MP3 file."
HOMEPAGE="http://flac.sourceforge.net/"
COPYRIGHT="2000-2007 Josh Coalson"
LICENSE="GNU LGPL v2.1
	GNU GPL v2
	BSD (3-clause)"
REVISION="1"
SOURCE_URI="http://downloads.xiph.org/releases/flac/flac-$portVersion.tar.xz"
CHECKSUM_SHA256="8ff0607e75a322dd7cd6ec48f4f225471404ae2730d0ea945127b1355155e737"
PATCHES="flac-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

PROVIDES="
	flac$secondaryArchSuffix = $portVersion compat >= 1
	lib:libFLAC$secondaryArchSuffix = 8.3.0 compat >= 8
	lib:libFLAC++$secondaryArchSuffix = 6.3.0 compat >= 6
	"
if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES="$PROVIDES
		cmd:flac$secondaryArchSuffix
		cmd:metaflac$secondaryArchSuffix
		"
fi
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libogg$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	"

PROVIDES_devel="
	flac${secondaryArchSuffix}_devel = $portVersion compat >= 1
	devel:libFLAC$secondaryArchSuffix = 8.3.0 compat >= 8
	devel:libFLAC++$secondaryArchSuffix = 6.3.0 compat >= 6
	"
REQUIRES_devel="
	flac$secondaryArchSuffix == $portVersion base
	devel:libogg$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libogg$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:nasm
	cmd:ninja
	cmd:pkg_config$secondaryArchSuffix
	"
TEST_REQUIRES="
	cmd:cmp
	"

BUILD()
{
	cmake -S. -Bbuilddir -GNinja \
		-DCMAKE_BUILD_TYPE=Release \
		-DBUILD_SHARED_LIBS=ON \
		-DWITH_STACK_PROTECTOR=OFF \
		 $cmakeDirArgs
	echo "#include <inttypes.h>" >> builddir/config.h
	cmake --build builddir $jobArgs
}

INSTALL()
{
	cmake --install builddir

	install -Dm 644 src/*/*.m4 -t $dataDir/aclocal

	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $binDir $documentationDir
	fi
	prepareInstalledDevelLibs libFLAC libFLAC++
	fixPkgconfig

	# devel package
	packageEntries devel \
		$dataDir \
		$developDir
}

TEST()
{
	FLAC__TEST_LEVEL=0 cmake --build build --target test
}
