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

EAPI="2"
inherit subversion autotools

LICENSE="GPL-2"
DESCRIPTION="Personal Data Recorder/Expert - Tool for managing medicinical data."
HOMEPAGE="http://pdrx.fastmail.fm/"
IUSE="+sqlite mysql cairo +board debug +readline etpan"

KEYWORDS="~amd64 ~x86"

RDEPEND=">=dev-libs/boost-1.39
	>=dev-libs/poco-1.3.6
	mysql? ( dev-libs/poco[mysql] )
	sqlite? ( dev-libs/poco[sqlite] ) 
	cairo? ( >=x11-libs/cairo-1.8.0 )
 	board? ( >=media-libs/libboard-0.9.0 )
	readline? ( sys-libs/readline )
	etpan? ( net-libs/libetpan )
	|| ( x11-libs/cairo media-libs/libboard )
	|| ( ( dev-libs/poco[mysql] ) ( dev-libs/poco[sqlite] ) ) "

DEPEND="${RDEPEND}"

SLOT="0"

ESVN_REPO_URI="svn://svn.savannah.nongnu.org/pdrx/trunk"

src_prepare() {
if ! use board && ! use cairo; then
die "You need at least one graphics engine (USE: board or cairo)." 
fi
if ! use sqlite && ! use mysql ; then
die "You need at least one database engine (USE: sqlite or mysql)." 
fi
	eautoreconf

}

src_configure(){

 econf \
        $(use_enable sqlite ) \
        $(use_enable mysql ) \
	$(use_enable board ) \
	$(use_enable debug ) \
	$(use_enable readline ) \
	$(use_enable etpan ) \
        $(use_enable cairo ) 
}

src_compile() {
	emake || die "emake failed"
}

src_install() {
	emake DESTDIR="${D}" install || die "emake install failed"
	dodoc AUTHORS ChangeLog README TODO doc/*|| die "dodoc failed"
	insinto /usr/share/doc/${P}/examples
	doins -r samples/simple samples/complex|| die "dodoc failed"
}

pkg_postinst() {
    ewarn "This is a SVN ebuild. Use it on your own risk and _DO_NOT_ file"
    ewarn "bugs at bugs.gentoo.org"
    elog "If this is your first install you will need to create a config"
    elog "file \$HOME/.pdrx (and depending on your config a database)."
    elog "Or copy one of the given example configurations from" 
    elog "/usr/share/doc/${P}/examples."
    elog "See /usr/share/doc/${P}/User_Manual.html for help."
}