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. 
"
LICENSE="GNU GPL v2"
COPYRIGHT="2014 Antonio Diaz Diaz"
HOMEPAGE="http://lzip.nongnu.org/lzip.html"
SOURCE_URI="http://download.savannah.gnu.org/releases/lzip/lzip-1.16.tar.gz"
CHECKSUM_SHA256="128cc25baf92c8b69700831e6f984d954016318cc78edca87870d0c033112751"
REVISION="1"
ARCHITECTURES="x86 ?x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
	# x86_gcc2 is fine as primary target architecture as long as we're building
	# for a different secondary architecture.
	ARCHITECTURES="$ARCHITECTURES x86_gcc2"
else
	ARCHITECTURES="$ARCHITECTURES !x86_gcc2"
fi
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

PROVIDES="
	lzip$secondaryArchSuffix = $portVersion
	cmd:lzip$commandSuffix = $portVersion
	"

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libgcc_s$secondaryArchSuffix
	lib:libstdc++$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	"

BUILD_PREREQUIRES="
	cmd:make
	cmd:gcc$secondaryArchSuffix
	"

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
}
