#!/usr/bin/make -f

# Nethack build script for Debian
#
# Ben Gertzfield (che@debian.org) 29 July 1997
# Copyright 1997 Ben Gertzfield. This script is released under the
# GNU General Public License, version 2 or later.

# Majorly adjusted for GnomeHack by Erik Andersen <andersee@debian.org>
# 13 March 1999

build: build-stamp
build-stamp:
	dh_testdir

	if [ -f autogen.sh ]; then \
	    echo "You seem to be building from CVS..."; \
	    ./autogen.sh --prefix=/usr \
		--enable-alt-hackdir=/usr/lib/games/gnomehack \
		--enable-alt-docdir=/usr/share/doc/gnomehack \
		--enable-alt-desktopdir=/usr/share/gnome/apps/Games \
		--enable-alt-savedir=/var/lib/games/gnomehack \
		--enable-exp-in-status --enable-wizard=root --enable-vision-algo=funcs \
		--with-tty-port --with-gnome-port ; \
	else \
	    echo "You seem to be building from a tarball..."; \
	    ./configure --prefix=/usr \
		--enable-alt-hackdir=/usr/lib/games/gnomehack \
		--enable-alt-docdir=/usr/share/doc/gnomehack \
		--enable-alt-desktopdir=/usr/share/gnome/apps/Games \
		--enable-alt-savedir=/var/lib/games/gnomehack \
		--enable-exp-in-status --enable-wizard=root --enable-vision-algo=funcs \
		--with-tty-port --with-gnome-port ; \
	fi; \
	$(MAKE)
	touch build-stamp

clean: clean-debian clean-source

clean-debian:
	dh_testdir
	dh_testroot
	rm -rf debian/tmp debian/files* core debian/substvars
	rm -f `find debian -name "*.orig"`
	rm -f `find debian -name "*~"`
	rm -rf `find debian -name .deps`
	dh_clean

clean-source:
	rm -f build-stamp nh10.pcf
	rm -f `find . -name "*.orig" -a ! -path debian/`
	rm -f `find . -name "*~" -a ! -path debian/`
	-$(MAKE) clean
	rm -rf config.cache config.log
	rm -rf `find . -name .deps -a ! -path debian/`

binary-indep: build
# Nothing to do by default

binary-arch: build
	dh_testdir	
	dh_testroot
	dh_clean -k
	dh_installdirs etc/init.d usr/share/doc/gnomehack/spoilers \
	    var/lib/games/gnomehack/save #usr/X11R6/lib/X11/fonts/misc

	$(MAKE) install DESTDIR=`pwd`/debian/tmp mandir=/usr/share/man docdir=/usr/share/doc/gnomehack

	# Adjust the install slightly -- move the gnomehack binaries
	# to the lib directory so I can put a wrapper script into
	# /usr/games instead
	mv debian/tmp/usr/games/* debian/tmp/usr/lib/games/gnomehack/
	install -m 644 -o root -g root helper-stuff/gnomehackrc \
		debian/tmp/etc/gnomehackrc
	install -m 0755 -o root -g games \
		helper-stuff/gnomehack_wrapper.sh \
		debian/tmp/usr/lib/games/gnomehack/gnomehack.sh
	
	# specially install X11 stuff (for the Xaw version... skiping
	#/usr/X11R6/bin/bdftopcf -o nh10.pcf win/X11/nh10.bdf 
	#install -m 644 nh10.pcf debian/tmp/usr/X11R6/lib/X11/fonts/misc/
	#gzip debian/tmp/usr/X11R6/lib/X11/fonts/misc/nh10.pcf

	echo "Don't worry when lintian complaints about"
	echo "	debian/tmp/usr/lib/games/gnomehack/license"
	echo "This file is runtime data that is displayed by the game, so"
	echo "lintian can just shut up -- this is not an extra copy."

	# extract spoilers to the docs directory
	tar xzf helper-stuff/spoilers.tar.gz -C debian/tmp/usr/share/doc/gnomehack

	# install wrapper scripts and supporting rc files
	# ( I should make the game install do this....)
	install -m 2755 -o root -g games \
		helper-stuff/gnomehack.sh debian/tmp/usr/games/gnomehack

	# remove superfluous gnome nethack.desktop entry
	rm -f debian/tmp/usr/share/gnome/apps/Games/nethack.desktop

	#Avoid gratuitous conflict with debian nethack package
	#install -m 2755 -o root -g games \
	#	helper-stuff/nethack.sh debian/tmp/usr/games/nethack
	#install -m 644 -o root -g root helper-stuff/nethackrc \
	#  debian/tmp/etc/nethackrc

	# Set up the init script to recover games...
	install -m 0755  -o root -g root \
		helper-stuff/gnomehack.init.sh \
	        debian/tmp/etc/init.d/gnomehack.sh
	dh_installinit --init-script="gnomehack.sh" -r -u"start 85 S ."

	dh_installdocs
	dh_installmenu
	# Install manpages (except for spkr.7)
	dh_installmanpages sys/unix/spkr.7
	dh_installchangelogs
	dh_strip
	dh_compress
	dh_fixperms

	chown root.games debian/tmp/usr/lib/games/gnomehack/gnomehack
	chmod 2755 debian/tmp/usr/lib/games/gnomehack/gnomehack
	dh_suidregister usr/lib/games/gnomehack/gnomehack
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary

