#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/python/python.mk

configure: configure-stamp
configure-stamp:
	dh_testdir
	touch configure-stamp


build: build-stamp

build-stamp: configure-stamp 
	dh_testdir

	python setup.py build
	docbook-to-man debian/updateSite.sgml > updateSite.1

	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	python setup.py clean --all

# For some reason the previous command creates a file, must erase it.
	dh_clean lib/pubtal/__init__.pyc updateSite.1

install: build
	dh_testdir
	dh_testroot
	dh_clean -k 
	dh_installdirs

	python setup.py install --no-compile --root=$(CURDIR)/debian/pubtal \
	  $(py_setup_install_args) --install-lib=/usr/share/pubtal \
	  --install-scripts=/usr/share/pubtal
	# Install all optional plugins too.
	cp -r optional-plugins/* $(CURDIR)/debian/pubtal/usr/share/pubtal/pubtal/plugins

	# Executables in Debian do not have extensions
	mv $(CURDIR)/debian/pubtal/usr/share/pubtal/updateSite.py \
	  $(CURDIR)/debian/pubtal/usr/share/pubtal/updateSite
	mv $(CURDIR)/debian/pubtal/usr/share/pubtal/uploadSite.py \
	  $(CURDIR)/debian/pubtal/usr/share/pubtal/uploadSite

	# Fix wrong execute permissions
	find $(CURDIR)/debian/pubtal/usr/share/pubtal -name \*.py -exec chmod a-x {} \;

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installchangelogs Changes.txt
	dh_installdocs
	dh_installman
	dh_link
	dh_compress
	dh_fixperms
	dh_python2
# Delete empty dirs
	find $(CURDIR)/debian/pubtal -depth -type d -empty -exec rmdir -- {} \;
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install configure
