#!/usr/bin/make -f

UPSTREAM = $(shell dpkg-parsechangelog | egrep '^Version: ' | cut -d ' ' -f 2- | cut -d '-' -f 1)

%:
	dh $@ --with python2,sphinxdoc

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=$(CURDIR) sphinx-build doc/ doc/_build/html

override_dh_auto_install:
	dh_auto_install
	mkdir -p debian/tmp/etc/
	cp -r fedmsg.d debian/tmp/etc/
	mkdir -p debian/tmp/usr/share/fedmsg/
	cp -r extras initsys debian/tmp/usr/share/fedmsg
	chmod +x debian/tmp/usr/share/fedmsg/initsys/sysv/*
	rm debian/tmp/usr/lib/python2*/dist-packages/fedmsg*.egg-info/SOURCES.txt

override_dh_installman:
	mkdir -p debian/tmp/manpages
	set -e; \
	for s in $(shell ls debian/tmp/usr/bin); do \
		PYTHONPATH="$(shell pwd)" help2man -n "Manpages for the fedmsg suite" --version-string="$(UPSTREAM)" debian/tmp/usr/bin/$$s > debian/tmp/manpages/$$s.1; \
	done
	dh_installman -ppython-fedmsg debian/tmp/manpages/*

override_dh_install:
	dh_install --fail-missing

override_dh_auto_clean:
	dh_auto_clean
	rm -rf doc/_build/

override_dh_installchangelogs:
	dh_installchangelogs -k CHANGELOG.rst

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	set -e; \
	for py in $(shell pyversions -r); do \
	 	$$py setup.py test ; \
	done
endif

get-orig-source:
	git clone --bare git://github.com/fedora-infra/fedmsg.git fedmsg-orig.git
	git --git-dir=fedmsg-orig.git archive $(shell echo $(UPSTREAM) | cut -d + -f 2  | cut -d . -f 3) | gzip > ../fedmsg_$(UPSTREAM).orig.tar.gz
	rm -rf fedmsg-orig.git
