#!/usr/bin/make -f
# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

PY2VERS := $(shell pyversions -s)
PY3VERS := $(shell py3versions -s)

# For running tests, we need UTF-8 charset
# See #604706 for references about this method
LOCALE_PATH	:= debian/tmpdir/usr/lib/locale
LOCALE_NAME	:= en_US
LOCALE_CHARSET	:= UTF-8

%:
	dh $@ --with python2,python3

override_dh_auto_install:
	set -e ; \
	for python in $(PY2VERS); do \
		$$python setup.py install --no-compile -O0 --install-layout=deb \
			--root $(CURDIR)/debian/python-ptable; \
	done
	rm -rf $(CURDIR)/debian/python-ptable/usr/bin

	set -e ; \
	for python in $(PY3VERS); do \
		$$python setup.py install --no-compile -O0 --install-layout=deb \
			--root $(CURDIR)/debian/python3-ptable; \
	done
	rm -rf $(CURDIR)/debian/python3-ptable/usr/bin

override_dh_auto_clean:
	set -e ; \
	for python in $(PY2VERS); do \
	    $$python setup.py clean -a; \
	done
	set -e ; \
	for python in $(PY3VERS); do \
	    $$python setup.py clean -a; \
	done
	find . -name \*.pyc -exec rm {} \;
	rm -rf $(LOCALE_PATH)
	dh_clean

override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	# configure a local charset dir, for testing purposes
	mkdir -p $(LOCALE_PATH)
	localedef -i $(LOCALE_NAME) -c -f $(LOCALE_CHARSET) \
		-A /usr/share/locale/locale.alias --quiet \
		$(LOCALE_PATH)/$(LOCALE_NAME).$(LOCALE_CHARSET)
	set -e ; \
	for python in $(PY2VERS) $(PY3VERS); do \
		PYTHONPATH=. LOCPATH=$(LOCALE_PATH) LC_ALL=$(LOCALE_NAME).$(LOCALE_CHARSET) $$python prettytable_test.py ; \
	done
endif

override_dh_installdocs:
	dh_installdocs -A README.rst
