#!/usr/bin/make -f
# -*- makefile -*-
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

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

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

actual_version:=$(shell PYTHONPATH=src python3 -c "from catkin_lint import __version__; print(__version__)")
debianized_version:=$(subst a,~a,$(subst b,~b,$(actual_version)))

ifneq ($(DEB_VERSION_UPSTREAM),$(debianized_version))
$(error Package version $(DEB_VERSION_UPSTREAM) does not match actual version $(debianized_version))
endif

export PYBUILD_NAME=catkin-lint
export PYBUILD_DESTDIR = debian/catkin-lint
export PYBUILD_INSTALL_ARGS = --install-lib=/usr/share/catkin-lint

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_install:
	dh_auto_install -O--buildsystem=pybuild
	mv debian/catkin-lint/usr/bin/catkin_lint debian/catkin-lint/usr/share/catkin-lint/run

override_dh_installman: debian/catkin_lint.1
	dh_installman -O--buildsystem=pybuild

debian/catkin_lint.1: src/catkin_lint/__init__.py
	PYTHONPATH=src python3 -m catkin_lint --help | help2man -N -n "check catkin packages for common errors" --version-string="$(actual_version)" -h- cat | sed -e 's/\<cat\>\|\<__main__\.py\>/catkin_lint/g' -e 's/\<CAT\>/CATKIN_LINT/g' > $@
