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-2016 Dieter Baron and Thomas Klausner"
LICENSE="BSD (3-clause)"
REVISION="2"
SOURCE_URI="http://www.nih.at/libzip/libzip-$portVersion.tar.gz"
CHECKSUM_SHA256="1faa5a524dd4a12c43b6344e618edce1bf8050dfdb9d0f73f3cc826929a002b0"
PATCHES="libzip-$portVersion.patchset"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

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

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

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

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:autoheader
	cmd:make
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	"

PATCH()
{
	sed -i -e 's/^LN=ln -f$/&rs/' man/Makefile.am
}

BUILD()
{
	runConfigure ./configure --disable-static
	make $jobArgs
}

INSTALL()
{
	make install

	prepareInstalledDevelLibs libzip
	fixPkgconfig

	# Move zipconf.h from lib/libzip/include/ to develop/headers/libzip/
	mkdir -p $includeDir/libzip
	mv $libDir/libzip/include/zipconf.h $includeDir/libzip
	rmdir $libDir/libzip/include $libDir/libzip

	# Adjust libincludedir to make it point to where zipconf.h was moved.
	sed -i -e "s,^\(libincludedir=\)$libDir"'\(/libzip\)/include$,\1${prefix}/'"${relativeIncludeDir}\2," \
		$developLibDir/pkgconfig/libzip.pc

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

	# devel package
	packageEntries devel \
		$developDir \
		$maybe_manDir_man3
}

TEST()
{
	make check
}
