#!/usr/bin/make -f

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

%:
	dh $@ --with python2,sphinxdoc,systemd --buildsystem=pybuild

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

override_dh_auto_install:
	dh_auto_install

	# Grab the fedmsg config
	mkdir -p debian/tmp/etc/
	cp -r fedmsg.d debian/tmp/etc/

	# Install the extras
	mkdir -p debian/tmp/usr/share/fedmsg/
	cp -r extras debian/tmp/usr/share/fedmsg

	# useless SOURCES.txt files
	rm debian/tmp/usr/lib/python2*/dist-packages/fedmsg*.egg-info/SOURCES.txt

override_dh_install:
	dh_install --fail-missing

override_dh_auto_clean:
	dh_auto_clean
	rm -rf doc/_build/
	rm -rf fedmsg/tests/fedmsg.d/

override_dh_installchangelogs:
	dh_installchangelogs -k CHANGELOG.rst

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	cp -r fedmsg.d fedmsg/tests/
	dh_auto_test
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
