#!/usr/bin/make -f
# example debian/rules for cdbs packages

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/class/python-distutils.mk

DEB_PYTHON_COMPILE_VERSION = 2.4

PYTHON = python$(DEB_PYTHON_COMPILE_VERSION)
PACKAGE := webcleaner
BASE := debian/$(PACKAGE)
DOCDIR := $(BASE)/usr/share/doc/$(PACKAGE)
SHAREDIR := $(BASE)/usr/share/$(PACKAGE)
ETCDIR := $(BASE)/etc/$(PACKAGE)
SERVICEDIR := $(ETCDIR)/service

# exclude files with special permissions
DEB_FIXPERMS_EXCLUDE += /etc/webcleaner/webcleaner.conf /var/log/webcleaner
# do not install with "make", but with "python setup.py install"
DEB_MAKE_INSTALL_TARGET =
# webcleaner gets the python files
DEB_DESTDIR = $(BASE)

makebuilddir/webcleaner::
	$(PYTHON) setup.py sdist --manifest-only
# for CVS build regenerate ./configure
	@if ! test -f ./configure; then ./autogen.sh; fi

binary-post-install/webcleaner-common::
# move files
	dh_movefiles --sourcedir=debian/webcleaner
# and cleanup after moving
	rm -rf $(BASE)/usr/share/webcleaner/templates
	rm -rf $(BASE)/usr/share/webcleaner/examples
	chown root:adm $(BASE)/var/log/webcleaner
	chmod 0750 $(BASE)/var/log/webcleaner
# delete INSTALL file
	rm -f $(DOCDIR)/INSTALL
# move config files
	mv $(SHAREDIR)/config/* $(ETCDIR)/
	rmdir $(SHAREDIR)/config
	ln -s /etc/webcleaner $(SHAREDIR)/config
# replace logging.conf
	rm $(ETCDIR)/logging.conf
	install -m 0644 debian/logging.conf $(ETCDIR)/logging.conf
# fix config permission
	chmod go-rwx $(ETCDIR)/webcleaner.conf
# install service files
	install -m 0755 service/webcleaner/run2 $(SERVICEDIR)/run
	install -m 0755 service/webcleaner/log/run $(SERVICEDIR)/log/
	install -m 0755 debian/webcleaner-ctl $(BASE)/usr/bin
# overrides
	install -m 0644 debian/webcleaner.lintian debian/webcleaner/usr/share/lintian/overrides/webcleaner
	install -m 0644 debian/webcleaner.linda debian/webcleaner/usr/share/linda/overrides/webcleaner
