#Packager: George Vlahavas <vlahavas~at~gmail~dot~com>

pkgname=scrotwm
pkgver=0.9.28
pkgrel=1gv
source=("http://opensource.conformal.com/snapshots/scrotwm/scrotwm-$pkgver.tgz" "scrotwm.desktop" "xinitrc.scrotwm" "LICENSE")
docs=('license')
dotnew=('etc/scrotwm.conf')
options=('noautodotnew')
url=http://scrotwm.org

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"scrotwm (a small dynamic tiling window manager)"
"scrotwm tries to stay out of the way so that valuable screen real"
"estate can be used for much more important stuff. It has sane defaults"
"and does not require one to learn a language to do any configuration."
"It was written by hackers for hackers and it strives to be small,"
"compact and fast."
)


build() {
	cd $startdir/src/$pkgname-$pkgver

	sed -i 's|setenv(\"LD_PRELOAD\", SWM_LIB, 1);|//setenv(\"LD_PRELOAD\", SWM_LIB, 1);|' scrotwm.c

	cd linux
	make || return 1
	make install PREFIX=/usr LIBDIR=/usr/lib${LIBDIRSUFFIX} MANDIR=/usr/man DESTDIR=$startdir/pkg
	mkdir -p $startdir/pkg/etc
	cp ../scrotwm.conf $startdir/pkg/etc/
	mkdir -p $startdir/pkg/usr/libexec/scrotwm
	cp ../*.sh $startdir/pkg/usr/libexec/scrotwm/
	sed -i "s|baraction.sh|/usr/libexec/scrotwm/baraction.sh|" $startdir/pkg/etc/scrotwm.conf
	sed -i "s|screenshot.sh|/usr/libexec/scrotwm/screenshot.sh|" $startdir/pkg/etc/scrotwm.conf
	sed -i "s|initscreen.sh|/usr/libexec/scrotwm/initscreen.sh|" $startdir/pkg/etc/scrotwm.conf

	# make the win key the default mod key
	sed -i "s/# modkey = Mod1/modkey = Mod4/" $startdir/pkg/etc/scrotwm.conf

	# put manpages in the right directories
	for i in `ls $startdir/pkg/usr/man/man1/scrotwm_*.1`; do
		LANG=`basename $i | sed "s/scrotwm_\(.*\)\.1/\1/"`
		mkdir -p $startdir/pkg/usr/man/$LANG/man1
		mv $startdir/pkg/usr/man/man1/scrotwm_$LANG.1 $startdir/pkg/usr/man/$LANG/man1/scrotwm.1
	done

	mkdir -p $startdir/pkg/usr/share/xsessions
	cp $startdir/src/scrotwm.desktop $startdir/pkg/usr/share/xsessions
	mkdir -p $startdir/pkg/etc/X11/xinit
	cp $startdir/src/xinitrc.scrotwm $startdir/pkg/etc/X11/xinit/
	chmod 755 $startdir/pkg/etc/X11/xinit/xinitrc.scrotwm
}