#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This is the debhelper compatability version to use.
export DH_COMPAT=1

build: build-stamp
build-stamp:
	dh_testdir

	autoconf
	./configure --with-tigerhome=/usr/lib/tiger --with-tigerwork=/var/run/tiger/work --with-tigerlog=/var/log/tiger --with-tigerbin=/usr/sbin --with-tigerconfig=/etc/tiger --prefix=/usr 
	$(MAKE) all


	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

	[ -f Makefile ] && $(MAKE) distclean || $(MAKE) -f Makefile.in distclean

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	# Add here commands to install the package into debian/tmp.
	$(MAKE) install DESTDIR=debian/tmp/
	# Just in case
	chmod a+x debian/tmp/usr/lib/tiger/systems/Linux/2/{deb,gen,check}_*
	chmod a+x debian/tmp/usr/lib/tiger/scripts/check_*
	# This is not needed
	-rm -rf debian/tmp/usr/lib/tiger/man/
	# Remove the systems that do not apply. 
	# Currently only Linux and default
	# AIX/  default/  HPUX/  IRIX/  Linux/  NeXT/  SunOS/  UNICOS/ UNICOSMK
	# TODO: make this for all dirs save for Linux and default (i.e.
	# make this 'mv' more generic)
	-find debian/tmp/ -type d -a -name "CVS" |xargs rm -rf 
	mv debian/tmp/usr/lib/tiger/systems/{AIX,HPUX,IRIX,NeXT,SunOS,UNICOS,UNICOSMK,Tru64,MacOSX} debian/tiger-otheros/usr/lib/tiger/systems/
	#install -m 755 debian/tiger debian/tmp/usr/sbin/
	#install -m 755 debian/tigexp debian/tmp/usr/sbin/
	#install -m 755 tigercron debian/tmp/usr/lib/tiger/
	install -m 600 cronrc debian/tmp/etc/tiger/
	install -m 600 tigerrc debian/tmp/etc/tiger/
	install -m 600 debian/debian.ignore debian/tmp/etc/tiger/tiger.ignore
	install -m 644 version.h debian/tmp/usr/lib/tiger/


# Build architecture-independent files here.
binary-indep: build install
# We have nothing to do by default.

# Build architecture-dependent files here.
binary-arch: build install
#	dh_testversion
	dh_testdir
	dh_testroot
	dh_installdebconf	
	dh_installdocs
	dh_installexamples tigerrc* site* cronrc
	dh_installmenu
	dh_installcron
	dh_installman man/tiger.8 man/tigexp.8 man/tigercron.8
	dh_installinfo
	dh_installchangelogs CHANGES
	dh_link
	dh_strip -XHPUX -XSunOS -XAIX -XHPUX -XIRIX -XNeXT -XMacOSX
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps -XHPUX -XSunOS -XAIX -XHPUX -XIRIX -XNeXT -XMacOSX
	dh_gencontrol
	dh_md5sums
	dh_builddeb

update-dsa:
# Updated Debian Security Advisories
# This target should only be run by the Debian maintainer (which needs
# to fix the update_advisories appropiately)
	cd systems/Linux/2 && sh update_advisories.sh
binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install
