#!/usr/bin/make -f

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

.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:
	$(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
ifeq "$(filter nocheck,$(DEB_BUILD_OPTIONS))" ""
	mkdir -p debian/tmp
	dh_builddeb --destdir=debian/tmp
	export LINTIAN_INTERNAL_TESTSUITE=1 && \
	./lintian4py --allow-root --no-cfg debian/tmp/*.deb 2>&1 | ( ! grep . )
	dpkg -f debian/tmp/*.deb Depends \
	| xargs -t -d '\n' dpkg-checkbuilddeps -d
endif
	dh_builddeb

# vim:ts=4 sw=4 noet
