SUMMARY="Free general-purpose data compression software"
DESCRIPTION="XZ Utils are free general-purpose data compression tools with \
a high compression ratio. They are the successors to LZMA Utils."
HOMEPAGE="https://tukaani.org/xz/"
COPYRIGHT="2005-2018 Lasse Collin"
LICENSE="GNU LGPL v2.1
	GNU GPL v2
	GNU GPL v3"
REVISION="1"
SOURCE_URI="https://downloads.sourceforge.net/lzmautils/xz-$portVersion.tar.bz2"
CHECKSUM_SHA256="5117f930900b341493827d63aa910ff5e011e0b994197c3b71c08a20228a42df"
SOURCE_DIR="xz-$portVersion"
ADDITIONAL_FILES="xz_utils-expander-rules"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

# On x86_gcc2 we don't want to install the commands in bin/<arch>/, but in bin/.
commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

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

PROVIDES="
	xz_utils$secondaryArchSuffix = $portVersion compat >= 5
	cmd:lzcat$commandSuffix = $portVersionCompat
	cmd:lzcmp$commandSuffix = $portVersionCompat
	cmd:lzdiff$commandSuffix = $portVersionCompat
	cmd:lzegrep$commandSuffix = $portVersionCompat
	cmd:lzfgrep$commandSuffix = $portVersionCompat
	cmd:lzgrep$commandSuffix = $portVersionCompat
	cmd:lzless$commandSuffix = $portVersionCompat
	cmd:lzma$commandSuffix = $portVersionCompat
	cmd:lzmadec$commandSuffix = $portVersionCompat
	cmd:lzmainfo$commandSuffix = $portVersionCompat
	cmd:lzmore$commandSuffix = $portVersionCompat
	cmd:unlzma$commandSuffix = $portVersionCompat
	cmd:unxz$commandSuffix = $portVersionCompat
	cmd:xz$commandSuffix = $portVersionCompat
	cmd:xzcat$commandSuffix = $portVersionCompat
	cmd:xzcmp$commandSuffix = $portVersionCompat
	cmd:xzdec$commandSuffix = $portVersionCompat
	cmd:xzdiff$commandSuffix = $portVersionCompat
	cmd:xzegrep$commandSuffix = $portVersionCompat
	cmd:xzfgrep$commandSuffix = $portVersionCompat
	cmd:xzgrep$commandSuffix = $portVersionCompat
	cmd:xzless$commandSuffix = $portVersionCompat
	cmd:xzmore$commandSuffix = $portVersionCompat
	lib:liblzma$secondaryArchSuffix = $portVersion compat >= 5
	"
REQUIRES="
	haiku$secondaryArchSuffix
	"

PROVIDES_devel="
	xz_utils${secondaryArchSuffix}_devel = $portVersion compat >= 5
	devel:liblzma$secondaryArchSuffix = $portVersion compat >= 5
	"
REQUIRES_devel="
	haiku${secondaryArchSuffix}_devel
	xz_utils$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:libtoolize$secondaryArchSuffix
	cmd:make
	"

defineDebugInfoPackage xz_utils$secondaryArchSuffix \
	"$commandBinDir"/lzmadec \
	"$commandBinDir"/lzmainfo \
	"$commandBinDir"/xz \
	"$commandBinDir"/xzdec \
	"$libDir"/liblzma.so.$libVersion

BUILD()
{
	touch po/t-cs.gmo
	runConfigure --omit-dirs binDir ./configure --bindir=$commandBinDir
	make $jobArgs
}

INSTALL()
{
	make install

	# remove libtool file
	rm -f $libDir/liblzma.la

	fixPkgconfig

	expanderRulesDir=$dataDir/expander/rules
	mkdir -p $expanderRulesDir
	cp "$portDir/additional-files/xz_utils-expander-rules" \
		"$expanderRulesDir/xz_utils"

	prepareInstalledDevelLibs liblzma
	packageEntries devel \
		$developDir
}

TEST()
{
	make check
}
