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

MJ_COMMITS = https://github.com/mathjax/mathjax-docs/commits/master
MJ_CONFIG  = https://raw.github.com/mathjax/mathjax-docs/master/conf.py
MJ_TARBALL = https://github.com/mathjax/mathjax-docs/archive/master.tar.gz

%:
	dh $@ --with sphinxdoc

override_dh_auto_build:
	sphinx-build . html
	dh_auto_build

override_dh_auto_clean:
	rm -rf html
	dh_auto_clean

override_dh_builddeb:
	dh_builddeb -- -Zxz

get-orig-source:
	base_version=`wget $(MJ_CONFIG) -qO- | grep -P "(?<=version = ').+(?=')" -o`; \
	date=`wget $(MJ_COMMITS) -qO- | grep -P '\d{4}-\d\d-\d\d' -o | sed 's/-//g' | head -n1`; \
	filename=mathjax-docs_$$base_version+$$date.orig.tar.gz; \
	wget $(MJ_TARBALL) -qO $$filename; \
	echo "Successfully downloaded tarball and saved to $$filename."
