#!/usr/bin/make -f

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

override_dh_installinit:
	dh_installinit --name maas-pserv
	dh_installinit --name maas-txlongpoll

override_dh_auto_install:
	dh_auto_install

	# Copy the local config file
	install -d -m 755  $(CURDIR)/debian/tmp/etc/maas
	cp $(CURDIR)/contrib/maas_local_settings_sample.py \
                $(CURDIR)/debian/tmp/etc/maas/maas_local_settings.py

	# Move static files
	install -d -m 755  $(CURDIR)/debian/tmp/usr/share/maas/web/static
	mv $(CURDIR)/debian/tmp/usr/lib/python*/*-packages/maasserver/static \
                $(CURDIR)/debian/tmp/usr/share/maas/web/

	dh_install --list-missing

DEB_DEBIAN_DIR=$(dir $(firstword $(MAKEFILE_LIST)))
REV=$(shell dpkg-parsechangelog -l$(DEB_DEBIAN_DIR)/changelog \
              | sed -rne 's,^Version: .*[+~]bzr([0-9]+).*,\1,p')
VER=$(shell dpkg-parsechangelog -l$(DEB_DEBIAN_DIR)/changelog \
              | sed -rne 's,^Version: ([^-]+).*,\1,p')
get-orig-source:
	bzr export -r $(REV) --root=maas-$(VER).orig \
             maas_$(VER).orig.tar.gz lp:maas
	rm -rf maas-$(VER)
	tar -xf maas_$(VER).orig.tar.gz
	rm maas_$(VER).orig.tar.gz
	rm maas-$(VER).orig/src/maasserver/static/jslibs/yui/3.4.1/build/uploader/assets/uploader.swf
	rm maas-$(VER).orig/src/maasserver/static/jslibs/yui/3.4.1/build/io-xdr/io.swf
	GZIP=--best tar -cz --owner root --group root --mode a+rX \
                        -f maas_$(VER).orig.tar.gz \
                        maas-$(VER).orig
	rm -r maas-$(VER).orig
