#! /usr/bin/make -f
############################ -*- Mode: Makefile -*- ###########################
## rules ---
## Author	    : Manoj Srivastava ( srivasta@pilgrim.umass.edu )
## Created On	    : Sat Apr 27 06:36:31 1996
## Created On Node  : melkor.pilgrim.umass.edu
## Last Modified By : Manoj Srivastava
## Last Modified On : Tue Feb  8 14:45:22 2000
## Last Machine Used: glaurung.green-gryphon.com
## Update Count	    : 126
## Status	    : Unknown, Use with caution!
## HISTORY	    :
## Description	    :
##
###############################################################################

#
# VERSION=$(shell LC_ALL=C dpkg-parsechangelog | grep ^Version: | \
#                          sed 's/^Version: *//')
#

# The name of the package (for example, `emacs').
package = $(shell grep Source debian/control | sed 's/^Source: //')

FILES_TO_CLEAN = debian/files debian/buildinfo debian/substvars
STAMPS_TO_CLEAN =  stamp-binary
DIRS_TO_CLEAN  = debian/tmp

CONFLOC:=/etc/cvsdeb.conf
SRCTOP := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
DOCDIR := debian/tmp/usr/share/doc/$(package)


# install commands
install_file= install    -p    -o root -g root -m 644
install_program= install -p    -o root -g root -m 755
make_directory= install  -p -d -o root -g root -m 755
thisdir=$(shell pwd)

all build:
# Builds the binary package.

clean:
	$(checkdir)
	rm -f $(FILES_TO_CLEAN) $(STAMPS_TO_CLEAN)
	rm -f -r debian/tmp
	rm -f core `find . \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
                -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
                -o -name '.*.rej' -o -name '.SUMS' -o -size 0 \) -print` TAGS

binary: binary-arch binary-indep

binary-arch: build
# builds the architecture dependent part

binary-indep: build stamp-binary

stamp-binary:
	@test $$(id | sed -e 's/(.*$$//' -e 's/^uid=//') || \
		(echo need root priviledges; exit 1)
	$(checkdir)
	rm -rf debian/tmp  debian/tmp.deb
	$(make_directory)  debian/tmp/DEBIAN
	$(make_directory)  debian/tmp/etc
	$(make_directory)  debian/tmp/usr/bin
	$(make_directory)  debian/tmp/usr/share/man/man1
	$(make_directory)  debian/tmp/usr/share/man/man5
	$(make_directory)  $(DOCDIR)
	$(install_program) debian/postinst     debian/tmp/DEBIAN/postinst
	$(install_program) debian/prerm        debian/tmp/DEBIAN/prerm
	$(install_file)    debian/conffiles    debian/tmp/DEBIAN/conffiles
	$(install_file)    debian/changelog    $(DOCDIR)/changelog
	$(install_file)    README              $(DOCDIR)/README
	$(install_file)    HOWTO               $(DOCDIR)/HOWTO
	$(install_file)    cvs-pkginit         $(DOCDIR)/cvs-pkginit
	pod2man            cvs-pkginit >       $(DOCDIR)/cvs-pkginit.1
	$(install_file)    cvsdeb.conf.5       debian/tmp/usr/share/man/man5/
	$(install_file)    cvs-buildpackage.1  debian/tmp/usr/share/man/man1
	$(install_file)    cvs-inject.1        debian/tmp/usr/share/man/man1
	$(install_file)    cvs-upgrade.1       debian/tmp/usr/share/man/man1
	$(install_file)    cvs-co-upgrade.1    debian/tmp/usr/share/man/man1
	-gzip -9fqr        debian/tmp/usr/share/man/
	-gzip -9fqr        $(DOCDIR)
	$(install_file)    debian/copyright    $(DOCDIR)/copyright
	$(install_file)    cvsdeb.conf         debian/tmp/etc/cvsdeb.conf
	$(install_program) cvs-buildpackage    debian/tmp/usr/bin/
	$(install_program) cvs-inject          debian/tmp/usr/bin/
	$(install_program) cvs-upgrade         debian/tmp/usr/bin/
	$(install_program) cvs-co-upgrade      debian/tmp/usr/bin/
	dpkg-gencontrol -isp
	chown -R root.root debian/tmp/
	chmod -R go=rX     debian/tmp/
	dpkg --build       debian/tmp ..
	touch              stamp-binary

define checkdir
        @test -f  cvs-buildpackage -a -f debian/rules || \
          (echo Not in correct source directory; exit 1)
endef

source diff:
	@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false

.PHONY: binary binary-arch binary-indep clean


