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

pkgname=esdl
pkgver=1.0.1
pkgrel=1ab
arch=i486
source=("http://sourceforge.net/projects/esdl/files/esdl/esdl-1.0.1/esdl-1.0.1.src.tar.gz")
sourcetemplate="http://gaia.homelinux.org/salix/packages/$pkgname/$pkgver/"
docs=("readme" "readme-sdl.txt" "license.terms")
url='http://sourceforge.net/apps/mediawiki/esdl/index.php?title=Main_Page'
options=("noautodotnew")

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"$pkgname (Erlang bindings to SDL)"
"Esdl is an Erlang binding to SDL and includes a binding to OpenGL."
"Esdl was created to be used in Wings3D but in other projects as well."
"SDL (and esdl) mainly does image blitting and input for games, if you"
"want a gui which handles windows and widgets checkout wxErlang."
)


build() {
	set -e
	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
	
  . vsn.mk # get version information (ESDL_VSN)
  # version subdir is applied by make install
  LIBDIR="$startdir/pkg`erl -noshell -eval "io:format([126,115,126,110],[code:root_dir()])" -s erlang halt`/lib"
  ESDL_PATH="`echo ${LIBDIR} | sed -e "s;^$startdir/pkg;;"`/${ESDL_VSN}"
  
	make $threads || return 1
  make install INSTALL_DIR=${LIBDIR} || return 1
  
  # fix perms (modified set_pre_permissions)
  (
    cd $startdir/pkg
    find . -perm 664 -exec chmod -v 644 {} \;
    find . -perm 600 -exec chmod -v 644 {} \;
    find . -perm 444 -exec chmod -v 644 {} \;
    find . -perm 400 -exec chmod -v 644 {} \;
    find . -perm 440 -exec chmod -v 644 {} \;
    find . -perm 777 -exec chmod -v 755 {} \;
    find . -perm 775 -exec chmod -v 755 {} \;
    find . -perm 700 -exec chmod -v 755 {} \;
    find . -perm 511 -exec chmod -v 755 {} \;
    find . -perm 711 -exec chmod -v 755 {} \;
    find . -perm 555 -exec chmod -v 755 {} \;
  )
  
  install -vd $startdir/pkg/etc/profile.d/
  cat >$startdir/pkg/etc/profile.d/esdl.sh <<EOF
#!/bin/sh
export ESDL_PATH="${ESDL_PATH}"
EOF

  cat >$startdir/pkg/etc/profile.d/esdl.csh <<EOF
#!/bin/csh
setenv ESDL_PATH ${ESDL_PATH}
EOF

  chmod a+x $startdir/pkg/etc/profile.d/*
    
	set +e
}