#! /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 : Fri Feb 27 16:27:10 1998
## Last Machine Used: tiamat.datasync.com
## Update Count	    : 122
## Status	    : Unknown, Use with caution!
## HISTORY	    :
## Description	    :
##
###############################################################################

#    $Id: rules,v 1.11 1998/02/27 22:27:17 srivasta Exp $


# Please change the maintainer information, as well as the debian version
# below, (and maybe the priority as well, espescially if you are uploading
# an official package)

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

# Priority of this version (or urgency, as dchanges would call it)
priority := Low
#  Package specific stuff

# The name of the package (for example, `emacs').
package = kernel-package
version := $(shell perl -n0777e 'if ($$. == 1 && m/\(([\S]+)\)/o){print "$$1\n";}' debian/changelog)


FILES_TO_CLEAN = debian/files
STAMPS_TO_CLEAN =  stamp-binary
DIRS_TO_CLEAN  =

CONFLOC:=/etc/kernel-pkg.conf
LIBLOC:=/usr/lib/kernel-package
MODULE_LOC := /usr/src/modules

# Location of the source dir
SRCTOP := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
# where kernel-package files go to
DEBDIR := $(LIBLOC)
DEBDIR_NAME:= $(shell basename $(DEBDIR))

DOCDIR = debian/tmp/usr/doc/$(package)
MAN5DIR = debian/tmp/usr/man/man5
MAN8DIR = debian/tmp/usr/man/man8

# 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


all build:
# Builds the binary package.

clean:
	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 root = "`whoami`" || (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/sbin
	$(make_directory)  debian/tmp/usr/lib/$(package)
	$(make_directory)  $(MAN5DIR)
	$(make_directory)  $(MAN8DIR)
	$(make_directory)  $(DOCDIR)
	$(install_file)    debian/conffiles debian/tmp/DEBIAN/conffiles
	$(install_program) debian/postinst debian/tmp/DEBIAN/postinst
	$(install_file)    debian/changelog $(DOCDIR)/changelog
	$(install_file)    README $(DOCDIR)/README
	$(install_file)    kernel/Flavours $(DOCDIR)/Flavours
	$(install_file)    Problems $(DOCDIR)/Problems
	$(install_file)    Multi-Arch $(DOCDIR)/Multi-Arch
	$(install_file)    Rationale $(DOCDIR)/Rationale
	gzip -9fqr         $(DOCDIR)
	$(install_file)    debian/copyright $(DOCDIR)/copyright
	$(install_file)    kernel-pkg.conf.5 $(MAN5DIR)/kernel-pkg.conf.5
	$(install_file)    make-kpkg.8  $(MAN8DIR)/make-kpkg.8
	$(install_file)    kernel-packageconfig.8  $(MAN8DIR)/
	gzip -9fqr         debian/tmp/usr/man
	$(install_file)    kernel-pkg.conf debian/tmp/etc/kernel-pkg.conf
	$(install_program) kernel-packageconfig \
		           debian/tmp/usr/sbin/kernel-packageconfig
	$(install_program) make-kpkg debian/tmp/usr/sbin/make-kpkg
	(cd kernel;        tar cf - * | \
           (cd             $(SRCTOP)/debian/tmp/usr/lib/$(package);\
                           tar xf -))
	$(install_file)    Rationale $(SRCTOP)/debian/tmp/usr/lib/$(package)/
	# Hack, tell the   rules file what version of kernel package it is
	sed -e             's/=K=V/$(version)/' kernel/rules > \
                              $(SRCTOP)/debian/tmp/usr/lib/$(package)/rules
	dpkg-gencontrol
	chown -R root.root debian/tmp
	dpkg --build       debian/tmp ..
	touch              stamp-binary

define checkdir
        test -f  make-kpkg -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

