#!/usr/bin/make -f

export PYBUILD_DESTDIR_python3=debian/python3-sympy/

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

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

override_dh_auto_build:
	# restore doc/inv with intersphinx inventories
	tar xzf debian/intersphinx-inventories.tgz

	# build the documentation in HTML format
	faketime "`dpkg-parsechangelog -S date`" \
		sh -c '(cd doc/; export SPHINXOPTS="-j auto"; $(MAKE) html)'

	# declare furo.js as a script of type 'module' in all HTML files
	@echo "Declare furo.js as a script of type 'module'"
	@for f in $$(grep -rl _static/scripts/furo.js doc/_build/html); do \
	  sed -i 's%<script src="_static/scripts/furo.js">%<script src="_static/scripts/furo.js" type="module">%' $$f; \
	  echo -n "$$(basename $$f) ... "; \
	done; \
	echo "Done"

	dh_auto_build

DOCDIR = debian/python-sympy-doc/usr/share/doc/python-sympy-doc
override_dh_auto_install:
	dh_auto_install
	mv debian/python3-sympy/usr/bin/isympy debian/isympy-common/usr/bin/
	mv debian/python3-sympy/usr/share/man/man1/* \
		debian/isympy-common/usr/share/man/man1/
	rm -rf debian/python*-sympy/usr/bin/
	rm -rf debian/python*-sympy/usr/share/man/
	# Get rid of embedded mpmath.  Unfortunately, we
	# can't remove all files with quilt (empty files, for example).
	rm -rf debian/python*-sympy/usr/lib/python*/dist-packages/sympy/mpmath/
	# create the file version.json for the package python-sympy-doc
	install -d $(DOCDIR)
	v=$$(dpkg-parsechangelog --show-field Version| sed 's/-.*//'); \
	  echo "{\"latest\": \"$$v\", \"dev\": \"$$v\"}" > \
	    $(DOCDIR)/version.json

override_dh_auto_clean:
	dh_auto_clean
	cd doc/; $(MAKE) clean; rm -rf src/inv
	rm -rf sympy.egg-info

override_dh_auto_test:
