#!/usr/bin/make -f

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

CROSS=--build=$(DEB_BUILD_GNU_TYPE)
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
	CROSS += --host=$(DEB_HOST_GNU_TYPE)
endif

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp

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

	dh_autoreconf_clean
	dh_clean

config.status: configure
	dh_testdir

	dh_autoreconf
	./configure $(CROSS) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info $(shell dpkg-buildflags --export=configure)

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 -- start 20 2 3 4 5 . stop 20 1 .
	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
