#!/usr/bin/make -f
# -*- makefile -*-
#
#
UPSTREAM_VERSION = $(shell dpkg-parsechangelog --show-field Version | awk '-F[:+]' '{print$$1}')
UPSTREAM_MAJOR = $(shell dpkg-parsechangelog --show-field Version | awk '-F[:+]' '{print$$1}')
UPSTREAM_DEB =  http://downloads.vmd.citrix.com/OpenStack/xe-guest-utilities/xe-guest-utilities_${UPSTREAM_MAJOR}_amd64.deb
PKG_NAME = $(shell dpkg-parsechangelog --show-field Source)
SPKG_VER = $(shell dpkg-parsechangelog --show-field Version |  awk '-F[:-]' '{print$$1"-"$$2}' )
SRC_PKG = $(PKG_NAME)_$(SPKG_VER).orig.tar.gz
CURDIR = $(shell pwd)

%:
	dh $@

get-packaged-orig-source:
	wget -O orig.deb $(UPSTREAM_DEB)
	mkdir extracted
	dpkg -x orig.deb extracted
	# Remove the binary xen-store utilities
	rm -rf extracted/usr/bin
	# Drop the share file as redundant. This contains superceeded copyright
	# notices that are not in the correct format and deprecated apt sources list.
	rm -rf extracted/usr/share
	# We don't need the old init.d job
	rm -rf extracted/etc
	tar -C extracted -zcvf $(CURDIR)/$(SRC_PKG) .

override_dh_installinit:
	dh_installinit --no-restart-on-upgrade --name xe-daemon
	dh_installinit --no-restart-on-upgrade --name xe-cloud

override_dh_systemd_enable:
	dh_systemd_enable --name xe-daemon xe-daemon.service


.PHONY: get-orig-source
