#!/usr/bin/make -f

directories = checks helpers lib profiles vendors
share = /usr/share/lintian/
version = $(word 2,$(shell dpkg-parsechangelog | grep ^Version))
deb = lintian4python_$(version)_all.deb

.PHONY: clean
clean: debian/control
	dh_clean
	rm -f debian/*-stamp

.PHONY: build build-arch build-indep
ifeq "$(filter nocheck,$(DEB_BUILD_OPTIONS))" ""
build build-indep: debian/test-stamp
debian/test-stamp:
	./private/update-code-analysis-tags --dry-run
	./private/update-pyflakes-tags --dry-run
	$(MAKE) -C tests/code-analysis/ test-local
	touch $(@)
endif

.PHONY: binary binary-arch binary-indep
binary binary-indep: debian/control
	dh_testroot
	dh_prep
	dh_install $(directories) $(share)
	dh_install lintian4py* /usr/bin/
	sed -i \
		-e "s,\(\$$lintian4python_root\) = .*,\1 = undef;," \
		-e "s,\(\$$lintian4python_version\) = undef;,\1 = '$(version)';," \
		debian/*/usr/bin/*
	dh_perl
	dh_installdocs
	dh_installchangelogs
	dh_lintian
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb
ifeq "$(filter nocheck,$(DEB_BUILD_OPTIONS))" ""
	export LINTIAN_INTERNAL_TESTSUITE=1 && \
	./lintian4py --allow-root --no-cfg ../$(deb) 2>&1 | ( ! grep . )
	dpkg -f ../$(deb) Depends \
	| xargs -t -d '\n' dpkg-checkbuilddeps -d
endif

# vim:ts=4 sw=4 noet
