#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/dpkg/pkg-info.mk

export PYBUILD_DESTDIR_python3=debian/python3-raritan-json-rpc

%:
	dh $@ --buildsystem=pybuild

override_dh_clean:
	dh_clean
	rm -rf pdu-python-api/raritan_json_rpc.egg-info

override_dh_auto_build:
	for file in `find . -type f -name "*.py"`; do \
	    FOUND_PYTHON=$$(head -n1 $$file | grep python); \
	    if [ "$$FOUND_PYTHON" = "#!/usr/bin/python" ]; then \
	        sed -i 's|^#!\/usr\/bin\/python$$|#!\/usr\/bin\/python3|g' $$file && echo "adjusted shebang in $$file";\
	    fi; \
	done
	dh_auto_build
	## Create manpage for perl script
	pod2man --utf8  --section 1p --name px2_configure $(CURDIR)/px2_configure.pl > $(CURDIR)/debian/px2_configure.1p

override_dh_install:
	dh_install
	## Rename perl script
	mv --verbose $(CURDIR)/debian/libraritan-rpc-perl/usr/bin/px2_configure.pl \
		$(CURDIR)/debian/libraritan-rpc-perl/usr/bin/px2_configure \
	## ... and change its name in the documentation as well
	sed -i -e 's/px2_configure\.pl/px2_configure/g' $(CURDIR)/debian/libraritan-rpc-perl/usr/bin/px2_configure \
		$(CURDIR)/debian/px2_configure.1p

override_dh_fixperms:
	dh_fixperms
	find debian/raritan-json-rpc-doc/usr/share/doc/raritan-json-rpc-doc/examples -type f -exec chmod 644 {} \;

override_dh_compress:
	## Don't compress some text files, they are referenced within the HTML files.
	dh_compress -X well-known-rids.md -X Changelog.txt
