#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

export PYBUILD_NAME = postorius

%:
	dh $@ --with python2,sphinxdoc --buildsystem=pybuild

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	ln -s ../src/postorius example_project/postorius
	set -e; \
	for python in $(shell pyversions -r); do \
		$$python $(shell which django-admin) test --pythonpath=example_project --settings=test_settings postorius; \
	done
	rm example_project/postorius
endif

override_dh_auto_build:
	PYTHONPATH=. sphinx-build -b html -E -N src/postorius/doc build/sphinx/html
	dh_auto_build

override_dh_auto_install:
	dh_auto_install
	# Don't embed bootstrap/jquery JS scripts
	find debian/python-django-postorius -name 'jquery-1.11.3.min.js' -type f -exec \
		ln -sf /usr/share/javascript/jquery/jquery.min.js {} \;
	find debian/python-django-postorius -name 'bootstrap.min.js' -type f -exec \
		ln -sf /usr/share/javascript/bootstrap/js/bootstrap.min.js {} \;
	find debian/python-django-postorius -name 'glyphicons-halflings-regular.ttf' -type f -exec \
		ln -sf /usr/share/glewlwyd/webapp/fonts/glyphicons-halflings-regular.ttf {} \;
	# Move static files outside of the lib directory
	mv debian/python-django-postorius/usr/lib/python2.7/dist-packages/postorius/static \
		debian/python-django-postorius/usr/share/python-django-postorius/
	ln -sf /usr/share/python-django-postorius/static \
		debian/python-django-postorius/usr/lib/python2.7/dist-packages/postorius/static

override_dh_installchangelogs:
	dh_installchangelogs src/postorius/doc/news.rst
