#!/usr/bin/make -f
# -*- mode: makefile; coding: utf-8 -*-

export PYBUILD_DESTDIR_python2=debian/python-snimpy/
export PYBUILD_DESTDIR_python3=debian/python3-snimpy/

%:
	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild

override_dh_auto_clean:
	dh_auto_clean
	rm -rf snimpy/__pycache__

override_dh_installdocs:
	dh_installdocs
	PYTHONPATH=. sphinx-build -N -q -E -b html docs/ \
                debian/python-snimpy-doc/usr/share/doc/python-snimpy-doc/html/

# We cannot run any test since we would need some MIBS unavailable in Debian (main)
override_dh_auto_test:

# We need to depend on the right version of CFFI.
override_dh_gencontrol:
	dh_gencontrol
	dh_gencontrol -ppython-snimpy -- -Vcffi:Depends="$(shell python -c 'import cffi ; min=cffi.__version__ ; max=min.split(".") ; max[-1] = str(int(max[-1])+1) ;  print("python-cffi (>= %s), python-cffi (<< %s)" % (min, ".".join(max)))')"
	dh_gencontrol -ppython3-snimpy -- -Vcffi3:Depends="$(shell python3 -c 'import cffi ; min=cffi.__version__ ; max=min.split(".") ; max[-1] = str(int(max[-1])+1) ;  print("python3-cffi (>= %s), python3-cffi (<< %s)" % (min, ".".join(max)))')"

override_dh_install:
	dh_install
	# Move snimpy executable in its dedicated package
	mkdir -p debian/snimpy/usr debian/snimpy/usr/share/man
	mv debian/python3-snimpy/usr/bin debian/snimpy/usr/.
	mv debian/python3-snimpy/usr/share/man/man1 debian/snimpy/usr/share/man/.
	rm -rf debian/python-snimpy/usr/bin debian/python-snimpy/usr/share/man
	rm -rf debian/python3-snimpy/usr/bin debian/python3-snimpy/usr/share/man
