# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=6

inherit common-lisp-3 eutils

DESCRIPTION="Elephant is an object database for Common Lisp"
HOMEPAGE="http://common-lisp.net/project/elephant/"
SRC_URI="http://common-lisp.net/~sionescu/files/${P}.tar.bz2
		doc? ( http://www.common-lisp.net/project/${PN}/doc/${PN}.pdf )"

LICENSE="GPL-2 LLGPL-2.1"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="doc postgres sqlite3"

RDEPEND="!dev-lisp/cl-${PN}
		sys-libs/db:4.5
		dev-lisp/uffi
		dev-lisp/clsql
		dev-lisp/cl-base64
		dev-lisp/fiveam
		postgres? ( dev-lisp/clsql[postgres] )
		sqlite3? ( dev-lisp/clsql[sqlite3] )"

CL_SYSTEMS="${PN} ${PN}-tests ele-bdb ele-clsql"

src_unpack() {
	unpack ${A}
}

src_prepare() {
	eapply "${FILESDIR}"/${PV}-config.sexp.patch
	eapply "${FILESDIR}"/${PV}-fix-tests.patch
	mv "${S}"/config.sexp "${S}"/my-config.sexp || die
	eapply_user
}

src_install() {
	common-lisp-install-sources tests src/{db-bdb,db-clsql,elephant,memutil,query,utils} my-config.sexp
	common-lisp-install-asdf
	if use postgres ; then
		common-lisp-install-asdf ele-postgresql
	fi
	if use sqlite3 ; then
		common-lisp-install-asdf ele-sqlite3
	fi

	dodoc CREDITS README
	dohtml doc/html/*
	use doc && dodoc "${DISTDIR}"/${PN}.pdf
	docinto examples && dodoc examples/*
}