SUMMARY="A C library for reading, creating, and modifying zip archives"
DESCRIPTION="libzip is a C library for reading, creating, and modifying zip \
archives."
HOMEPAGE="http://www.nih.at/libzip/"
COPYRIGHT="1999-2020 Dieter Baron and Thomas Klausner"
LICENSE="BSD (3-clause)"
REVISION="1"
SOURCE_URI="http://www.nih.at/libzip/libzip-$portVersion.tar.gz"
CHECKSUM_SHA256="30ee55868c0a698d3c600492f2bea4eb62c53849bcf696d21af5eb65f3f3839e"
PATCHES="libzip-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

PROVIDES="
	libzip$secondaryArchSuffix = $portVersion
	lib:libzip$secondaryArchSuffix = 5.0.0 compat >= 5.0.0
	"
if [ -z "$secondaryArchSuffix" ]; then
	PROVIDES="$PROVIDES
		cmd:zipcmp
		cmd:zipmerge
		cmd:ziptool
		"
fi

REQUIRES="
	haiku$secondaryArchSuffix
#	lib:libbz2$secondaryArchSuffix
#	lib:liblzma$secondaryArchSuffix
#	lib:libnettle$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
#	lib:libzstd$secondaryArchSuffix
	"

PROVIDES_devel="
	libzip${secondaryArchSuffix}_devel = $portVersion
	devel:libzip$secondaryArchSuffix = 5.0.0 compat >= 5.0.0
	"
REQUIRES_devel="
	libzip$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
#	devel:libbz2$secondaryArchSuffix
#	devel:liblzma$secondaryArchSuffix
#	devel:libnettle$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
#	devel:libzstd$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:gcc$secondaryArchSuffix
	cmd:grep
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:sed
	"

TEST_REQUIRES="
	cmd:diff
	cmd:find
	"

BUILD()
{
	rm -rf build
	cmake -B build -S . \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_INCLUDEDIR=$includeDir \
		-DDOCUMENTATION_FORMAT=man \
		$cmakeDirArgs
	make -C build $jobArgs
}

INSTALL()
{
	make -C build install

	# Move zipconf.h from include/ to develop/headers/
	mv $prefix/include/zipconf.h $includeDir
	rm -rf $prefix/include

	prepareInstalledDevelLibs libzip
	fixPkgconfig

	if [ -z "$secondaryArchSuffix" ]; then
		maybe_manDir_man3=$manDir/man3
	else
		maybe_manDir_man3=
		rm -rf $prefix/bin
		rm -rf $documentationDir
	fi

	# devel package
	packageEntries devel \
		$developDir \
		$libDir/cmake \
		$maybe_manDir_man3
}

TEST()
{
	make -C build check
}
