#!/usr/bin/make -f
#export DH_VERBOSE=1
export LC_ALL=C

PYX_FILES = $(wildcard djvu/*.pyx)
C_FILES = $(PYX_FILES:.pyx=.c)

nosetests = /usr/bin/nosetests --verbose --no-skip

pythonpath = $$(_py_=$(strip $(1)); _py_=$${_py_\#python}; ls -d $(CURDIR)/build/lib.*-$${_py_})
pythonpath_dbg = $$(_py_=$(strip $(1)); _py_=$${_py_\#python}; ls -d $(CURDIR)/build/lib_d.*-$${_py_} 2>/dev/null || ls -d $(CURDIR)/build/lib.*-$${_py_}-pydebug)

:PHONY: override_dh_install
override_dh_install:
	dh_install
	rm -f $(CURDIR)/debian/python-djvu/usr/lib/python*/dist-packages/djvu/dllpath.py

.PHONY: override_dh_installdocs
override_dh_installdocs:
ifneq ($(shell dh_listpackages | grep -x -F python-djvu-doc),)
	python setup.py build_sphinx
endif
	dh_installdocs -X.buildinfo -Xobjects.inv

.PHONY: override_dh_auto_clean
override_dh_auto_clean: 
	rm -Rf doc/build/ doc/stamp
	rm -Rf build/
	find . -type f \( -name '*.py[co]' -or -name '*.so' -or -name '*.c' \) -delete
	rm -Rf *.egg-info/
	rm -f djvu/config.pxi

.PHONY: override_dh_strip
override_dh_strip:
ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
	dh_strip --dbg-package=python-djvu-dbg
	cd debian/*-dbg/usr/lib/debug/usr/lib && mv pyshared pymodules
endif

.PHONY: override_dh_auto_test
override_dh_auto_test:
ifeq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	mkdir -p debian/tmp/locale/
	localedef -f UTF-8 -i ja_JP ./debian/tmp/locale/ja_JP.UTF-8/
	export LOCPATH=$(CURDIR)/debian/tmp/locale/ && \
	cd tests && \
	set -x -e; \
	for python in $(shell pyversions -r); do \
		ln -sf $(call pythonpath,$$python)/djvu djvu; $$python $(nosetests); rm djvu; \
		ln -sf $(call pythonpath_dbg,$$python)/djvu djvu; $$python-dbg $(nosetests); rm djvu; \
	done
endif

.PHONY: override_dh_installchangelogs
override_dh_installchangelogs:
	dh_installchangelogs doc/changelog

.PHONY: override_dh_compress
override_dh_compress:
	dh_compress -X.txt

.PHONY: build build-arch build-indep binary binary-arch binary-indep clean
build build-arch build-indep binary binary-arch binary-indep clean:
	dh $(@)

# vim:ts=4 sw=4 noet
