# SliTaz package receipt.

PACKAGE="pekwm"
VERSION="0.1.13"
CATEGORY="x-window"
SHORT_DESC="Very light, configurable and themable window manager for X."
MAINTAINER="jozee@slitaz.org"
DEPENDS="xorg-libX11 xorg-libXinerama xorg-libXft xorg-libXrandr xorg-libXpm"
BUILD_DEPENDS="xorg-dev xorg-dev-proto zlib-dev"
SUGGESTED="hsetroot tint2 lxpanel wbar xorg-xprop xorg-xev xdotool wmctrl"
TARBALL="$PACKAGE-$VERSION.tar.bz2"
WEB_SITE="http://www.pekwm.org/projects/pekwm"
WGET_URL="$WEB_SITE/files/$TARBALL"

# Rules to configure and make the package.
compile_rules()
{
	cd $src
	./configure --prefix=/usr --sysconfdir=/etc $CONFIGURE_ARGS &&
	make &&
	make DESTDIR=$DESTDIR install
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/usr/bin $fs/usr/share/pekwm $fs/etc
	cp -a $_pkg/usr/bin $fs/usr
	cp -a $_pkg/usr/share/pekwm $fs/usr/share
	cp -a $_pkg/etc $fs
	# Custom configuration files and scripts
	cp -a $stuff/etc $fs
	cp -a $stuff/scripts $fs/usr/share/pekwm
	# Set perms.
	chown -R root.root $fs
	chmod +x $fs/etc/pekwm/start
	chmod +x $fs/usr/share/pekwm/scripts/*
	chmod 0755 $fs/usr/bin/pekwm
}

post_install()
{
	# Pekwm searches for default font path (100dpi folder) for xsever to render 
	# menus; either manually set it in .xinitrc or fake 100dpi folder fonts 
	# by linking to ttf-dejavu
	if [ ! -d $1/usr/share/fonts/X11/100dpi/ ]; then
		mkdir -p $1/usr/share/fonts/X11/100dpi
		cd $1/usr/share/fonts/X11/100dpi
		ln -s ../../truetype/ttf-dejavu/* .
	fi
	
	res=`cat $1/etc/slim.conf | grep ^session | sed s/"sessions. *"//`
	# Adding WM to SLIM available sessions.
	if ! echo "$res" | grep -q $PACKAGE; then
		echo -n "Adding $PACKAGE to /etc/slim.conf..."
		sed -i "s/^sessions.*/sessions            ${res},$PACKAGE/" /etc/slim.conf
		status
	fi
}

post_remove()
{
	# Remove WM from SLIM available sessions.
	if grep -q $PACKAGE $1/etc/slim.conf; then
		sed -i s/,$PACKAGE// $1/etc/slim.conf
	fi
}