# SliTaz package receipt.

PACKED_SIZE="84.0K"
UNPACKED_SIZE="248.0K"
PACKAGE="jwm"
VERSION="2.2.0"
CATEGORY="x-window"
SHORT_DESC="JWM is a light Window Manager for the X window system."
MAINTAINER="pankso@slitaz.org"
LICENSE="GPL2"
TARBALL="$PACKAGE-$VERSION.tar.xz"
WEB_SITE="http://www.joewing.net/programs/jwm/"
WGET_URL="http://www.joewing.net/programs/jwm/releases/$TARBALL"
TAGS="wm window-manager"
HOST_ARCH="i486 arm"

DEPENDS="xorg-libX11 xorg-libXft xorg-libXrender xorg-libXpm xorg-libXext \
xorg-libXmu xorg-libXinerama xorg-libXau xorg-libXdmcp xorg-libXt libjpeg \
libpng slitaz-configs-base xorg-xload xorg-xclock imlib2 hsetroot"
BUILD_DEPENDS="xorg-libX11-dev xorg-libXft-dev jpeg-dev libpng-dev"

# Handle cross compilation
case "$ARCH" in
	arm)
		DEPENDS="$DEPENDS joe lynx ytree"
		ARCH_ARGS="--disable-nls" ;;
	i?86)
		DEPENDS="$DEPENDS compton nano" ;;
esac

# Rules to configure and make the package.
compile_rules()
{
	#[ -f done.resize-backgound.u ] || patch -p1 < $stuff/resize-backgound.u
	#touch done.resize-backgound.u
	./configure \
    	--prefix=/usr \
    	--mandir=/usr/share/man \
		--sysconfdir=/etc/xdg/jwm \
		--disable-fribidi \
		--disable-rpath \
		--disable-rsvg \
		--disable-confirm \
		$CONFIGURE_ARGS $ARCH_ARGS 2>/dev/null &&
	make && make install
}

testsuite()
{
	readelf -h $install/usr/bin/jwm
}

# Rules to gen a SliTaz package suitable for Tazpkg.
genpkg_rules()
{
	mkdir -p $fs/etc/xdg/jwm $fs/usr/share
	cp -a $install/usr/bin $fs/usr/bin
	# Simple and default config file.
	cp $stuff/simple.jwmrc $fs/etc/xdg/jwm/simple.jwmrc
	cp $stuff/slitaz.jwmrc $fs/etc/xdg/jwm/system.jwmrc
	cp -r $stuff/xsessions $fs/usr/share
}

post_install()
{
	if [ -d "$1/etc/jwm" ]; then
		echo "Removing old system wide configs: $1/etc/jwm"
		rm -rf $1/etc/jwm
	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/" $1/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
}
