SUMMARY="Lossless data compressor based on the LZMA algorithm"
DESCRIPTION="Lzip is a lossless data compressor with a user interface \
similar to the one of gzip or bzip2. Lzip is about as fast as gzip, \
compresses most files more than bzip2, and is better than both \
from a data recovery perspective. Lzip is a clean implementation \
of the LZMA \"algorithm\".

The lzip file format is designed for data sharing and long-term \
archiving, taking into account both data integrity and decoder \
availability:

- The lzip format provides very safe integrity checking and some \
data recovery means. The lziprecover program can repair bit-flip \
errors (one of the most common forms of data corruption) in lzip \
files, and provides data recovery capabilities, including \
error-checked merging of damaged copies of a file.
- The lzip format is as simple as possible (but not simpler). \
The lzip manual provides the code of a simple decompressor along \
with a detailed explanation of how it works, so that with the only \
help of the lzip manual it would be possible for a digital \
archaeologist to extract the data from a lzip file long after \
quantum computers eventually render LZMA obsolete.
- Additionally the lzip reference implementation is copylefted, \
which guarantees that it will remain free forever."
HOMEPAGE="http://www.nongnu.org/lzip/lzip.html"
COPYRIGHT="2008-2018 Antonio Diaz Diaz"
LICENSE="GNU GPL v2"
REVISION="1"
SOURCE_URI="https://download.savannah.gnu.org/releases/lzip/lzip-$portVersion.tar.gz"
CHECKSUM_SHA256="4792c047ddf15ef29d55ba8e68a1a21e0cb7692d87ecdf7204419864582f280d"

ARCHITECTURES="all !x86_gcc2"
if [ "$targetArchitecture" = x86_gcc2 ]; then
SECONDARY_ARCHITECTURES="x86"
fi

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

PROVIDES="
	lzip$secondaryArchSuffix = $portVersion
	cmd:lzip = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	cmd:cmp
	cmd:g++$secondaryArchSuffix
	cmd:make
	"

BUILD()
{
	./configure --prefix=$prefix \
		--bindir=$commandBinDir \
		--datarootdir=$dataRootDir \
		--infodir=$infoDir \
		--mandir=$manDir
	make $jobArgs
}

INSTALL()
{
	make install

	# Create expander rule
	mkdir -p $dataDir/expander/rules
	echo '"application/x-lzip"	.tar.lz	"'$binDir/'lzip -cd %s | tar -tvf -"	"'$binDir/'lzip -cd %s | tar -xvf -"' > $dataDir/expander/rules/lzip
	echo '"application/x-lzip"	.tlz	"'$binDir/'lzip -cd %s | tar -tvf -"	"'$binDir/'lzip -cd %s | tar -xvf -"' >> $dataDir/expander/rules/lzip
	echo '"application/x-lzip"	.lz	"echo %s | sed '\''s/.lz$//g'\''"	"'$binDir/'lzip -df %s"' >> $dataDir/expander/rules/lzip
}

TEST()
{
	make check
}
