#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export PYBUILD_NAME=sasview

# Enable additional hardening options for the binaries but not PIE since it is
# not wanted for shared libraries.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie

# SasView insists on writing to ~/sasview.log
export HOME = $(CURDIR)/build/

# Force pdflatex to use SOURCE_DATE_EPOCH for \today too
export FORCE_SOURCE_DATE = 1


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

override_dh_auto_clean:
	dh_auto_clean
	# clean up docs
	rm -rf docs/sphinx-docs/build docs/sphinx-docs/source-temp otherdocs
	# clean up tests
	find test -name logs -type d -exec rm -rf {} +
	rm -rf test/tests.log .cache test/.cache test/__init__.py

override_dh_auto_build-indep:
	# build the arch-dep packages to be able to build the docs
	dh_auto_build
	# reassemble the docs from dependent packages to make the overall
	./debian/fetchdocs
	python ./docs/sphinx-docs/build_sphinx.py
	# Strip absolute build paths from HTML documentation
	find -type f -name '*.html' -print0 | \
	  xargs -0r sed -i -e "s@$(CURDIR)/`echo build/lib.*`@path/to@g"
	ln -sf /usr/share/javascript/mathjax/ docs/sphinx-docs/build/html/_static/

override_dh_auto_test-indep:
	# nothing to do

override_dh_install:
	rm debian/python-sasview/usr/lib/python2.7/dist-packages/sas/sasgui/guiframe/images/Thumbs.db
	mkdir -p debian/sasview/usr/bin
	mv debian/python-sasview/usr/bin/sasview debian/sasview/usr/bin/sasview
	dh_numpy

override_dh_fixperms-arch:
	dh_fixperms
	chmod a-x debian/python-sasview/usr/lib/python2.7/dist-packages/sas/sasview/test/1d_data/saxess_example.pdh
