#Packager: Tim Beech <tim ~dot~beech~at~gmail~dot~com>
#Former Packager(s): Name <email@address.com>

pkgname=racket
pkgver=5.3
pkgrel=2tjb
#arch=noarch
source=("http://download.racket-lang.org/installers/5.3/racket/$pkgname-$pkgver-src-unix.tgz" "drracket.desktop")
sourcetemplate=http://people.salixos.org/mimosa/packages/$pkgname/$pkgver/
#docs=("readme" "install" "copying" "changelog" "authors" "news" "todo" "COPYING.txt")
#No need as the docs will be moved manually
url="http://racket-lang.org/"

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"racket - a scheme dialect and IDE"
"Racket is a dialect of Scheme that comes with an IDE - DrRacket - and"
"a series of teaching languages. In conjunction with the second edition"
"of the book How to Design Programs (available online) it may be used"
"as an introduction to Scheme and to programming in general. Racket"
"comes with a full set of libraries, and is aimed at software"
"development not just teaching. Extensive documentation is included."
)


build() {
	cd $startdir/src/$pkgname-$pkgver/src
	# sed copied from Arch PKGBUILD for good measure
	# something to do with interrupts during garbage collection
	sed -i 's/struct siginfo/siginfo_t/' racket/gc2/sighand.c
	
	./configure \
		--prefix=/usr \
		--libdir=/usr/lib${LIBDIRSUFFIX} \
		--localstatedir=/var \
		--sysconfdir=/etc \
		--build=$arch-slackware-linux
	make || return 1
	make DESTDIR=$startdir/pkg install 

	# put docs in the right place
	mkdir -p $startdir/pkg/usr/doc
	mv $startdir/pkg/usr/share/$pkgname/doc $startdir/pkg/usr/doc/$pkgname-$pkgver
	rm -rf $startdir/pkg/usr/share/$pkgname-$pkgver
	#make sure Racket help can still find them
	ln -s /usr/doc/racket-5.3 $startdir/pkg/usr/share/racket/doc
	#change help text describing location
	sed -i "s_doc/release_/usr/doc/$pkgname-$pkgver/release_" $startdir/pkg/usr/doc/$pkgname-$pkgver/license/index.html
	sed -i 's_ in your Racket installation__' $startdir/pkg/usr/doc/$pkgname-$pkgver/license/index.html
	#ensure docs not writeable
	chmod -R go-w $startdir/pkg/usr/doc
	
	# deal with the icons
	for size in 16 32 48
	do
	mkdir -p $startdir/pkg/usr/share/icons/hicolor/${size}x${size}/apps/
	cp $startdir/src/$pkgname-$pkgver/collects/icons/plt-${size}x${size}.png \
		$startdir/pkg/usr/share/icons/hicolor/${size}x${size}/apps/racket.png
	done
	
	# .desktop file
	mkdir -p $startdir/pkg/usr/share/applications
	cp $startdir/src/drracket.desktop $startdir/pkg/usr/share/applications
}