SUMMARY="An audio time-stretching and pitch-shifting library"
DESCRIPTION="Rubber Band is a library and utility program that permits \
changing the tempo and pitch of an audio recording independently of one \
another."
HOMEPAGE="https://www.breakfastquay.com/rubberband/"
COPYRIGHT="2007-2018 Particular Programs Ltd"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://breakfastquay.com/files/releases/rubberband-$portVersion.tar.bz2"
CHECKSUM_SHA256="86bed06b7115b64441d32ae53634fcc0539a50b9b648ef87443f936782f6c3ca"
PATCHES="rubberband-$portVersion.patchset"

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

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

libVersion="2.1.1"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	rubberband$secondaryArchSuffix = $portVersion
	cmd:rubberband$commandSuffix = $portVersion
	lib:librubberband$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libfftw3$secondaryArchSuffix
	lib:libsamplerate$secondaryArchSuffix
	lib:libsndfile$secondaryArchSuffix
	lib:libvamp_sdk$secondaryArchSuffix
	"

PROVIDES_devel="
	rubberband${secondaryArchSuffix}_devel = $portVersion
	devel:librubberband$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	rubberband$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libfftw3$secondaryArchSuffix
	devel:libsamplerate$secondaryArchSuffix
	devel:libsndfile$secondaryArchSuffix
	devel:libvamp_sdk$secondaryArchSuffix
	ladspa_sdk${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage rubberband$secondaryArchSuffix \
	"$commandBinDir"/rubberband \
	"$libDir"/librubberband.so.$libVersion \
	"$libDir"/ladspa/ladspa-rubberband.so \
	"$libDir"/vamp/vamp-rubberband.so \

PATCH()
{
	# Don't try to install $(JNI_TARGET) if it was not built.
	# (It can't be built without javac.)
	sed -i \
		-e "s/cp -f \(\$(JNI_TARGET)\) \$(DESTDIR).*/@[ -f \1 ] \&\& & || true/;" \
		-e "/^INSTALL_BINDIR/ s|\(\$(PREFIX)/\)bin$|\1$relativeCommandBinDir|;" \
		-e "/^INSTALL_INCDIR/ s|\(\$(PREFIX)/\)include/|\1$relativeIncludeDir/|;" \
		-e "/^INSTALL_LRDFDIR/ s|\(\$(PREFIX)/\)share/|\1$relativeDataDir/|;" \
		-e "/^INSTALL_/ s|\(\$(PREFIX)/\)lib|\1$relativeLibDir|;" \
		Makefile.in
}

BUILD()
{
	autoreconf -fi
	runConfigure --omit-dirs binDir ./configure --bindir=$commandBinDir
	make $jobArgs
}

INSTALL()
{
	make install

	prepareInstalledDevelLibs librubberband
	fixPkgconfig

	# devel package
	packageEntries devel \
		$developDir
}

TEST()
{
	bin/rubberband --version
}
