# SliTaz package receipt.

PACKED_SIZE="60.0K"
UNPACKED_SIZE="152.0K"
PACKAGE="lzma"
VERSION="4.57"
CATEGORY="base-system"
SHORT_DESC="Compressor with a high compression ratio."
MAINTAINER="pascal.bellard@slitaz.org"
LICENSE="LGPL2.1"
TARBALL="lzma$(echo $VERSION | sed 's/\.//').tar.bz2"
WEB_SITE="https://sourceforge.net/projects/sevenzip/"
WGET_URL="$SF_MIRROR/sevenzip/$TARBALL"
TAGS="compression archive"
HOST_ARCH="i486 arm"

DEPENDS="lzlib zlib gcc-lib-base"

# What is the latest version available today?
current_version()
{
	wget -O - https://sourceforge.net/projects/sevenzip/files/LZMA%20SDK/ 2>/dev/null | \
	sed '/scope="row/!d;s|.*a href="|"https://sourceforge.net|;s| .*||;q' | xargs wget -O - 2>/dev/null | \
	sed "/$PACKAGE/!d;/tar/!d;s|.*$PACKAGE\\(.\\)\\(.*\\).tar.*\".*|\\1.\\2|;q"
}

# Rules to configure and make the package.
compile_rules()
{
	if [ ! -f done.lzlib.u ]; then
		patch -p0 < $stuff/lzlib.u || return 1
		touch done.lzlib.u
	fi
	cd CPP/7zip/Compress/LZMA_Alone
	
	# Handle cross compilation
	case "$ARCH" in
		arm)
			sed -i s'/g++/arm-slitaz-linux-gnueabi-c++/' makefile.gcc
			sed -i s'/gcc/arm-slitaz-linux-gnueabi-gcc/' makefile.gcc ;;
	esac

	# Remove copyright message.
	sed '/MY_VERSION_COPYRIGHT_DATE/d' -i LzmaAlone.cpp

	make -f makefile.gcc lzma 2> /dev/null
	make -f makefile.gcc liblz.so.1.0.0 &&
	make -f makefile.gcc lzma
}


# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/bin
	cp -a $src/CPP/7zip/Compress/LZMA_Alone/lzma-shared $fs/usr/bin/lzma-alone
	cp $stuff/lzma $fs/usr/bin
	chmod 755 $fs/usr/bin/lzma
	ln -s lzma $fs/usr/bin/unlzma
	ln -s lzma $fs/usr/bin/lzcat
}

post_remove()
{
	ln -s /bin/busybox "$1/usr/bin/unlzma"
	ln -s /bin/busybox "$1/usr/bin/lzcat"
}
