#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1

include /usr/share/dpkg/pkg-info.mk

BUILD_DATE  = $(shell LC_ALL=C date -u "+%d %B %Y" -d "@$(SOURCE_DATE_EPOCH)")
SPHINXOPTS := -E -N -D html_last_updated_fmt="$(BUILD_DATE)"

export PYBUILD_NAME=django-filters

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_build:
	@echo
	@echo "Rebuild the GNU message catalogs..."
	@echo
	@for lang in `find django_filters/locale/ -maxdepth 1 -type d | sort`; do \
	    if [ -f $${lang}/LC_MESSAGES/django.po ]; then \
	        LANG=`basename $${lang}` ;\
	        echo "Create message catalog for '$${LANG}'" ;\
	        msgfmt -v $${lang}/LC_MESSAGES/django.po -o $${lang}/LC_MESSAGES/django.mo ;\
	    fi ;\
	done
	dh_auto_build

override_dh_sphinxdoc:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. python3 -m sphinx -b html $(SPHINXOPTS) docs $(CURDIR)/debian/python-django-filters-doc/usr/share/doc/python-django-filters-doc/html
	rm -rf $(CURDIR)/debian/python-django-filters-doc/usr/share/doc/python-django-filters-doc/html/.doctrees
	dh_sphinxdoc
endif

override_dh_auto_test:
	dh_auto_test -- --system=custom --test-args="PYTHONPATH={build_dir} {interpreter} ./runtests.py"
