#!/usr/bin/make -f

# Verbose mode
# export DH_VERBOSE=1

RELEASE_VERSION := 2005

%:
	dh $@ --with python2

override_dh_auto_build:
	[ -d excluded_files/cobbler ] || mkdir -p excluded_files/cobbler
	[ -d excluded_files/koan ] || mkdir -p excluded_files/koan
	mv -f cobbler/sub_process.py excluded_files/cobbler
	mv -f koan/sub_process.py excluded_files/koan
	mv -f koan/opt_parse.py excluded_files/koan
	mv -f koan/text_wrap.py excluded_files/koan
	python setup.py build

override_dh_auto_clean:
	dh_auto_clean
	if [ -d excluded_files/cobbler ] ; then \
		mv excluded_files/cobbler/* cobbler ;\
	fi
	if [ -d excluded_files/koan ] ; then \
		mv excluded_files/koan/* koan ;\
	fi
	if [ -d excluded_files ] ; then \
		rm -rf excluded_files ;\
fi
	rm -f docs/*.gz

override_dh_auto_test:
	nosetests cobbler/*.py || true

override_dh_auto_install:
	python setup.py install -f --install-layout=deb --root=$(CURDIR)/debian/tmp
	mv $(CURDIR)/debian/tmp/usr/sbin/tftpd.py $(CURDIR)/debian/tmp/usr/sbin/tftpd
	chmod -x $(CURDIR)/debian/tmp/var/lib/cobbler/webroot/cobbler/svc/services.py

override_dh_install:
	# remove files we don't want or need
	for i in \
		etc/init.d/cobblerd \
		etc/apache2/conf.d/cobbler.conf \
		etc/apache2/conf.d/cobbler_web.conf \
		etc/cobbler/cobblerd.service \
		etc/cobbler/distro_signatures.json \
		etc/cobbler/users.digest \
		var/lib/cobbler/webroot/cobbler_webui_content/jquery.min.js \
		;do rm -f $(CURDIR)/debian/tmp/$$i; done
	# link to the system jquery.min.js
	ln -s -t $(CURDIR)/debian/tmp/var/lib/cobbler/webroot/cobbler_webui_content \
		/usr/share/javascript/jquery/jquery.min.js

	dh_install --list-missing

# For maintainer use only, generate a tarball:
gentarball: SOURCE=cobbler
gentarball: UV=$(shell dpkg-parsechangelog|awk '/^Version:/ {print $$2}'|sed 's/-.*$$//')
gentarball:
	git archive --format=tar upstream-unstable --prefix=$(SOURCE)-$(UV)/ | gzip -9 > ../$(SOURCE)_$(UV).orig.tar.gz

