#!/usr/bin/make -f

# A few notes on regression testing:
#
# The build process runs a modified version of the upstream regression tests.
# The modified test suite is similar to the upstream one, but ensures that only
# an explicit set of tests are run and always in the same order.  The modified
# test suite also allows for Debian-specific expected results where necessary.
#
# Failed tests leave a .results file in the test_expected directory.  This file
# is used either for debugging or in order to create Debian-specific expected
# results files.  It should not be possible for these results files to end up
# in the source package, because if they exist at all, it means that some tests
# have failed -- and this by definition causes the build process to fail.
# However, the results files are now removed in the clean rule so that past
# failures don't accidentally get kept around and placed into the source
# package.

build_dir     = build
install_dir   = debian/tmp
results_files = test_expected/*.results
setup         = /usr/bin/python ./setup.py --quiet

binary: binary-indep

binary-arch:

binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs CHANGELOG
	dh_installdocs
	dh_installman
	dh_installexamples
	dh_install --list-missing --sourcedir $(install_dir)
	dh_fixperms
	dh_compress -X.py
	dh_pysupport -d
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

install: build
	dh_testdir
	dh_testroot
	dh_installdirs 
	mkdir $(install_dir)/bin
	cp -f debian/wrapper $(install_dir)/bin/pychecker

build: build-stamp
build-stamp: 
	dh_testdir
	$(setup) build --build-base $(build_dir) install --no-compile --install-purelib $(install_dir)/lib/pychecker
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	sh debian/regression.sh
endif
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	$(setup) clean
	find . -name "*.pyc" | xargs rm -f
	find . -name "*.pyo" | xargs rm -f
	rm -f $(results_files)    # no need to keep around past regression test failures
	rm -rf $(build_dir) $(install_dir)
	dh_clean

.PHONY: binary binary-indep install build clean

