SUMMARY="Free implementation of rsync remote-delta algorithm"
DESCRIPTION="librsync is a free software library that implements the \
rsync remote-delta algorithm.  This algorithm allows efficient remote \
updates of a file, without requiring the old and new versions to \
both be presentat the sending end.  The library uses a \"streaming\" \
design similar to that of zlib with the aim of allowing it to be embedded \
into many different applications."
HOMEPAGE="https://github.com/librsync/librsync"
COPYRIGHT="1995 Patrick Powell
	1996-1999 Andrew Tridgell
	1996 Paul Mackerras
	1999-2014 Martin Pool
	2002-2003 Donovan Baarda"
LICENSE="GNU LGPL v2.1"
REVISION="4"
SOURCE_URI="https://github.com/librsync/librsync/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256='b5c4dd114289832039397789e42d4ff0d1108ada89ce74f1999398593fae2169'
if [ $effectiveTargetArchitecture = x86_gcc2 ]; then
	PATCHES="librsync-$portVersion.patchset"
fi

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

PROVIDES="
	$portName = $portVersion
	cmd:rdiff$secondaryArchSuffix = $portVersion
	lib:librsync$secondaryArchSuffix = 2.0.0 compat >= 2
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:libpopt$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

# Although the librsync soname is bumped to 2.0.0, it is purely an ABI change,
# so the compat level for the devel package remains at 1.
PROVIDES_devel="
	${portName}_devel = $portVersion compat >= 1
	devel:librsync$secondaryArchSuffix = 2.0.0 compat >= 1
	"
REQUIRES_devel="
	librsync$secondaryArchSuffix == $portVersion base
	lib:libbz2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:libpopt$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:cmake
	cmd:make
	cmd:perl
	"

BUILD()
{
	mkdir -p build
	cd build
	cmake -DCMAKE_INSTALL_PREFIX=$prefix -DCMAKE_BUILD_TYPE=release ..
	make $jobArgs
}

INSTALL()
{
	make -C build install

	mkdir -p $includeDir
	mv $prefix/include/* $includeDir
	rmdir $prefix/include

	if [ -n "$secondaryArchSuffix" ]; then
		mv $prefix/lib $prefix/lib2
		mkdir -p $libDir
		mv $prefix/lib2/* $libDir/
		rmdir $prefix/lib2
	fi
	prepareInstalledDevelLibs librsync
	packageEntries devel \
		$developDir
}

TEST()
{
	cd build
	make -k test
}
