#!/usr/bin/make -f
############################ -*- Mode: Makefile -*- ###########################
## rules ---
## Author	    : Manoj Srivastava ( srivasta@tiamat.datasync.com )
## Created On	    : Sun Mar 15 15:00:40 1998
## Created On Node  : tiamat.datasync.com
## Last Modified By : Manoj Srivastava
## Last Modified On : Wed Mar 18 00:30:19 1998
## Last Machine Used: tiamat.datasync.com
## Update Count	    : 24
## Status	    : Unknown, Use with caution!
## HISTORY	    :
## Description	    :
## $Id$
###############################################################################
FILES_TO_CLEAN	= debian/files debian/buildinfo debian/substvars \
		  sgml_layout.text
STAMPS_TO_CLEAN = stamp-configure stamp-build stamp-binary
DIRS_TO_CLEAN	= debian/tmp sgml_layout.html
thisdir		= $(shell pwd)

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
deb_rule	= $(MAKE) -f $(thisdir)/debian/rules

package := $(shell grep Source debian/control | sed 's/^Source: //')
version := $(shell perl -n0777e 'if ($$. == 1 && m/\(([\S]+)\)/o){print "$$1\n";}' debian/changelog)

DOCDIR	:= debian/tmp/usr/doc/$(package)
LIBDIR	:= debian/tmp/usr/lib/sgml
BINDIR	:= debian/tmp/usr/sbin
MANDIR	:= debian/tmp/usr/man/man8
ETCDIR	:= debian/tmp/etc


all build: configure stamp-build
stamp-build:
# Builds the binary package.
	$(checkdir)
	-(if [ -x	    /usr/bin/debiandoc2html ] ; then   \
	    debiandoc2text  sgml_layout.sgml ;		       \
	  fi)
	-(if [ -x	    /usr/bin/debiandoc2html ] ; then   \
	    debiandoc2html  sgml_layout.sgml ;		       \
	  fi)
	dpkg -l perl sp jade sgml-data make dpkg-dev | \
	  awk '$$1 == "ii" { printf("%s-%s\n", $$2, $$3) }' > \
	   debian/buildinfo
	touch stamp-build

configure: stamp-configure  Makefile
Makefile stamp-configure:
	$(checkdir)
	touch stamp-configure

clean:
# Undoes the effect of `make -f debian/rules build'.
	$(checkdir)
	rm -f  $(FILES_TO_CLEAN) $(STAMPS_TO_CLEAN)
	rm -rf $(DIRS_TO_CLEAN)
	-test -f Makefile && $(MAKE) realclean
	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

binary-indep: build stamp-binary
stamp-binary:
# Makes a binary package.
	test root = "`whoami`" || (echo need root priviledges; exit 1)
	$(checkdir)
	test -f stamp-build || $(deb_rule) build
	-rm -rf debian/tmp
	$(make_directory)   debian/tmp
	chmod g-s	    debian/tmp
	$(make_directory)   debian/tmp/DEBIAN
	$(make_directory)   $(MANDIR)
	$(make_directory)   $(BINDIR)
	$(make_directory)   $(DOCDIR)
	$(make_directory)   $(LIBDIR)
	$(make_directory)   $(ETCDIR)
	$(install_file)	    README		    $(DOCDIR)
	$(install_file)	    sgml_layout.sgml	    $(DOCDIR)
	$(install_file)	    debian/changelog	    $(DOCDIR)
	$(install_file)	    debian/buildinfo	    $(DOCDIR)/buildinfo.Debian
	$(install_program)  install-sgmlcatalog	    $(BINDIR)
	$(install_file)	    install-sgmlcatalog.8   $(MANDIR)
	$(install_file)	    sgml.catalog	    $(ETCDIR)
	-(if [ -f	    sgml_layout.text ] ; then	       \
	    $(install_file) sgml_layout.text	    $(DOCDIR); \
	  fi)
	-gzip -9qfr	    $(DOCDIR)
	-(if [ -d	    sgml_layout.html ] ; then	       \
	    (cd		    sgml_layout.html; tar cf - . |     \
			      (cd ../$(DOCDIR); tar xvpf -));  \
	  fi)
	$(install_file)	    debian/copyright	    $(DOCDIR)
	$(install_file)	    debian/conffiles	    debian/tmp/DEBIAN/
	-gzip -9qfr	    debian/tmp/usr/man/
	(cd $(LIBDIR);	    ln -s /etc/sgml.catalog catalog)
	dpkg-gencontrol
	chown		    -R root.root debian/tmp
	chmod		    -R go=rX	 debian/tmp
	dpkg-deb	    --build	 debian/tmp ..

define checkdir
	test -f sgml.catalog -a -f debian/rules
endef

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

.PHONY: binary binary-arch binary-indep clean
