SUMMARY="bzip2 data compression utilities and libraries"
DESCRIPTION="
bzip2 is a patent free, high-quality data compressor. It typically compresses \
files to within 10% to 15% of the best available techniques (the PPM family of \
statistical compressors), whilst being around twice as fast at compression and \
six times faster at decompression. bzip2 supports recovery from media errors \
as well. Its command line flags are similar to those of GNU Gzip.
"
HOMEPAGE="http://www.bzip.org/"
LICENSE="bzip2"
COPYRIGHT="1996-2010 Julian R Seward"
SOURCE_URI="http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz"
CHECKSUM_SHA256="a2848f34fcd5d6cf47def00461fcb528a0484d8edef8208d6d2e2909dc61d9cd"
REVISION="5"
ARCHITECTURES="x86_gcc2 x86 x86_64 arm"
SECONDARY_ARCHITECTURES="x86 x86_gcc2"

PROVIDES="
	bzip2$secondaryArchSuffix = $portVersion compat >= 1
	lib:libbz2$secondaryArchSuffix = $portVersion compat >= 1.0
	"

if [ -z "$secondaryArchSuffix" ]; then
PROVIDES="$PROVIDES
	cmd:bzcat = $portVersion compat >= 1
	cmd:bzcmp = $portVersion compat >= 1
	cmd:bzdiff = $portVersion compat >= 1
	cmd:bzegrep = $portVersion compat >= 1
	cmd:bzfgrep = $portVersion compat >= 1
	cmd:bzgrep = $portVersion compat >= 1
	cmd:bzip2 = $portVersion compat >= 1
	cmd:bzip2recover = $portVersion compat >= 1
	cmd:bzless = $portVersion compat >= 1
	cmd:bzmore = $portVersion compat >= 1
	cmd:bunzip2 = $portVersion compat >= 1
	"
fi

REQUIRES="
	haiku$secondaryArchSuffix
	"
BUILD_REQUIRES="
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:ar
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:make
	cmd:sed
	"


BUILD()
{
	make $jobArgs
	make $jobArgs -f Makefile-libbz2_so
		# shared libary not built by default
}

INSTALL()
{
	make install PREFIX=$prefix

	mkdir -p $libDir

	#move the static library to the right dir for secondary arch builds
	if [ -n "$secondaryArchSuffix" ];then
		mv $prefix/lib/libbz2.a $libDir
	fi

	# also install shared lib
	ln -sf libbz2.so.1.0.6 libbz2.so
	cp -a libbz2.so.1.0.6 libbz2.so.1.0 libbz2.so $libDir

	# move man pages
	mkdir -p $manDir
	mv $prefix/man/* $manDir
	rmdir $prefix/man

	# move headers
	bzip2IncludeDir=$includeDir
	mkdir -p $bzip2IncludeDir
	mv $prefix/include/* $bzip2IncludeDir
	rmdir $prefix/include

	# prepare development lib links
	prepareInstalledDevelLibs libbz2

	# devel package
	packageEntries devel \
		$developDir

	#remove bin commands and man pages when building for secondary arch
	if [ -n "$secondaryArchSuffix" ];then
		rm -rf $prefix/bin
		rm -rf $manDir
	fi
}

# ----- devel package -------------------------------------------------------

PROVIDES_devel="
	bzip2${secondaryArchSuffix}_devel = $portVersion compat >= 1
	devel:libbz2$secondaryArchSuffix = $portVersion compat >= 1.0
	"
REQUIRES_devel="
	bzip2$secondaryArchSuffix == $portVersion base
	"
