# Copyright 2003-2007 The Savonet Team
# Distributed under the terms of the GNU General Public License, v2 or later
# $Header: $

IUSE="doc nativecode unicode alsa ao mp3 aac mp3id3 id3tag lame rtp speech wget"

inherit eutils

DESCRIPTION="Programmable and flexible audio stream generator, mainly intended as a web-radio engine."
HOMEPAGE="http://savonet.sf.net"
SRC_URI="mirror://sourceforge/savonet/${P}.tar.bz2"

DEPEND="
	dev-lang/ocaml
	dev-ml/pcre-ocaml
	>=dev-ml/ocaml-dtools-0.1.3
	>=dev-ml/ocaml-shout-0.2.2
	>=dev-ml/ocaml-vorbis-0.4.0
	>=dev-ml/ocaml-ogg-0.1.1
	unicode? ( >=dev-ml/camomile-0.7.1 )
	alsa?    ( >=dev-ml/ocaml-alsa-0.1.2 )
	ao?      ( dev-ml/ocaml-ao )
	mp3?     ( >=dev-ml/ocaml-mad-0.3.1 )
	aac?    ( >=dev-ml/ocaml-faac-0.1.0 >=dev-ml/ocaml-faad-0.1.0 )
	mp3id3?  ( dev-ml/ocaml-mp3id3 )
	id3tag?  ( >=media-libs/libid3tag-0.15.1b )
	lame?    ( dev-ml/ocaml-lame )
	rtp?     ( >=net-libs/libortp-1.0.0 )
	speech?  ( app-accessibility/festival )
"
RDEPEND="
	>=dev-lang/ocaml-3.08
	speech?  (
		app-accessibility/festival
		media-sound/sox
		media-sound/normalize
	)
	wget?    ( net-misc/wget )
"

SLOT="0"
KEYWORDS="~x86 ~amd64"
LICENSE="GPL-2"
RESTRICT="nostrip"

src_compile () {
	econf \
		$(use_enable nativecode) \
		$(use_enable unicode camomile) \
		$(use_enable alsa) \
		$(use_enable ao) \
		$(use_enable mp3 mad) \
		$(use_enable mp3id3) \
		$(use_enable id3tag)\
		$(use_enable lame) \
		$(use_enable rtp) \
		|| die "configure failed"
	emake || die "emake failed"
	use doc && emake doc
	use doc || emake fakedoc
}

pkg_setup() {
	enewuser  liquidsoap '' '' '' '' || die "problem adding user liquidsoap"
	enewgroup liquidsoap '' '' '' '' || die "problem adding group liquidsoap"
}

src_install () {
	einstall || die "einstall failed"
	use doc && einstall api-doc-install
	einstall gentoo-install
	keepdir /var/lib/log/liquidsoap
	keepdir /var/lib/run/liquidsoap
}

pkg_postinst() {
	einfo "Some example configuration has been put into /etc/liquidsoap/radio.liq."
	einfo "After editing it a bit, you should be able to run it using"
	einfo "/etc/init.d/liquidsoap start"
	einfo "The Savonet team thanks you for using liquidsoap!"
}
