#!/usr/bin/make -f
# GNU copyright 1997 to 1999 by Joey Hess.
# Copyright (c) 1999 Herbert Xu <herbert@debian.org>
# Copyright (C) 2004-2008 Anibal Monsalve Salazar <anibal@debian.org>

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

# This has to be exported to make some magic below work.
export DH_OPTIONS

include /usr/share/quilt/quilt.make

build: patch build-stamp
build-stamp:
	dh_testdir

	if [ ! -f MCONFIG ]; then \
		./configure; \
		sed -e 's/^CFLAGS=\(.*\)$$/CFLAGS= -g -D_GNU_SOURCE \1/' \
		    MCONFIG > MCONFIG.new; \
		mv MCONFIG.new MCONFIG; \
	fi
	$(MAKE)

	touch build-stamp

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp install-stamp

	touch MCONFIG
	[ ! -f Makefile ] || $(MAKE) distclean

	dh_clean

install: DH_OPTIONS=
install: build install-stamp
install-stamp:
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	install finger/finger debian/finger/usr/bin
	install fingerd/fingerd debian/fingerd/usr/sbin/in.fingerd
	cp finger/finger.1 debian/finger/usr/share/man/man1
	cp fingerd/fingerd.8 debian/fingerd/usr/share/man/man8/in.fingerd.8

	dh_strip
	touch install-stamp

# This single target is used to build all the packages, all at once, or
# one at a time. So keep in mind: any options passed to commands here will
# affect _all_ packages. Anything you want to only affect one package
# should be put in another target, such as the install target.
binary-common:
	# Need this version of debhelper for DH_OPTIONS to work.
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installmenu
	dh_installcron
	dh_installinfo
	dh_installchangelogs ChangeLog
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture independant packages using the common target.
binary-indep: install
# (Uncomment this next line if you have such packages.)
#	 $(MAKE) -f debian/rules DH_OPTIONS=-i binary-common

# Build architecture dependant packages using the common target.
binary-arch: install
	$(MAKE) -f debian/rules DH_OPTIONS=-a binary-common

# Any other binary targets build just one binary package at a time.
binary-%: install
	make -f debian/rules binary-common DH_OPTIONS=-p$*

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