#!/usr/bin/make -f

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

PYTHONPATH = $(wildcard $(CURDIR)/build/lib.*-$(shell pyversions -dv))

.PHONY: override_dh_auto_build
override_dh_auto_build: build/stamp
	
build/stamp: $(C_FILES)
	dh_auto_build
	touch $(@)

%.c: %.pyx
	cython $(<)

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

doc/stamp: build/stamp
	$(MAKE) -C doc/ html PYTHONPATH=$(PYTHONPATH):$(CURDIR)
	touch $(@)

.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/

.PHONY: override_dh_strip
override_dh_strip:
	dh_strip --dbg-package=python-djvu-dbg
	cd debian/*-dbg/usr/lib/debug/usr/lib && mv pyshared pymodules

.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
