SUMMARY="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="https://sourceware.org/bzip2/"
COPYRIGHT="1996-2019 Julian R Seward"
LICENSE="bzip2"
REVISION="1"
SOURCE_URI="https://sourceware.org/pub/bzip2/bzip2-$portVersion.tar.gz"
CHECKSUM_SHA256="ab5a03176ee106d3f0fa90e381da478ddae405918153cca248e682cd0c4a2269"
PATCHES="bzip2-$portVersion.patchset"

ARCHITECTURES="all"
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
	"

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

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

debugList=("$libDir"/libbz2.so.$portVersion)
if [ -z "$secondaryArchSuffix" ]; then
	debugList+=("$binDir"/bzip2)
	debugList+=("$binDir"/bzip2recover)
fi
defineDebugInfoPackage bzip2$secondaryArchSuffix "${debugList[@]}"

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.$portVersion libbz2.so
	cp -a libbz2.so.$portVersion 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
}

TEST()
{
	make test
}
