#!/usr/bin/make -f

build_dir   = build
install_dir = debian/lio-utils



%:
	dh $@ --with python2

override_dh_auto_clean:
	# manually clean any *.pyc files
	find . -name "*.pyc" | xargs rm -f
	find . -name "*.pyo" | xargs rm -f

override_dh_auto_build:
	dh_testdir
	$(MAKE) DESTDIR=$(install_dir) -C tools
	cd tcm-py ; python setup.py build --build-base $(build_dir)/tcm-py/
	cd lio-py ; python setup.py build --build-base $(build_dir)/lio-py/

override_dh_auto_install:
	$(MAKE) DESTDIR=$(CURDIR)/$(install_dir) conf_install;	\
	if [ -d tools ]; then	\
		mkdir -p $(CURDIR)/$(install_dir)/usr/sbin;	\
		$(MAKE) DESTDIR=$(CURDIR)/$(install_dir) -C tools install; \
        fi
	if [ -d mib-modules ]; then	\
		$(MAKE) DESTDIR=$(CURDIR)/$(install_dir) -C mib-modules install;	\
	fi

	cd tcm-py ; python setup.py install --prefix=/usr --no-compile --root=$(CURDIR)/$(install_dir) --install-layout=deb
	cd lio-py ; python setup.py install --prefix=/usr --no-compile --root=$(CURDIR)/$(install_dir) --install-layout=deb

override_dh_link:
	# Hack for now.
	chmod a+x $(CURDIR)/$(install_dir)/usr/share/pyshared/*.py

	# Upstream links a bunch of py's to bins.
	dh_link /usr/share/pyshared/tcm_node.py /usr/sbin/tcm_node
	dh_link /usr/share/pyshared/tcm_loop.py /usr/sbin/tcm_loop
	dh_link /usr/share/pyshared/tcm_dump.py /usr/sbin/tcm_dump
	dh_link /usr/share/pyshared/tcm_fabric.py /usr/sbin/tcm_fabric
	dh_link /usr/share/pyshared/lio_node.py /usr/sbin/lio_node
	dh_link /usr/share/pyshared/lio_dump.py /usr/sbin/lio_dump

override_dh_installinit:
	dh_installinit --name target
