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

inherit eutils wxwidgets

DESCRIPTION="cave surveying tool for creating 2D/3D cave maps"
HOMEPAGE="http://therion.speleo.sk/"
SRC_URI="http://therion.speleo.sk/downloads/${P}.tar.gz"
RESTRICT="mirror"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="x86"
IUSE="loch"

RDEPEND=">=dev-lang/tk-8.4.3
	dev-tcltk/bwidget
	virtual/tetex"
DEPEND="${RDEPEND}
	media-gfx/imagemagick
	loch? (
		>=media-libs/freetype-2
		>=x11-libs/wxGTK-2.6
		>=sci-libs/vtk-5.0
	)
	dev-lang/perl"

S=${WORKDIR}/${PN}

src_compile() {
	if use loch ; then
		export WX_GTK_VER="2.8"
		need-wxwidgets gtk2
		sed -i "s: wx-config : ${WX_CONFIG} :;
			s:/usr/local:/usr:;
			s:-lvtkjpeg -lvtkpng -lvtkzlib::" loch/Makefile
	else
		sed -i 's: = loch/loch$: = :' Makefile
	fi

	VTK_PV=$(echo /usr/include/vtk-* | cut -c18-)
	sed -i "s:vtk-5.0:vtk-${VTK_PV}:" loch/Makefile

	emake || die "make failed"
}

src_install() {
	dobin therion xtherion/xtherion || die "dobin failed"
	if use loch ; then
		dobin loch/loch || die "dobin loch failed"
	fi

	make_desktop_entry xtherion "Therion"
	make_desktop_entry loch "Loch"

	insinto /etc
	doins therion.ini xtherion/xtherion.ini || die "doini failed"

	dodoc CHANGES README
	insinto /usr/share/doc/${PF}
	doins thbook/thbook.pdf || die "dopdf failed"
}
