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

include /usr/share/cdbs/1/rules/debhelper.mk
DEB_PYTHON_SYSTEM = pysupport
DEB_PYTHON_MODULE_PACKAGE = python-nipype
DEB_PYTHON_MODULE_PACKAGES = python-nipype
include /usr/share/cdbs/1/class/python-distutils.mk

DEB_DESTDIR = $(CURDIR)/debian/python-nipype
export HOME=$(CURDIR)/build

build/python-nipype::
	mkdir -p build
	echo "backend : Agg" >| build/matplotlibrc

#
# Documentation
#
doc: doc-stamp
doc-stamp: build/python-nipype
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	: # TODO: We need to set matplotlib backend to Agg before building...
	export PYTHONPATH=$$PWD MPLCONFIGDIR=$(CURDIR)/build; cd doc; $(MAKE) html
	touch $@
endif

build/python-nipype-doc:: doc

install/python-nipype::
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	cd debian && \
	 PYTHONPATH=$(DEB_DESTDIR)/usr/lib/python$(cdbs_python_current_version)/site-packages \
     MPLCONFIGDIR=$(CURDIR)/build \
	  nosetests -v nipype -e test_spm_path
endif
	: # no executable spreadsheets
	find debian -iname *csv -print0 | xargs -r -0 chmod a-x

# use jquery from Debian package
# symlinked by debhelper
install/python-nipype-doc::
	-rm doc/_build/html/_static/jquery.js
	: # In documentation (.html), fix paths to .py source files
	find doc/_build/html -iname '*.html' \
	| xargs sed -ie 's,file://$(CURDIR),file:///usr/share/pyshared,g'
	: # Prune sphinx bi-products (.htmle) files
	-find doc/_build/html -iname '*.htmle' -delete

# immediately useable documentation
# and exemplar data (they are small excerpts anyways)
DEB_COMPRESS_EXCLUDE := .py .pdf .html .css .jpg .txt .js .json .rtc .par .bin
# -doc package contents
DEB_INSTALL_DOCS_python-nipype-doc := doc/_build/html
#doc/_build/latex/nipype.pdf

clean::
	rm -rf build pypeline.log
	$(MAKE) -C doc clean

.PHONY: doc clean
