#!/usr/bin/make -f

version = $(word 2,$(shell dpkg-parsechangelog | grep ^Version:))

.PHONY: clean
clean: doc/Makefile tests/Makefile
	$(MAKE) -C doc/ clean
	$(MAKE) -C tests/ clean
	dh_clean debian/build-stamp

.PHONY: build build-arch build-indep
build: build-indep
build-indep: debian/build-stamp
	
debian/build-stamp: doc/Makefile adequate
	$(MAKE) -B -C doc/
ifeq "$(filter nocheck,$(DEB_BUILD_OPTIONS))" ""
	adt_adequate=./adequate adt_testpkg=coreutils debian/tests/smoke-test
endif
	touch $(@)

.PHONY: binary binary-arch binary-indep

binary: binary-indep
binary-indep: build-indep
	dh_testroot
	dh_prep
	dh_installdirs
	dh_install
	sed -i \
		-r -e 's/^(our \$$VERSION) =.*/\1 = "$(version)";/' \
		debian/*/usr/bin/*
	dh_installman doc/*.1
	dh_perl
	dh_installdocs
	dh_installchangelogs
	dh_buildinfo
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# vim:ts=4 sw=4 noet
