SUMMARY="Hybrid lossless audio compression format & tools"
DESCRIPTION="WavPack is a completely open audio compression format, providing \
lossless, high-quality lossy, and a unique hybrid compression mode."
HOMEPAGE="https://wavpack.com/"
COPYRIGHT="1998-2021 David Bryant"
LICENSE="WavPack"
REVISION="1"
SOURCE_URI="https://wavpack.com/wavpack-$portVersion.tar.bz2"
CHECKSUM_SHA256="0716a6dcf9a72d61005e1b09bbbd61aaf49837cb4e4a351992a6daed16cac034"

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

if [ "$targetArchitecture" != x86_gcc2 ]; then
	commandSuffix=$secondaryArchSuffix
	commandBinDir=$binDir
else
	commandSuffix=
	commandBinDir=$prefix/bin
fi

PROVIDES="
	wavpack$secondaryArchSuffix = $portVersion
	lib:libwavpack$secondaryArchSuffix = 1.2.0 compat >= 1
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_bin="
	wavpack${secondaryArchSuffix}_bin = $portVersion
	cmd:wavpack$commandSuffix = $portVersion
	cmd:wvgain$commandSuffix = $portVersion
	cmd:wvtag$commandSuffix = $portVersion
	cmd:wvunpack$commandSuffix = $portVersion
	"
REQUIRES_bin="
	haiku$secondaryArchSuffix
	wavpack$secondaryArchSuffix == $portVersion base
	lib:libiconv$secondaryArchSuffix
	"

PROVIDES_devel="
	wavpack${secondaryArchSuffix}_devel
	devel:libwavpack$secondaryArchSuffix = 1.2.0 compat >= 1
	"
REQUIRES_devel="
	wavpack$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:awk
	cmd:diff
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	"

PATCH()
{
	sed -i -e "/wpincludedir/ \
		s|/include\(/wavpack\)|/$relativeOldIncludeDir\1|" \
		include/Makefile.am
}

BUILD()
{
	aclocal
	libtoolize --force
	automake --add-missing
	autoconf
	runConfigure --omit-dirs binDir ./configure --bindir=$commandBinDir
	make $jobArgs
}

INSTALL()
{
	make install
	rm $libDir/libwavpack.la

	prepareInstalledDevelLib libwavpack
	fixPkgconfig

	packageEntries bin \
		$commandBinDir \
		$manDir

	packageEntries devel \
		$developDir
}

TEST()
{
	make check
}
