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

IUSE="alsa oss singlefft"

inherit eutils

DESCRIPTION="Gnome Wave Cleaner"
HOMEPAGE="http://gwc.sourceforge.net/"
MAJVER="${PV%%.*}"
MINVER="${PV#*.}"
MINVER="${MINVER%.*}"
PATLVL="${PV##*.}"
MY_P="${PN}-${MAJVER}.${MINVER}-${PATLVL}"
SRC_URI="mirror://sourceforge/${PN}/${MY_P}.tgz"

SLOT="0"
LICENSE="GPL-1"
KEYWORDS="~x86"

DEPEND=">=media-libs/libsndfile-1.0.1
	>=sci-libs/fftw-2.1.3
	gnome-base/gnome-libs
	alsa? ( >=media-sound/alsa-driver-0.9 )"

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

src_compile() {
	# Configure gwc source
	sed -i -e "/^CFLAGS =/s/-mcpu=@UNAME_MACHINE@ -march=@UNAME_MACHINE@//" \
		-e "/^CFLAGS =/s/@CFLAGS@/${CFLAGS}/" Makefile.in
	local myconf
	use alsa && myconf="--enable-alsa"
	use oss || myconf="${myconf} --without-oss"
	use singlefft && myconf="${myconf} --enable-single-fftw3"

	econf ${myconf} || die "Configuration failed"

	# Build the meschach math library first 
	# so good CFLAGS are used
	cd ${S}/meschach
	sed -i -e '/^CFLAGS =/c/CFLAGS = ${CFLAGS}/'  makefile.in
	PATH=".:$PATH"
	econf --with-sparse || die "Failed to configure meschach math lib"
	( make part1 && make part2 && make part3 && cp machine.h ..) || die \
	            "Failed to compile meschach math lib"


	# Now build gwc
	cd ${S}
	PATH=.:${PATH}
	emake || die
}

src_install () {

	MYDIRS='\$(BINDIR)\|\$(pixmapdir)\|\$(HELPDIRC)\|\$(DOCDIR)' 
	sed -i -e "/^DOCDIR =/c DOCDIR = \/usr\/share\/doc\/\$\{PV\}" \
		-e 's:install -d :install -d \$\{D\}/:' \
		-e "/install -p/,/pixmapdir)$/ s:\($MYDIRS\):\$\{D\}/&:" Makefile
	make install DESTDIR=${D} || die
}