SUMMARY="Provides tools for creating and manipulating squashfs filesystems"
DESCRIPTION="squashfs-tools provides tools for creating and appending to \
(mksquashfs) and extracting (unsquashfs) squashfs filesystems.

Squashfs is a compressed read-only filesystem. It is intended for general \
read-only filesystem use, archival use (i.e. in cases where a .tar.gz file \
may be used, and in constrained block device/memory systems (e.g. embedded \
systems) where low overhead is needed."
HOMEPAGE="http://squashfs.sourceforge.net/"
COPYRIGHT="2002-2014 Philip Lougher"
LICENSE="GNU GPL v2"
REVISION="3"
SOURCE_URI="https://downloads.sf.net/squashfs/squashfs$portVersion.tar.gz"
CHECKSUM_SHA256="0d605512437b1eb800b4736791559295ee5f60177e102e4d4ccd0ee241a5f3f6"
SOURCE_DIR="squashfs$portVersion/squashfs-tools"

debianRevision="3"
SOURCE_FILENAME_2="squashfs-tools_$portVersion-$debianRevision+deb9u1.debian.tar.xz"
SOURCE_URI_2="http://httpredir.debian.org/debian/pool/main/s/squashfs-tools/$SOURCE_FILENAME_2"
CHECKSUM_SHA256_2="760fa5221778a851883b0843c9ee50662af0b33e6674909b79b8ab1312c6446a"

commit="dceb729f0369d72f1d7820705fd12510b71446d2"
patchsetBaseUri="https://gitweb.gentoo.org/repo/gentoo.git/plain/sys-fs/squashfs-tools/files"
SOURCE_FILENAME_3="squashfs-tools-$portVersion-2gb.patch"
SOURCE_FILENAME_4="squashfs-tools-$portVersion-aligned-data.patch"
SOURCE_FILENAME_5="squashfs-tools-$portVersion-local-cve-fix.patch"
SOURCE_FILENAME_6="squashfs-tools-$portVersion-mem-overflow.patch"
SOURCE_URI_3="$patchsetBaseUri/$SOURCE_FILENAME_3?id=$commit#noarchive"
SOURCE_URI_4="$patchsetBaseUri/$SOURCE_FILENAME_4?id=$commit#noarchive"
SOURCE_URI_5="$patchsetBaseUri/$SOURCE_FILENAME_5?id=$commit#noarchive"
SOURCE_URI_6="$patchsetBaseUri/$SOURCE_FILENAME_6?id=$commit#noarchive"
CHECKSUM_SHA256_3="cdb9c85c2f733c0db879275d0ee2480f528aa3191f236bbf1ff681c75b14a024"
CHECKSUM_SHA256_4="3030ddfa5ba9d0baea7f5e4761b33dea67fbc4d49c86e475830fc1bfbfddb145"
CHECKSUM_SHA256_5="7edceedead4f5a57dc009afecd0f414d60a3878dc43f8de5224bff391ed32c76"
CHECKSUM_SHA256_6="a94f9df3439bef373da31a734e6dad42f5fc5a6d91f2b9d15d30b02f1aac73b3"

PATCHES="
	squashfs_tools-$portVersion-haiku-compat.patch
	squashfs_tools-$portVersion-gcc2.patch
	"

ARCHITECTURES="all"
SECONDARY_ARCHITECTURES="x86_gcc2 x86"

if [ "$effectiveTargetArchitecture" != x86_gcc2 ]; then
	HAVE_XZ=1
else
	HAVE_XZ=
fi

PROVIDES="
	squashfs_tools$secondaryArchSuffix = $portVersion
	cmd:mksquashfs$secondaryArchSuffix = $portVersion
	cmd:unsquashfs$secondaryArchSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:liblz4$secondaryArchSuffix
	${HAVE_XZ:+lib:liblzma$secondaryArchSuffix}
	lib:liblzo2$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:liblz4$secondaryArchSuffix
	${HAVE_XZ:+devel:liblzma$secondaryArchSuffix}
	devel:liblzo2$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:gcc$secondaryArchSuffix
	cmd:make
	"

MAKE_ARGS="
	LZ4_SUPPORT=1
	LZMA_XZ_SUPPORT=${HAVE_XZ:+1}
	LZO_SUPPORT=1
	XATTR_SUPPORT=0
	XZ_SUPPORT=${HAVE_XZ:+1}
	"

PATCH()
{
	patch -p2 -i $sourceDir2/debian/patches/0002-*.patch
	patch -p2 -i $sourceDir2/debian/patches/0003-*.patch
	patch -p2 -i $sourceDir2/debian/patches/0004-*.patch
	patch -p2 -i $sourceDir2/debian/patches/0006-*.patch
	# previously applied) patch detected?
	# patch -p2 -i $sourceDir2/debian/patches/0007-*.patch
	patch -p2 -i $sourceDir3/$SOURCE_FILENAME_3
	patch -p2 -i $sourceDir4/$SOURCE_FILENAME_4
	patch -p2 -i $sourceDir6/$SOURCE_FILENAME_6
	# This one patch requires -p1
	patch -p1 -i $sourceDir5/$SOURCE_FILENAME_5
}

BUILD()
{
	make $MAKE_ARGS $jobArgs
}

INSTALL()
{
	make install $MAKE_ARGS INSTALL_DIR=$binDir

	install -d -m 755 $manDir/man1
	install -m 444 -t $manDir/man1 $sourceDir2/debian/manpages/*.1
}
