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

inherit eutils versionator

MY_PV="$(replace_version_separator '.' '_')"

DESCRIPTION="Analyzing and Visualizing Evolutionary Data"
HOMEPAGE="http://www.splitstree.org/"
SRC_URI="http://www-ab.informatik.uni-tuebingen.de/software/splitstree4/V${MY_PV}/${PN}_unix_${MY_PV}.sh"
RESTRICT="mirror"

LICENSE="as-is"
SLOT="4"
KEYWORDS="x86 ~amd64"
IUSE=""

RDEPEND=">=virtual/jre-1.4.2"
DEPEND=""

S="${WORKDIR}"

src_unpack() {
	offset=$(grep -a -m 1 -o '^tail -n +[0-9]\+ "$prg_dir' "${DISTDIR}/${A}" | \
		sed 's:^tail -n +::;s: "$prg_dir::')
	[[ -n ${offset} ]] || die "could not determine offset for tail"

	tail -n +${offset} "${DISTDIR}/${A}" | tar -C ${T} -xzf -
	unzip -q ${T}/content.zip

	rm -rf .install4j* uninstall SplitsTree
	chmod 644 *

	for f in * ; do
		g=${f//\\/\/}
		if [[ "$g" == "$f" ]]; then
			continue
		fi
		if [[ -d "$f" ]]; then
			rmdir "$f"
			mkdir -p "$g"
		else
			mv "$f" "$g"
		fi
	done

	cat <<EOF > SplitsTree
#!/bin/bash
classpath="/opt/${PN}/class"
for f in /opt/${PN}/jars/*.jar; do
	classpath="\$classpath:\$f"
done
exec \$(java-config --java) -server -Xmx400M -cp "\$classpath" \\
	splits.main.SplitsTree
EOF
}

src_compile() {
	einfo "this is a binary package"
}

src_install() {
	insinto /opt/${PN}
	doins -r *
	fperms 755 /opt/${PN}/SplitsTree
	dosym /opt/${PN}/SplitsTree \
		/usr/bin/${PN}
	dosym /opt/${PN}/class/resources/icons/SplitsTree32.png \
		/usr/share/pixmaps/${PN}.png
	make_desktop_entry ${PN} "SplitsTree4"
}
