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

# Hack to ensure Python stuff to be installed in the right place
DEB_PYTHON_DESTDIR=$(if $(filter %-docs,$(cdbs_curpkg)),$(DEB_DESTDIR),$(CURDIR)/debian/$(cdbs_curpkg))

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk

# ieee-data
python_module_path=/usr/lib/python*/dist-packages
binary-fixup/python-netaddr binary-fixup/python3-netaddr::
	rm $(CURDIR)/debian/$(cdbs_curpkg)$(python_module_path)/netaddr/eui/iab.*
	rm $(CURDIR)/debian/$(cdbs_curpkg)$(python_module_path)/netaddr/eui/oui.*
	ln -s /usr/share/ieee-data/oui.txt $(CURDIR)/debian/$(cdbs_curpkg)$(python_module_path)/netaddr/eui/
	ln -s /usr/share/ieee-data/iab.txt $(CURDIR)/debian/$(cdbs_curpkg)$(python_module_path)/netaddr/eui/
	# We use "python" on purpose: the idx files cannot be generated by python3
	PYTHONPATH=$(CURDIR) python \
		$(CURDIR)/debian/$(cdbs_curpkg)$(python_module_path)/netaddr/eui/ieee.py
	dh_link -p$(cdbs_curpkg)

# No netaddr binary for python3-netaddr
binary-fixup/python3-netaddr::
	rm -rf $(CURDIR)/debian/$(cdbs_curpkg)/usr/bin

# Documentation
build/python-netaddr-docs::
	PYTHONPATH=$(CURDIR) sphinx-build -q docs/source docs/api
binary-fixup/python-netaddr-docs::
	dh_sphinxdoc -p$(cdbs_curpkg)

# Tests
ifeq (,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
install/python-netaddr install/python3-netaddr::
	$(cdbs_curpythonindepbinary) debian/runtests.py .
endif

clean::
	-rm -rf docs/api
