SUMMARY="Checks and undeletes partitions and a signature based recovery tool"
DESCRIPTION="TestDisk is powerful free data recovery software\! \
It was primarily designed to help recover lost partitions and/or \
make non-booting disks bootable again when these symptoms are caused \
by faulty software: certain types of viruses or human error \
(such as accidentally deleting a Partition Table). \
Partition table recovery using TestDisk is really easy. \

TestDisk features:

- Fix partition table, recover deleted partition
- Recover FAT32 boot sector from its backup
- Rebuild FAT12/FAT16/FAT32 boot sector
- Fix FAT tables
- Rebuild NTFS boot sector
- Recover NTFS boot sector from its backup
- Fix MFT using MFT mirror
- Locate ext2/ext3/ext4 Backup SuperBlock
- Undelete files from FAT, exFAT, NTFS and ext2 filesystem
- Copy files from deleted FAT, exFAT, NTFS and ext2/ext3/ext4 partitions.

TestDisk has features for both novices and experts.
For those who know little or nothing about data recovery techniques, \
TestDisk can be used to collect detailed information about a \
non-booting drive which can then be sent to a tech for further analysis. \
Those more familiar with such procedures should find TestDisk a handy \
tool in performing onsite recovery."
HOMEPAGE="https://www.cgsecurity.org/wiki/TestDisk"
COPYRIGHT="1998-2018 Christophe GRENIER"
LICENSE="GNU GPL v2"
REVISION="3"
SOURCE_URI="https://www.cgsecurity.org/testdisk-$portVersion.tar.bz2"
CHECKSUM_SHA256="1413c47569e48c5b22653b943d48136cb228abcbd6f03da109c4df63382190fe"

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

commandSuffix=$secondaryArchSuffix
commandBinDir=$binDir
if [ "$targetArchitecture" = x86_gcc2 ]; then
	commandSuffix=
	commandBinDir=$prefix/bin
fi

#TODO: add SVG icon to qphotorec
#TODO: require libntfs3g, ext2fs, reiserfs

PROVIDES="
	testdisk$secondaryArchSuffix = $portVersion
	cmd:fidentify$commandSuffix = $portVersion
	cmd:photorec$commandSuffix = $portVersion
	cmd:testdisk$commandSuffix = $portVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libuuid$secondaryArchSuffix >= 1.3
	lib:libz$secondaryArchSuffix
	"

PROVIDES_qt="
	testdisk${secondaryArchSuffix}_qt = $portVersion
	cmd:qphotorec$commandSuffix = $portVersion
	"
REQUIRES_qt="
	haiku$secondaryArchSuffix
	testdisk$secondaryArchSuffix == $portVersion base
	lib:libiconv$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libncurses$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5Gui$secondaryArchSuffix
	lib:libQt5Widgets$secondaryArchSuffix
	lib:libuuid$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:libiconv$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libncurses$secondaryArchSuffix
	devel:libQt5Core$secondaryArchSuffix
	devel:libQt5Gui$secondaryArchSuffix
	devel:libQt5Widgets$secondaryArchSuffix
	devel:libuuid$secondaryArchSuffix >= 1.3
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:aclocal
	cmd:autoconf
	cmd:automake
	cmd:gcc$secondaryArchSuffix
	cmd:make
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:pkg_config$secondaryArchSuffix
	"

BUILD()
{
	export CXXFLAGS="-std=c++11"
	autoreconf -fi
	LIBS="-lintl" \
	runConfigure --omit-dirs binDir ./configure --bindir="$commandBinDir" \
		--disable-stack-protector
	make $jobArgs
}

INSTALL()
{
	make install

	addAppDeskbarSymlink $prefix/bin/qphotorec "QPhotoRec"

	# cleanup XDG stuff we do not need
	rm -R $dataDir/applications
	rm -R $dataDir/icons

	packageEntries qt \
		$prefix/bin/qphotorec \
		$manDir/*/qphotorec.* \
		$manDir/*/*/qphotorec.* \
		$dataDir/deskbar/menu/Applications/QPhotoRec
}

TEST()
{
	make check
}
