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

inherit eutils

DESCRIPTION="Ice Window Manager with Themes"

HOMEPAGE="http://www.icewm.org/"

#fix for icewm preversion package names
MY_P=${P/_/}
S=${WORKDIR}/${MY_P}

mymirror="thomas.takeroot.de/icewm"
aworkspaces="aworkspaces-1.4"
SRC_URI="mirror://sourceforge/${PN}/${MY_P}.tar.gz
	http://${mymirror}/${MY_P}-atasks-iconpadding.patch
	http://${mymirror}/${MY_P}-notoolbargap.patch
	pager? ( http://${mymirror}/${MY_P}-${aworkspaces}.patch )
	mixer? ( http://${mymirror}/${MY_P}-mixerfull-0.3.patch )"
RESTRICT="mirror"

LICENSE="GPL-2"
SLOT="0"

KEYWORDS="~amd64 ~ppc ~sparc x86"

IUSE="esd gnome imlib nls truetype xinerama mixer shaped pager"

RDEPEND="|| ( (
		x11-libs/libXau
		x11-libs/libX11
		x11-libs/libXrandr
		x11-libs/libXext
		x11-libs/libXpm
		x11-libs/libXrender
		truetype? ( x11-libs/libXft )
		x11-libs/libXt
		x11-libs/libXdmcp )
	virtual/x11 )
	esd? ( media-sound/esound )
	gnome? ( gnome-base/gnome-libs gnome-base/gnome-desktop dev-util/pkgconfig )
	imlib? ( >=media-libs/imlib-1.9.10-r1 )
	nls? ( sys-devel/gettext )
	truetype? ( >=media-libs/freetype-2.0.9 )
	media-fonts/artwiz-fonts
	media-libs/giflib"

DEPEND="${RDEPEND}
	|| ( (
		x11-proto/xproto
		x11-proto/xextproto
		xinerama? ( x11-proto/xineramaproto ) )
	virtual/x11 )
	>=sys-apps/sed-4"

src_unpack() {
	unpack ${A}; cd ${S}

	epatch ${DISTDIR}/${MY_P}-atasks-iconpadding.patch
	epatch ${DISTDIR}/${MY_P}-notoolbargap.patch

	if use pager; then
		epatch ${DISTDIR}/${MY_P}-${aworkspaces}.patch
	fi

	if use mixer; then
		epatch ${DISTDIR}/${MY_P}-mixerfull-0.3.patch
		./autogen.sh
	fi

	sed -i "s:ppp0 eth0:ra0:" src/default.h

	echo "#!/bin/sh" > $T/icewm
	echo "/usr/bin/icewm-session" >> $T/icewm

}

src_compile(){
	CXXFLAGS="${CXXFLAGS}" econf \
		--with-libdir=/usr/share/icewm \
		--with-cfgdir=/etc/icewm \
		--with-docdir=/usr/share/doc/${PF}/html \
		--enable-gradients \
		--enable-corefonts \
		$(use_enable truetype xfreetype) \
		--enable-shape \
		$(use_enable shaped shaped-decorations) \
		$(use_with esd icesound) \
		$(use_with esd esd-config /usr/bin/esd-config) \
		$(use_enable nls) \
		$(use_enable nls i18n) \
		$(use_with imlib) \
		$(use_enable x86 x86-asm) \
		$(use_enable xinerama) \
		$(use_enable gnome menus-gnome1) \
		$(use_enable gnome menus-gnome2) \
		|| die "configure failed"

	sed -i "s:/icewm-\$(VERSION)::" src/Makefile || die "patch failed"
	sed -i "s:ungif:gif:" src/Makefile || die "libungif fix failed"

	emake || die "emake failed"
}

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

	newman doc/icewm.1.man icewm.1
	dodoc AUTHORS BUGS CHANGES README*
	dohtml -a html,sgml doc/*

	exeinto /etc/X11/Sessions
	doexe $T/icewm

	make_session_desktop IceWM icewm-session
}
