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

inherit eutils qt4 flag-o-matic

MY_P="${P}nonpublic"

DESCRIPTION="molecular modeling and visualization application"
HOMEPAGE="http://www.ballview.org/"
SRC_URI="http://www.ballview.org/Downloads/Develop/${MY_P}.tar.gz"
RESTRICT="mirror"

LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~amd64 x86"
IUSE="debug doc fftw python"

RDEPEND="$(qt4_min_version 4.1)
	virtual/glut
	fftw? ( >=sci-libs/fftw-3.0.1 )
	python? ( >=dev-python/sip-4.4.5 )"
DEPEND="sys-devel/bison
	sys-devel/flex
	doc? ( app-text/tetex )
	${RDEPEND}"

S="${WORKDIR}/${MY_P}/source"

src_compile() {
	append-ldflags -L${S}

	echo "accepted" > config.lic
	econf \
		$(use_enable debug debuginfo) \
		$(use_enable !debug optimization) \
		$(use_enable python) \
		$(use_enable fftw) \
		--disable-fftw-longdbl \
		--with-qt=/usr \
		--with-qt-incl=/usr/include/qt4 \
		--with-qt-libs=/usr/lib/qt4 \
		--without-glew-incl \
		--without-glew-libs \
		|| die "econf failed"
	sed 's:^#define BALL_PATH .*:#define BALL_PATH "/usr/share/BALL":' \
		-i ../include/BALL/CONFIG/config.h

	emake -j1 lib || die "make lib failed"
	emake -j1 BALLView || die "make BALLView failed"

	if use python ; then
		emake -j1 -C PYTHON/EXTENSIONS
	fi

	chmod -x ../data/QSAR/*
	chmod -x ../data/CHARMM/charmm*

	if [[ -n $(which convert 2>/dev/null) ]]; then
		convert -resize 32x32 \
			APPLICATIONS/BALLVIEW/logo.png \
			${T}/${PN}.png \
			|| eerror "convert icon failed"
	fi

	if use doc ; then
		make -C ../doc/TUTORIAL tutorial.pdf || eerror "make doc failed"
	fi
}

src_install() {
	dolib libBALL.so libVIEW.so || die "dolib failed"
	dobin APPLICATIONS/BALLVIEW/BALLView || die "dobin failed"
	dodoc COPYRIGHT ChangeLog

	if use python ; then
		insinto /usr/lib/python2.4/lib-dynload
		doins PYTHON/EXTENSIONS/BALLmodule.so || \
			eerror "doins python module failed"
	fi

	cd ..

	insinto /usr/share/BALL
	doins -r data || eerror "doins data failed"

	insinto /usr/share/BALL/doc
	doins -r doc/BALLView || eerror "doins doc/BALLView failed"
	doins -r doc/internal || eerror "doins doc/internal failed"

	if use doc ; then
		insinto /usr/share/doc/${PF}
		doins doc/TUTORIAL/tutorial.pdf || eerror "doins pdf failed"
	fi

	if [[ -f ${T}/${PN}.png ]]; then
		doicon ${T}/${PN}.png
	fi

	make_desktop_entry BALLView "BALLView"
}
