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

pkgname=nethack
pkgver=3.4.3
pkgrel=1gv
source=("https://downloads.sourceforge.net/project/nethack/nethack/3.4.3/nethack-343-src.tgz" "nethack.png" "nethack.desktop")
docs=("readme" "install" "copying" "changelog" "authors" "news" "todo" "files" "porting" "guidebook.txt")
url=http://www.nethack.org/index.html

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"nethack (single player dungeon exploration game)"
"NetHack is an old but extremely rich (and hard) dungeon-hacking game."
"Players can start with a variety of roles ranging from Barbarian to"
"Tourist, races and alignment."
"Your goal in the game is basically to go down to the end of the"
"dungeon, get the fabulous Amulet of Yendor and get out to offer it to"
"your God. You already know it won't be that easy..."
)


build() {
	cd $startdir/src/$pkgname-$pkgver
	sh sys/unix/setup.sh

	sed -e '/define HACKDIR/ s|/usr/games/lib/nethackdir|/usr/share/nethack/|' \
		-e '/^#define COMPRESS\s/ s|/usr/bin/compress|/bin/gzip|' \
		-e '/^#define COMPRESS_EXTENSION/ s|".Z"|".gz"|' \
		-e 's|^/\* \(#define DLB\) \*/|\1|' -i include/config.h

	sed -e 's|^/\* \(#define LINUX\) \*/|\1|' \
		-e 's|^/\* \(#define TIMED_DELAY\) \*/|\1|' -i include/unixconf.h

	sed -e 's|^# \(WINTTYLIB = -lncurses\)|\1|' \
		-e 's|^WINTTYLIB = -ltermlib|#&|' -i src/Makefile

	sed -e '/^GAMEDIR\s*=/ s|/games/.*$|/share/$(GAME)|' \
		-e '/^GAMEUID\s*=/ s|games|root|' \
		-e '/^GAMEGRP\s*=/ s|bin|users|' \
		-e '/^GAMEPERM\s*=/ s|04755|02755|' \
		-e '/^FILEPERM\s*=/ s|0644|0664|' \
		-e '/^DIRPERM\s*=/ s|0755|0775|' \
		-e '/^SHELLDIR\s*=/ s|/games|/bin|' -i Makefile

	sed -e "/^MANDIR\s*=/s|/usr/man/man6|$startdir/pkg/usr/man/man6|" -i doc/Makefile

	sed "s/ -O / $CFLAGS /" -i src/Makefile
	sed "s/ -O / $CFLAGS /" -i util/Makefile

	make

	mkdir -p $startdir/pkg/usr/share/icons/hicolor/48x48/apps
	cp $startdir/src/nethack.png $startdir/pkg/usr/share/icons/hicolor/48x48/apps/
	mkdir -p $startdir/pkg/usr/share/applications
	cp $startdir/src/nethack.desktop $startdir/pkg/usr/share/applications/

	install -dm755 $startdir/pkg/usr/man/man6
	make PREFIX=$startdir/pkg/usr install manpages
	sed -e "s|HACKDIR=$startdir/pkg\(.*\)/|HACKDIR=\1/|" \
		-i $startdir/pkg/usr/bin/nethack
}