#!/usr/bin/make -f

include /usr/share/quilt/quilt.make

DEB_HOST_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
	CROSS=CC=$(DEB_HOST_GNU_TYPE)-gcc
else
	CROSS=
endif

clean: unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp
	rm -f config.guess config.sub

	[ ! -f Makefile ] || $(MAKE) distclean
	rm -f accounting.html
	rm -f accounting.info

	dh_clean

config.status: configure patch
	dh_testdir

ifneq "$(wildcard /usr/share/misc/config.sub)" ""
	cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
	cp -f /usr/share/misc/config.guess config.guess
endif
	autoreconf
	./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)"

build: build-stamp
build-stamp: config.status
	dh_testdir

	$(MAKE)
	$(MAKE) info
	$(MAKE) html

	touch build-stamp


install: build
	dh_testdir
	dh_testroot
	dh_prep

	$(MAKE) DESTDIR=$(CURDIR)/debian/tmp install

	# Removing last, it's in the sysvinit package instead.
	rm -f debian/tmp/usr/bin/last
	rm -f debian/tmp/usr/share/man/man1/last.1

binary: binary-arch

binary-arch: install
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs ChangeLog
	dh_installdocs
	dh_installinit
	dh_installcron
	dh_installinfo
	dh_installman
	dh_strip
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep:

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