#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-

# override HOME (for weave) and matplotlib config directory
# to allow building in chroots with read-only HOME
export HOME=$(CURDIR)/build
export MPLCONFIGDIR=$(HOME)

%:
	dh  $@

# Build docs during build
override_dh_auto_build:
	dh_auto_build
	echo "backend : Agg" >| $(MPLCONFIGDIR)/matplotlibrc

	: # Build Documentation -- assure existence of build/html for nodoc
	mkdir -p build/html
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	export PYTHONPATH=$(CURDIR) ; \
	 $(MAKE) -C scikits/statsmodels/docs html
	mv scikits/statsmodels/docs/build/* build/
	rm -rf statsmodels/docs/source/generated/
endif

override_dh_clean:
	dh_clean
	rm -rf build *-stamp *.egg-info scikits/statsmodels/docs/source/generated

# Prune toplevel scikits/__init__.py to avoid conflicts across future
# scikits- packages, and rely on pysupport to create such one if
# necessary
override_dh_auto_install: ${PYVERS:%=python-install%}
	dh_auto_install
	find debian -wholename \*scikits/__init__.py -delete
	: # strip docs/ since they aren't really a Python module, there is -doc for it
	find debian -wholename \*scikits/statsmodels/docs | xargs rm -rf
	find debian -iname COPYING | xargs -r rm -f

override_dh_auto_test:
	: # Test and do not exit on failure since there are knowntofail atm
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	python setup.py test
endif

## immediately useable documentation and exemplar scripts/data
override_dh_compress:
	dh_compress -X.py -X.html -X.pdf -X.css -X.jpg -X.txt -X.js -X.json -X.rtc -X.inv

override_dh_installdocs:
	: # Use jquery from Debian package, so prune shipped one
	-rm ./build/html/_static/jquery.js
	dh_installdocs

get-orig-source:
	uscan --upstream-version 0 --rename
