SUMMARY="The zziplib extract data from archives in a single zip"
DESCRIPTION="Lightweight library used to easily extract data from \
files archived in a single zip file."
HOMEPAGE="http://zziplib.sourceforge.net/"
COPYRIGHT="1999-2010 Guido Draheim"
LICENSE="GNU LGPL v2.1
	MPL v1.1"
REVISION="1"
SOURCE_URI="https://github.com/gdraheim/zziplib/archive/v$portVersion.tar.gz"
CHECKSUM_SHA256="93ef44bf1f1ea24fc66080426a469df82fa631d13ca3b2e4abaeab89538518dc"
SOURCE_FILENAME="zziplib-v$portVersion.tar.gz"
PATCHES="zziplib-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86"

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

PROVIDES="
	zziplib$secondaryArchSuffix = $portVersion
	lib:libzzip_0$secondaryArchSuffix = $libVersionCompat
	lib:libzzipfseeko_0$secondaryArchSuffix = $libVersionCompat
	lib:libzzipmmapped_0$secondaryArchSuffix = $libVersionCompat
	lib:libzzipwrap_0$secondaryArchSuffix = $libVersionCompat
	"
if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES="$PROVIDES
		cmd:unzip_mem$secondaryArchSuffix = $portVersion
		cmd:unzzip$secondaryArchSuffix = $portVersion
		cmd:unzzip_big$secondaryArchSuffix = $portVersion
		cmd:unzzip_mem$secondaryArchSuffix = $portVersion
		cmd:unzzip_mix$secondaryArchSuffix = $portVersion
		cmd:zzcat$secondaryArchSuffix = $portVersion
		cmd:zzdir$secondaryArchSuffix = $portVersion
		cmd:zzxorcat$secondaryArchSuffix = $portVersion
		cmd:zzxorcopy$secondaryArchSuffix = $portVersion
		cmd:zzxordir$secondaryArchSuffix = $portVersion
	"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_devel="
	zziplib${secondaryArchSuffix}_devel = $portVersion
	devel:libzzip$secondaryArchSuffix = $libVersionCompat
	devel:libzzip_0$secondaryArchSuffix = $libVersionCompat
	devel:libzzipfseeko$secondaryArchSuffix = $libVersionCompat
	devel:libzzipfseeko_0$secondaryArchSuffix = $libVersionCompat
	devel:libzzipmmapped$secondaryArchSuffix = $libVersionCompat
	devel:libzzipmmapped_0$secondaryArchSuffix = $libVersionCompat
	devel:libzzipwrap$secondaryArchSuffix = $libVersionCompat
	devel:libzzipwrap_0$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	zziplib$secondaryArchSuffix == $portVersion base
	devel:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	cmd:python3
	cmd:sed
	cmd:tar
	cmd:zip
	"

PATCH()
{
	sed -e "/def\ test_59800/,/self.rm_testdir/d" \
		-e "/def\ test_65430/,/self.rm_testdir/d" \
		-e "/def\ test_65440/,/self.rm_testdir/d" \
		-e "/def\ test_65460/,/self.rm_testdir/d" \
		-e "/def\ test_65470/,/self.rm_testdir/d" \
		-e "/def\ test_65480/,/self.rm_testdir/d" \
		-e "/def\ test_65485/,/self.rm_testdir/d" \
		-i test/zziptests.py
}

BUILD()
{
	mkdir -p build && cd build
	cmake $cmakeDirArgs ..
	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	# remove commands for secondary architecture
	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $binDir $documentationDir
	fi

	prepareInstalledDevelLibs \
		libzzip-0 \
		libzzipfseeko-0 \
		libzzipmmapped-0 \
		libzzipwrap-0 \
		libzzip \
		libzzipfseeko \
		libzzipmmapped \
		libzzipwrap
	fixPkgconfig

	if [ -n "$secondaryArchSuffix" ]; then
		rm -rf $manDir
		maybe_manDir=
	else
		maybe_manDir=$manDir
	fi

	packageEntries devel \
		$developDir \
		$dataDir \
		$maybe_manDir
}

TEST()
{
	cd build
	make check
}
