SUMMARY="The ultimate old-school single player dungeon exploration game"
DESCRIPTION="NetHack is a single-player roguelike video game originally \
released in 1987 with ASCII graphics. It is a descendant of an earlier game \
called Hack (1985), which is a descendant of Rogue (1980)."
HOMEPAGE="http://www.nethack.org/"
COPYRIGHT="1985-2015 Stichting Mathematisch Centrum and M. Stephenson"
LICENSE="nethack"
REVISION="1"
SOURCE_URI="https://www.nethack.org/download/$portVersion/nethack-362-src.tgz"
CHECKSUM_SHA256="fbd00ada6a4ee347ecd4a350a5b2995b4b4ab5dcc63881b3bc4485b0479ddb1d"
SOURCE_DIR="nethack-$portVersion"
PATCHES="nethack-$portVersion.patchset"

#the x86 is left is somebody wanted to edit it to work under gcc4
#(it compiles in gcc4, but what is the point if it compiles under gcc2)
ARCHITECTURES="all ?x86"

GLOBAL_WRITABLE_FILES="
	settings/nethack directory keep-old
	"

PROVIDES="
	nethack = $portVersion
	cmd:nethack
	cmd:nethack_bin
	"
REQUIRES="
	haiku
	lib:libncurses >= 6
	"

BUILD_REQUIRES="
	haiku_devel
	devel:libncurses >= 6
	"
BUILD_PREREQUIRES="
	cmd:awk
	cmd:bison
	cmd:flex
	cmd:gcc
	cmd:groff
	cmd:install
	cmd:make
	cmd:nroff
	cmd:sed
	cmd:tbl
	"

defineDebugInfoPackage nethack \
	"$binDir"/nethack_bin

BUILD()
{
	./sys/unix/setup.sh ./sys/unix/hints/haiku
	make PREFIX=$binDir $jobArgs
}

INSTALL()
{
	mkdir -p $binDir
	make install PREFIX=$binDir

	#copy the main binary file to be in main directory
	cp $binDir/nethack/nethack $binDir/nethack_bin
	mkdir -p $settingsDir/nethack

	#move configs to writable directory (license also belongs there)
	cp -r $binDir/nethack/license \
		$binDir/nethack/logfile \
		$binDir/nethack/nhdat \
		$binDir/nethack/perm \
		$binDir/nethack/record \
		$binDir/nethack/save \
		$binDir/nethack/symbols \
		$binDir/nethack/sysconf \
		$binDir/nethack/xlogfile \
		$settingsDir/nethack/

	#remove first nethack dir to not make a name problems
	rm -rf $binDir/nethack

	#replace paths from installation to rights paths in system
	sed "s/HACKDIR=.*/HACKDIR=\/boot\/system\/settings\/nethack/; \
		s/HACK=.*/HACK=\/bin\/nethack_bin/" \
		$binDir/nethacksh/nethack > $binDir/nethack
	chmod +x $binDir/nethack
	rm -rf $binDir/nethacksh
}
