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

EAPI=2

inherit autotools eutils multilib

MY_P=${P/_rc/rc}
DESCRIPTION="An open-source turn-key solution for DNSSEC"
HOMEPAGE="http://www.opendnssec.org/"
SRC_URI="http://www.opendnssec.org/files/source/${MY_P}.tar.gz"
LICENSE="BSD"

SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="auditor softhsm opensc"

DEPEND=">=net-libs/ldns-1.6.4
	>=dev-libs/libxml2-2.6.16
	>=dev-lang/ruby-1.8.7_p249[ssl]
	>=dev-ruby/dnsruby-1.4.3
	>=dev-python/4suite-1.0.2-r1
	>=dev-db/sqlite-3.3.9
	softhsm? ( >=dev-libs/softhsm-1.1.3 )
	opensc? ( >=dev-libs/opensc-0.11.12 )"
RDEPEND="${DEPEND}"

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


pkg_setup() {
	enewgroup opendnssec
	enewuser opendnssec -1 -1 -1 opendnssec
}

src_prepare() {
	epatch "${FILESDIR}"/"${P}"-Makefile.am.patch || die "epatch failed"
	epatch "${FILESDIR}"/"${P}"-configure.ac.patch || die "epatch failed"
	eautoreconf
}

src_configure() {
	local myconf=""
	use softhsm && myconf="$myconf --with-pkcs11-softhsm=/usr/$(get_libdir)/libsofthsm.so"
	use opensc && myconf="$myconf --with-pkcs11-opensc=/usr/$(get_libdir)/opensc-pkcs11.so"

	econf $myconf \
	$(use_enable auditor)
}

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

	dodoc KNOWN_ISSUES NEWS README || die "dodoc failed"
	rm "${D}"/usr/share/opendnssec.spec || die "failed to remove spec file"
}
