#!/usr/bin/make -f
# -----------------------------------------------------------------------------
# First coded by Luca - De Whiskey's - De Vitis <luca@debian.org>
# -----------------------------------------------------------------------------
# $Id: rules,v 1.3 2003/11/03 14:15:26 luca Exp $
#
#   Copyright (C) @year@ Luca - De Whiskey's - De Vitis <luca@debian.org>
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


version = 2.2
python  = python$(version)
debian  = debian/zopectl
lib     = $(debian)/usr/lib/$(python)/site-packages
sbin	= $(debian)/usr/sbin
etc		= $(debian)/etc/zopectl
man		= $(debian)/usr/share/man/man8

txt2man = txt2man -s $(2) -v Zope -t $(1) > $(1).$(2)

command = echo "import ZopeCTL" ; echo "print ZopeCTL.$(1).__doc__"

extract = ($(call command,$(1))) | $(python) | $(call txt2man,$(2),$(3))

zopectl.8:
	$(call extract,ZopeController,zopectl,8)

zopectlrc.5:
	$(call extract,ZopeInstanceConf,zopectlrc,5)

build: build-stamp
build-stamp: zopectl.8 zopectlrc.5
	dh_testdir
	touch build-stamp

clean:
	dh_testdir
	dh_testroot
	rm -f build-stamp
	rm -rf *.8 *.5 ZopeCTL.pyc var
	dh_clean

install: build-stamp
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs
	install -m 0644 -D ZopeCTL.py $(lib)/ZopeCTL.py
	install -m 0755 zopectl $(sbin)
	install -m 0644 etc/zopectlrc etc/default.conf $(etc)

# Build architecture-independent files here.
binary-indep: install
	dh_testdir
	dh_testroot
	dh_installchangelogs 
	dh_installdocs
	dh_installman
	dh_installexamples
	dh_link
	dh_compress
	dh_fixperms
	dh_installdeb
	dh_python -V $(version)
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

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