#!/usr/bin/make -f
# debian.rules file for the Debian/GNU Linux doc-linux package
# Copyright 1995-97 by Dirk Eddelbuettel <edd@debian.org>

# Sample debian.rules file - for GNU Hello (1.3).
# Copyright 1994,1995 by Ian Jackson.
# I hereby give you perpetual unlimited permission to copy,
# modify and relicense this file, provided that you do not remove
# my name from the file itself.  (I assert my moral right of
# paternity under the Copyright, Designs and Patents Act 1988.)
# This file may have to be extensively modified

# There used to be `source' and `diff' targets in this file, and many
# packages also had `changes' and `dist' targets.  These functions
# have been taken over by dpkg-source, dpkg-genchanges and
# dpkg-buildpackage in a package-independent way, and so these targets
# are obsolete.                       

package		= doc-linux
package2	= doc-linux-html
package3	= doc-linux-text
this_dir        = $(shell pwd)
debtmp		= $(this_dir)/debian/tmp
docdir		= $(debtmp)/usr/doc/$(package)
docbase		= $(debtmp)/usr/doc/
howtodir	= $(debtmp)/usr/doc/HOWTO
# the following directories are necessarily local to my machine  --edd
faqloc		= /var/spool/mirror/sunsite/faqs/linux-faq
howloc		= /var/spool/mirror/sunsite/HOWTO
htmlloc		= /var/spool/mirror/sunsite/HOWTO/other-formats/html
htmlminiloc	= /var/spool/mirror/sunsite/HOWTO/mini/other-formats/html
tmptar		= /tmp/howto.tar

build:
	$(checkdir)
	# nothing to be made here  -$(MAKE)
	echo "As long as the mirror of sunsite is recent..."
	touch build

clean:
	$(checkdir)
	# no target clean in makefile  -$(MAKE) -i clean
	-rm -rf *~ debian/tmp debian/*~ debian/files* build index.html

binary-indep:	checkroot build
	$(checkdir)
	-rm -rf $(debtmp)
	install -d $(debtmp)/DEBIAN $(docdir)	   
	install -c -m 0755 debian/{postinst,postrm} $(debtmp)/DEBIAN/.	    
	install -d -m 0755 $(debtmp)/usr/doc/FAQ
	install -c -m 0644 $(faqloc)/Linux-FAQ.gz    $(debtmp)/usr/doc/FAQ
	install -c -m 0644 $(faqloc)/Linux-FAQ.ps.gz $(debtmp)/usr/doc/FAQ
	#install -c -m 0644 $(faqloc)/Linux-FAQ.README $(debtmp)/usr/doc/FAQ
	#install -d -m 0755 $(debtmp)/usr/info
	#install -c -m 0644 $(faqloc)/linux-faq.info.gz $(debtmp)/usr/info
	install -d -m 0755 $(debtmp)/usr/doc/FAQ/html
	(cd $(debtmp)/usr/doc/FAQ/html; \
		tar xfvz $(faqloc)/Linux-FAQ.html.tar.gz; \
		ln -s Linux-FAQ.html index.html)
	install -d -m 0755 $(debtmp)/usr/lib/menu
	install -c -m 0644 debian/menu-faq $(debtmp)/usr/lib/menu/$(package)
	install -c -m 0644 debian/changelog $(docdir)/.
	gzip -9v $(docdir)/*  
	install -c -m 0644 debian/README.debian 	$(docdir)/.
	install -c -m 0644 debian/copyright 		$(docdir)/.
	# dpkg-shlibdeps $(package)
	dpkg-gencontrol -p$(package)
	chown -R root.root debian/tmp
	chmod -R g-ws debian/tmp
	dpkg --build debian/tmp ..  
	#
	# now make the doc-linux-html package
	#
	-rm -rf $(debtmp)
	install -d $(debtmp)/DEBIAN $(docbase)/$(package2)
	install -c -m 0755 debian/{postinst,postrm} $(debtmp)/DEBIAN/.	    
	install -c -m 0755 debian/preinst-html	    $(debtmp)/DEBIAN/preinst
	install -d -m 0755 $(howtodir)/html $(howtodir)/html/mini
	(cd $(howtodir)/html; \
		for i in $(htmlloc)/*html.tar.gz; do tar xfz $$i; done; \
		cd $(howtodir)/html/mini; \
		for i in $(htmlminiloc)/*html.tar.gz; do tar xfz $$i; done; \
		cd $(howtodir)/html; \
		../../../../../index-howtos; )
	install -d -m 0755 $(debtmp)/usr/lib/menu
	install -c -m 0644 debian/menu-html $(debtmp)/usr/lib/menu/$(package2)
	install -c -m 0644 debian/changelog $(docbase)/$(package2)
	gzip -9v $(docbase)/$(package2)/*  
	install -c -m 0644 debian/copyright $(docbase)/$(package2)
	# dpkg-shlibdeps $(package2)
	dpkg-gencontrol -p$(package2)
	chown -R root.root $(debtmp)
	chmod -R g-ws $(debtmp)
	dpkg --build $(debtmp) ..	 
	#
	# now make the doc-linux-text package
	#
	-rm -rf $(debtmp)
	install -d $(debtmp)/DEBIAN  $(docbase)/$(package3)
	install -c -m 0755 debian/{postinst,postrm} $(debtmp)/DEBIAN/.	    
	install -c -m 0755 debian/preinst-text	    $(debtmp)/DEBIAN/preinst
	install -d -m 0755 $(howtodir)
	(cd $(howloc); find . -type f -maxdepth 1 | \
			xargs -r tar cvfp $(tmptar))
	(cd $(howloc); find mini/ unmaintained/ | \
			xargs -r tar rvfp $(tmptar))
	(cd $(howtodir); tar xvfp $(tmptar); rm -f -v $(tmptar))
	rm -fv $(howtodir)/Linux-HOWTOs.tar.gz 
	rm -r  $(howtodir)/mini/other-formats
	chmod -R u+w $(howtodir)
	./debian/make-howtoindex -v $(howtodir) $(howtodir)/mini \
		$(howtodir)/unmaintained $(howtodir)/unmaintained/mini 
	install -c -m 0644 index.html  		$(howtodir)/.
	install -d -m 0755 $(debtmp)/usr/lib/menu
	install -c -m 0644 debian/menu-text $(debtmp)/usr/lib/menu/$(package3)
	install -c -m 0644 debian/changelog $(docbase)/$(package3)
	gzip -9v $(docbase)/$(package3)/*  
	install -c -m 0644 debian/copyright $(docbase)/$(package3)
	# dpkg-shlibdeps $(package3)
	dpkg-gencontrol -p$(package3)
	chown -R root.root $(debtmp)
	chmod -R g-ws $(debtmp)
	dpkg --build $(debtmp) ..	 

binary-arch:	checkroot build
	$(checkdir)
	# There are no architecture-dependent files to be uploaded
	# generated by this package.  If there were any they would be
	# made here.

define checkdir
	# test -f $(package).c doesn't work here: package name != command name
	test -f debian/rules
endef

# Below here is fairly generic really

binary: binary-indep binary-arch

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

checkroot:
	$(checkdir)
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep clean checkroot                  

# Local variables:
#   mode: makefile
# End:

