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

inherit eutils wxwidgets

DESCRIPTION="Cave Surveying Software"
HOMEPAGE="http://www.survex.com/"
SRC_URI="http://www.survex.com/software/${PV}/${P}.tar.gz"
LICENSE="GPL-2"

KEYWORDS="~alpha ~amd64 ~arm ~hppa ~ia64 ~mips ~ppc ~s390 ~sparc x86"
SLOT="0"

IUSE="svxedit profile vim"
DEPEND=">=x11-libs/wxGTK-2.4"
RDEPEND="${DEPEND}
	svxedit? ( dev-tcltk/bwidget )"

pkg_setup() {
	# no unicode please!
	need-wxwidgets gtk2
}

src_compile() {
	if ! use svxedit; then
		sed -i 's:bin_SCRIPTS = svxedit:bin_SCRIPTS =:' src/Makefile.in
	fi
	if use vim; then
		sed -i 's:gnome-edit:gvim:' lib/survex.keys.in
		tar -xzf ${FILESDIR}/vim.tgz || ewarn "vim.tgz missing"
	fi

	# sgmltools break my sandbox installation
	sed -i 's:sgmltools --version:false:' configure
	sed -i 's:docbook-to-man:docbook2man:' doc/Makefile.in

	econf \
		WXCONFIG=${WX_CONFIG} \
		--enable-docdir=/usr/share/doc/${PF} \
		$(use_enable profile profiling) \
		|| die "econf failed"
	emake || die "emake failed"
}

src_install() {
	DESTDIR=${D} make install || die "install failed"

	if use vim; then
		insinto /usr/share/vim/vimfiles
		doins -r vim/*
	fi

	rm -f ${D}/usr/share/doc/${PF}/manual.rtf
	gzip ${D}/usr/share/doc/${PF}/manual.*

	make_desktop_entry aven "Aven" /usr/share/survex/icons/aven.png
	if use svxedit; then
		make_desktop_entry svxedit "Survex Source Editor"
	fi
}
