#! /usr/bin/make -f
############################ -*- Mode: Makefile -*- ###########################
## debian/rules ---
## Author           : root ( root@melkor.pilgrim.umass.edu )
## Created On       : Tue Jul  9 15:45:40 1996
## Created On Node  : melkor.pilgrim.umass.edu
## Last Modified By : Manoj Srivastava
## Last Modified On : Tue Feb 26 14:13:55 2002
## Last Machine Used: glaurung.green-gryphon.com
## Update Count     : 78
## Status           : Unknown, Use with caution!
## HISTORY          :
## Description      :
##
###############################################################################
#

ifdef ARCH
  ha:=-a$(ARCH)
endif

# set the dpkg-architecture vars
export DEB_BUILD_ARCH      := $(shell dpkg-architecture $(ha) \
                                        -qDEB_BUILD_ARCH)
export DEB_BUILD_GNU_CPU   := $(shell dpkg-architecture $(ha) \
                                        -qDEB_BUILD_GNU_CPU)
export DEB_BUILD_GNU_SYSTEM:= $(shell dpkg-architecture $(ha) \
                                        -qDEB_BUILD_GNU_SYSTEM)
export DEB_BUILD_GNU_TYPE  := $(shell dpkg-architecture $(ha) \
                                        -qDEB_BUILD_GNU_TYPE)
export DEB_HOST_ARCH       := $(shell dpkg-architecture $(ha) \
                                        -qDEB_HOST_ARCH)
export DEB_HOST_GNU_CPU    := $(shell dpkg-architecture $(ha) \
                                        -qDEB_HOST_GNU_CPU)
export DEB_HOST_GNU_SYSTEM := $(shell dpkg-architecture $(ha) \
                                        -qDEB_HOST_GNU_SYSTEM)
export DEB_HOST_GNU_TYPE   := $(shell dpkg-architecture $(ha) \
                                        -qDEB_HOST_GNU_TYPE)


#
# 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: //')
arch=$(shell dpkg --print-gnu-build-architecture)

# The maintainer information.
maintainer = Manoj Srivastava
email= srivasta@debian.org

# Configuration variables (these should be pretty generic)
SRCTOP    = $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi;)
TMPTOP    = $(SRCTOP)/debian/tmp
ETCDIR    = $(TMPTOP)/etc
BINDIR    = $(TMPTOP)/usr/bin
DEBLIBDIR = $(TMPTOP)/var/lib/$(package)
DEBDOCDIR = $(TMPTOP)/usr/share/doc/$(package)
MANDIR    = $(TMPTOP)/usr/share/man/
MAN1DIR   = $(MANDIR)/man1
MAN5DIR   = $(MANDIR)/man5
LINTIANDIR= $(TMPTOP)/usr/share/lintian/overrides

#  Package specific stuff.  The idea is to try to make the rules
#  generic (gradually).

FILES_TO_CLEAN = stamp-configure stamp-build 
DIRS_TO_CLEAN  = $(TMPTOP) 

# install commands
install_file    := /usr/bin/install -p    -o root -g root -m 644
install_program := /usr/bin/install -p    -o root -g root -m 755
make_directory  := /usr/bin/install -p -d -o root -g root -m 755


all build: stamp-build

stamp-build:
# Builds the binary package.
	$(checkdir)
	touch stamp-build

clean:
# Undoes the effect of `$(MAKE) -f debian/rules build'.
	$(checkdir)
	rm -f  $(FILES_TO_CLEAN)
	rm -rf $(DIRS_TO_CLEAN)
	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-indep: build stamp-binary

binary-arch:
	@echo No arch specific binary packages

stamp-binary:
	$(checkroot)
	$(checkdir)
	rm -rf              $(TMPTOP)
	$(make_directory)   $(TMPTOP)
	chmod g-s           $(TMPTOP)
	$(make_directory)   $(TMPTOP)/DEBIAN
	$(make_directory)   $(BINDIR)
	$(make_directory)   $(ETCDIR)
	$(make_directory)   $(MAN1DIR)
	$(make_directory)   $(MAN5DIR)
	$(make_directory)   $(DEBLIBDIR)
	$(make_directory)   $(DEBDOCDIR)
	$(make_directory)   $(LINTIANDIR)
	echo 	            "ucf: postinst-does-not-set-usr-doc-link" \
                                >> $(LINTIANDIR)/$(package)
	$(install_program)  debian/postinst   $(TMPTOP)/DEBIAN/postinst
	$(install_program)  debian/prerm      $(TMPTOP)/DEBIAN/prerm
	$(install_file)     debian/conffiles  $(TMPTOP)/DEBIAN/conffiles
	$(install_program)  ucf               $(BINDIR)
	$(install_file)     ucf.1             $(MAN1DIR)
	$(install_program)  lcf               $(BINDIR)
	$(install_file)     lcf.1             $(MAN1DIR)
	$(install_file)     ucf.conf.5        $(MAN5DIR)
	$(install_file)     ucf.conf          $(ETCDIR)
	$(install_file)     debian/changelog  $(DEBDOCDIR)/changelog
	touch               $(DEBLIBDIR)/hashfile
	gzip -9frq          $(MANDIR)
	gzip -9frq          $(DEBDOCDIR)
# make sure the copyright file is not compressed
	$(install_file)     debian/copyright  $(DEBDOCDIR)/copyright
	chmod -R u+w        $(TMPTOP)/usr/
	dpkg-gencontrol -isp
	chown -R root.root  $(TMPTOP)
	chmod -R go=rX      $(TMPTOP)
	dpkg --build        $(TMPTOP) ..


checkroot:
	test 0 = $$(id | sed -e 's/(.*$$//' -e 's/^uid=//') || \
		(echo need root priviledges; exit 1)

define checkdir
	test -f  ucf.1 -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 
