#!/usr/bin/make -f

# Verbose mode
#export DH_VERBOSE=1

WITH_PYTHON2 = $(shell test -f /usr/bin/dh_python2 && echo "--with python2")

%:
	dh $@ ${WITH_PYTHON2}

get-orig-source:
	uscan --verbose --force-download --rename --destdir=../build-area

UPSTREAM_GIT=git://github.com/openstack/glance.git
DEBIAN_VERSION=$(shell dpkg-parsechangelog |  sed -n 's/^Version: \(.*\)-[^-]*/\1/p')
DEBIAN_NAME=glance

get-orig-source-git:
	git clone $(UPSTREAM_GIT) $(DEBIAN_NAME)
	cd $(DEBIAN_NAME) ; \
	git checkout stable/essex ; \
	python setup.py sdist ; \
	mv dist/glance-2012.1.tar.gz ../glance_$(DEBIAN_VERSION).orig.tar.gz

override_dh_install:
	dh_install

ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	bash run_tests.sh -N
endif

override_dh_auto_build:
	dh_auto_build
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	mkdir doc/build
	python setup.py build_sphinx
else
	mkdir -p doc/build/html
endif

override_dh_auto_clean:
	dh_auto_clean
	rm -rf doc/build
	rm -rf glance.sqlite

override_dh_installinit:
	dh_installinit --name glance-api
	dh_installinit --name glance-registry
