SUMMARY="Decompression library for RAR, TAR, ZIP and 7z archives"
DESCRIPTION="unarr originated as a port of the RAR extraction features from \
The Unarchiver project required for extracting images from comic \
book archives (.cbr). It was written as an alternative to \
libarchive which didn't have support for parsing filters or solid \
compression at the time."
HOMEPAGE="https://github.com/sumatrapdfreader/sumatrapdf/tree/master/ext/unarr"
COPYRIGHT="The Unarchiver project
	Simon Bünzli
	Felix Kauselmann
	Bastien Nocera"
LICENSE="GNU LGPL v3"
REVISION="2"
SOURCE_URI="https://github.com/selmf/unarr/archive/v${portVersion}.tar.gz"
CHECKSUM_SHA256="0098e3f33182d16c13eb21278696651b170360a9a4d1c0214db4bd7882253223"

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

PROVIDES="
	unarr$secondaryArchSuffix = $portVersion
	lib:libunarr$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	unarr${secondaryArchSuffix}_devel = $portVersion
	devel:libunarr$secondaryArchSuffix = $portVersion
	"
REQUIRES_devel="
	unarr$secondaryArchSuffix == $portVersion base
	devel:liblzma$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libbz2$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:ar$secondaryArchSuffix
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:ranlib$secondaryArchSuffix
	"

defineDebugInfoPackage unarr$secondaryArchSuffix \
	$libDir/libunarr.so.1.0.0

PATCH()
{
	# fix a small typo in pkg-config.pc.cmake, fixed since in master branch,  but not in latest release yet
	# to remove at next release bump
	sed -i 's/@CMAKE_INSTALL_INCLUDEDIR_LIBDIR@/@CMAKE_INSTALL_LIBDIR@/g' pkg-config.pc.cmake
}

BUILD()
{
	mkdir -p build
	cd build

	# build static library
	cmake .. \
		-DCMAKE_BUILD_TYPE:STRING="Release" \
		-DBUILD_SHARED_LIBS=OFF \
		$cmakeDirArgs
	make $jobArgs

	# build shared library too
	cmake .. \
		-DCMAKE_BUILD_TYPE:STRING="Release" \
		-DBUILD_SHARED_LIBS=ON \
		$cmakeDirArgs
	make $jobArgs
}

INSTALL()
{
	mkdir -p $binDir $libDir $includeDir
	cp build/libunarr.a $libDir
	cp -P build/libunarr.so* $libDir
	cp unarr.h $includeDir

	mkdir -p $libDir/pkgconfig
	cp build/libunarr.pc $libDir/pkgconfig/libunarr.pc

	prepareInstalledDevelLib libunarr
	fixPkgconfig
	packageEntries devel \
		$developDir
}
