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

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

ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
export CFLAGS ?= -O0
endif
PY2VERS=$(shell pyversions -vs)

%:
	dh $@ --with python2 --with sphinxdoc --buildsystem=python_distutils


override_dh_auto_build:
ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE)
	mv doc/usersguide-?.?.?.pdf doc/usersguide.pdf
else
	$(MAKE) ANNOUNCE.txt
	$(MAKE) -C src all
	mkdir -p doc/html
	touch doc/usersguide.pdf
endif
	dh_auto_build --buildsystem=python_distutils


override_dh_install:
	# Install everything excluding the *_d.so debug extensions to python-tables
	dh_install -X"*_d.so" "debian/tmp/usr/lib/python2*" -p python-tables

	# Install the debug extensions to python-tables-dbg
	dh_install "debian/tmp/usr/lib/python2*/*-packages/tables/*_d.so" -p python-tables-dbg

	# Continue with regular dh_install
	dh_install -p python-tables-doc
	dh_numpy
	# using override_dh_auto_test causes problems for dbg versions
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	set -e -x; \
	for py in $(PY2VERS); do \
		cd $(CURDIR)/build/lib.*-$$py; \
		env PYTHONPATH=. python$$py tables/tests/test_all.py -vvv; \
		cd $(CURDIR)/debian/tmp/usr/lib/python$$py/dist-packages; \
		env PYTHONPATH=. python$$py-dbg tables/tests/test_all.py -vvv; \
	done
endif


override_dh_auto_clean:
	# Avoid unnecessary cythonization (see
	# https://github.com/PyTables/PyTables/issues/122)
	#dh_auto_clean --buildsystem=python_distutils
	$(MAKE) distclean
	rm -f doc/*.pdf
	# distutils.ccompiler leaves this behind
	rm -f a.out
	rm -rf tmp/


override_dh_sphinxdoc:
ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
	dh_sphinxdoc -ppython-tables-doc
	rm -f $(CURDIR)/debian/python-tables-doc/usr/share/doc/python-tables-doc/html/_static/jquery.cookie.js
endif


override_dh_installchangelogs:
	dh_installchangelogs -k RELEASE_NOTES.txt


override_dh_compress:
	dh_compress -X.txt -X.pdf -X.py -X.h5


.PHONY: override_dh_auto_build override_dh_auto_clean override_dh_sphinxdoc \
        override_dh_install override_dh_installchangelogs override_dh_compress
