#!/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
PYVERS=$(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_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
endif


override_dh_installchangelogs:
	dh_installchangelogs RELEASE_NOTES.txt


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


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

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

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


.PHONY: override_dh_auto_build override_dh_auto_clean override_dh_sphinxdoc \
        override_dh_install override_dh_installchangelogs override_dh_compress
