#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# 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

DEB_VERSION:=$(shell dpkg-parsechangelog | grep "^Version:" | cut  -d" " -f2 | cut -d"-" -f1 | cut -d"+" -f1 )
PY_VERSION:=$(shell PYTHONPATH=src python -c "from catkin_lint import __version__; print __version__" )

ifneq ($(DEB_VERSION),$(PY_VERSION))
$(error Debian version $(DEB_VERSION) does not match package version $(PY_VERSION))
endif

PY3REQUESTED := $(shell py3versions -r)
PY3DEFAULT := $(shell py3versions -d)
PYTHON3 := $(filter-out $(PY3DEFAULT),$(PY3REQUESTED)) python3

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

override_dh_auto_clean:
	dh_auto_clean
	rm -rf build

override_dh_auto_build:
	set -e; for python in $(PYTHON3); do \
		$$python setup.py build; \
	done
	dh_auto_build

override_dh_auto_install:
	set -e; for python in $(PYTHON3); do \
		$$python setup.py install --install-layout=deb --root=debian/tmp; \
	done
	dh_auto_install

make-orig-tar:
	git archive --prefix=catkin-lint-$(PY_VERSION)/ -o ../catkin-lint_$(PY_VERSION).orig.tar.gz $(shell git merge-base debian master )

