#Maintainer: Shador <futur~DOT~andy~AT~googlemail.com>

pkgname=xpenguins
pkgver=2.2
pkgrel=1ab
arch=i486
source=("http://xpenguins.seul.org/xpenguins-2.2.tar.gz" "xpenguins.png")
sourcetemplate="http://gaia.homelinux.org/salix/packages/$pkgname/$pkgver/"
docs=("readme" "install" "copying" "changelog" "authors" "news")
url='http://xpenguins.seul.org/'

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"$pkgname (a Desktop decoration with walking penguins)"
"Ever wanted cute little penguins walking along the tops of your"
"windows? Ever wanted to send an army of cute little penguins to invade"
"the screen of someone else on your network? Probably not, but why not"
"try this program out anyway - it's free (licensed under the GNU GPL)."
)


build() {
	threadcount=$(($(sed -ne '/cpu cores/h;${g;s/[^0-9]*//p}' \
						< /proc/cpuinfo)*2))
	if [ $threadcount -lt 2 ]; then
		threadcount=2
	elif [ $threadcount -gt 8 ]; then
		threadcount=8
	fi
	threads="-j${threadcount}"

	cd $startdir/src/$pkgname-$pkgver
	
	./configure \
		--prefix=/usr \
		--libdir=/usr/lib${LIBDIRSUFFIX} \
		--localstatedir=/var \
		--sysconfdir=/etc \
		--mandir=/usr/man || return 1
	make $threads || return 1
	make install DESTDIR=$startdir/pkg || return 1
  
  mkdir -vp $startdir/pkg/usr/bin/
  cat >$startdir/pkg/usr/bin/xpenguins-menu <<EOF
#!/bin/sh
if ! pgrep "^xpenguins$" >/dev/null 2>&1; then
  xpenguins >/dev/null 2>&1 &
  sleep 2s
  exit
else
  killall xpenguins >/dev/null 2>&1
fi
sleep 4s
if pgrep "^xpenguins$" >/dev/null 2>&1; then
  killall -9 xpenguins >/dev/null 2>&1
fi
EOF
  chmod +x $startdir/pkg/usr/bin/xpenguins-menu
  
    mkdir -vp $startdir/pkg/usr/share/applications/
  cat >$startdir/pkg/usr/share/applications/xpenguins.desktop <<EOF
[Desktop Entry]
Encoding=UTF-8
Name=Start/Stop XPenguins
Exec=xpenguins-menu
Icon=xpenguins
Terminal=false
Type=Application
Categories=GNOME;GTK;Game;
StartupNotify=true
EOF

  install -vD $startdir/src/xpenguins.png $startdir/pkg/usr/share/icons/hicolor/48x48/apps/xpenguins.png
}