#!/usr/bin/make -f

include /usr/share/python-van.pydeb/rules_templates/rules.1.mk

# target overwritten
build: $(PYVERS:%=build-python%) $(PYVERS:%=build-dbg-python%)
	touch $@
build-dbg-python%:
	dh_testdir
	python$*-dbg setup.py build
	touch $@

# target overwritten
clean:
	dh_testdir
	dh_testroot
	$(MAKE) -f debian/rules $(PYVERS:%=clean-python%)
	rm -f build-python?.? build-dbg-python?.?
	rm -rf build
	rm -rf dist
	find -iname '*.pyc' -exec rm -f {} \;
	find -iname '*.pyo' -exec rm -f {} \;
	dh_clean

# target overwritten
install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	$(MAKE) -f debian/rules $(PYVERS:%=install-python%) $(PYVERS:%=install-dbg-python%)

# target overwritten
install-dbg-python%:
	python$*-dbg setup.py install --no-compile --single-version-externally-managed $(py_setup_install_args) --root=debian/$(package)-dbg --install-data=usr/lib/$(package)
	find debian/$(package)-dbg
	find debian/$(package)-dbg ! -type d ! -name '*.so' | xargs rm -f
	find debian/$(package)-dbg -depth -empty -exec rmdir {} \;

# target overwritten
binary-common:
	dh_testdir
	dh_testroot
	dh_install
	dh_installchangelogs
	dh_installdocs
	dh_installexamples
	dh_installman
	dh_link
	dh_strip
	#dh_strip -p$(package) --dbg-package=$(package)-dbg
	rm -rf debian/$(package)-dbg/usr/share/doc/$(package)-dbg
	mkdir -p debian/$(package)-dbg/usr/share/doc
	ln -sf $(package) debian/$(package)-dbg/usr/share/doc/$(package)-dbg
	dh_compress
	dh_fixperms
	dh_pycentral
	dh_makeshlibs
	dh_installdeb
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

post-install-python%:
	install -D -m 644 src/zope/__init__.py \
	    debian/$(package)/$(call py_libdir,$*)/zope/__init__.py
	#(echo -n 'setuptools:Depends=' && van-pydeb depends --egg-info debian/$(package)/$(call py_libdir,$*)/$(py_package).egg-info --exclude-extra docs) >> debian/$(package).substvars
	#(echo -n 'setuptools:Suggests=' && van-pydeb depends --egg-info debian/$(package)/$(call py_libdir,$*)/$(py_package).egg-info --extra docs) >> debian/$(package).substvars
	#sed -i 's/python-setuptools/python-pkg-resources/g' debian/$(package).substvars
	#find debian/$(package) -name '*.c' | xargs -r rm -f
