# Copyright 1999-2009 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"
inherit eutils

DESCRIPTION="Data recovery tool to fault-tolerantly extract data from damaged (io-errors) devices or files."
HOMEPAGE="http://safecopy.sourceforge.net"
SRC_URI="mirror://sourceforge/safecopy/${P}.tar.gz -> ${P}.tar.gz
http://sourceforge.net/tracker/download.php?group_id=141056&atid=748330&file_id=328461&aid=2796779 -> ${P}-amd64.patch.gz"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""

DEPEND=""

src_prepare() {
	epatch "${FILESDIR}"/${P}-sandbox.patch
	epatch "${WORKDIR}"/${P}-amd64.patch
}

src_install() {
	emake DESTDIR="${D}" install || die "make install failed"
	dodoc README || die "copying documentation failed"
}


src_test() {
	einfo "Test phase:"
	cd test/libsafecopydebug;
	einfo "Compiling safecopy test suite..."
	if ! { econf && emake; }; then
		cd ../..;
		if hasq test $FEATURES; then
			die 'Safecopy test suite wrapper library did not compile.'
		else
			eerror 'Safecopy test suite wrapper library did not compile.'
		fi;
	else
		cd ..;
		einfo "Running safecopy self test..."
		if ! ./test.sh; then
			cd ..;
			if hasq test $FEATURES; then
				die 'Safecopy blackbox self test failed. See above output for details.'
			else
				eerror 'Safecopy blackbox self test failed. See above output for details.'
			fi;
		else
			cd ..;
			einfo "Self-test run succeeded.";
		fi;
	fi;
}