# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $
# This ebuild come from http://bugs.gentoo.org/show_bug.cgi?id=116614 - The site http://gentoo.zugaina.org/ only host a copy.
# written by dongeon, additions by feivelda

inherit eutils toolchain-funcs kde

DESCRIPTION="KDE file sharing client using the anonymous file sharing network MUTE"

HOMEPAGE="http://kommute.sourceforge.net/"

MUTE_VER="0.5"
MUTE_NAME="MUTE_fileSharing-${MUTE_VER}_UnixSource"

SRC_URI="http://dl.sourceforge.net/sourceforge/${PN}/${P}.tar.gz
        http://dl.sourceforge.net/sourceforge/mute-net/${MUTE_NAME}.tar.gz"
LICENSE="GPL-2"

SLOT="0"

KEYWORDS="~x86 ~ppc ~amd64"

IUSE=""

DEPEND=""

need-kde 3.2

S=${WORKDIR}/${MUTE_NAME}

src_unpack()
{
        unpack ${A} || die "unpack failed"
        mv -f ${PN} ${MUTE_NAME} || die
	cd ${S}
	epatch ${FILESDIR}/gcc4.patch || die
	epatch ${FILESDIR}/gcc4_configure.patch || die
}

src_compile() {
        if useq ppc ; then
                echo 2 > cmd
                einfo "Compiling for ppc"
        elif useq x86 ; then
                echo 1 > cmd
                einfo "Compiling for x86"
        elif useq amd64 ; then
                echo 1 > cmd
                einfo "Compiling for amd64"
        else
                die "Can't determine the archiquecture x86 or ppc"
        fi

        echo -e \\n2\\n >> cmd
        ./runToBuild < cmd || die "Build failed"
        cd ${S}/${PN}

        # This is needed to fix building with autoconf 2.60.
        # Many thanks to who preferred such a stupid check rather
        # than a working arithmetic comparison.
        if [[ -f admin/cvs.sh ]]; then
                sed -i -e '/case $AUTO\(CONF\|HEADER\)_VERSION in/,+1 s/2\.5/2.[56]/g' \
                admin/cvs.sh
        fi

        # For some reasons, autoconf 2.60 throws up lots of warnings when using
        # older versions of automake, so force automake 1.9 when using that
        if [[ $(autoconf --version) == autoconf*2.60* ]]; then
                einfo "Forcing automake 1.9 when using autoconf 2.60"
                export WANT_AUTOMAKE="1.9"
        fi

        export KDE_DIR="$(kde-config --prefix)"
        if use arts; then
                export PREFIX="--prefix ${KDE_DIR}"
        else
                export PREFIX="--prefix ${KDE_DIR} --without-arts"
        fi

	make -f Makefile.cvs || die
        econf ${PREFIX} || die "econf failed"

        emake || die "emake failed"
}

src_install() {
        cd ${S}/${PN}
        make install DESTDIR=${D} || die "make install fail"
        make_desktop_entry ${PN} || eerror "make_desktop_entry fail"
}

pkg_postinst() {
        einfo "Visit these webs for more info:"
        einfo "http://kommute.sourceforge.net"
        einfo "http://www.mymute.info"
        einfo "http://www.planetpeer.de/wiki/index.php"
}
