#!/usr/bin/make -f
# Derived from: 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.

SHELL=/bin/bash

package=linuxdoc-tools

# for FHS transition
DOCDIR=/usr/share/doc/$(package)
MANDIR=/usr/share/man
INFODIR=/usr/share/info

# The next section may have to be extensively modified

build:
	$(checkdir)
	PATH=/usr/bin:$(PATH) ./configure --prefix=/usr \
	 --mandir=$(MANDIR) --with-installed-nsgmls
	$(MAKE) prefix=/usr mandir=$(MANDIR) PERL=/usr/bin/perl \
	  OPTIMIZE="-g -O2"
	touch build

clean:
	$(checkdir)
	-rm -f .depend
	-rm -f build
	-$(MAKE) distclean
	-find . -name \*~| xargs -r rm -f
	-rm -rf debian/tmp debian/*~ debian/files debian/substvars
	-for d in entity-map iso-entities ; do \
	     ( cd $$d && make distclean); \
	  done
	-rm -f {entity-map,iso-entities}/Makefile

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

binary-arch:	checkroot build
	-rm -rf debian/tmp
	install -d debian/tmp/DEBIAN
	cp debian/control debian/tmp/DEBIAN
	install debian/{prerm,postinst,postrm} debian/tmp/DEBIAN
	install -d debian/tmp$(DOCDIR)
#
# create copyright file by merging some files
	cp debian/copyright debian/tmp$(DOCDIR)
	echo -e '\n------------------\n The linuxdoc-tools license\n' >>\
		debian/tmp$(DOCDIR)/copyright
	cat COPYING >>debian/tmp$(DOCDIR)/copyright
	echo -e '\n------------------\n The sgmls license\n' >>\
		debian/tmp$(DOCDIR)/copyright
	cat sgmls-1.1/LICENSE >>debian/tmp$(DOCDIR)/copyright
#
# sp is no longer included.
#	echo -e '\n------------------\n The sp license\n' >>\
#		debian/tmp$(DOCDIR)/copyright
#	cat sp/COPYING >>debian/tmp$(DOCDIR)/copyright
	echo -e '\n------------------\n The iso-entities license\n' >>\
		debian/tmp$(DOCDIR)/copyright
	cat iso-entities/COPYING >>debian/tmp$(DOCDIR)/copyright
	echo -e '\n------------------\n The entity-map license\n' >>\
		debian/tmp$(DOCDIR)/copyright
	cat entity-map/COPYING >>debian/tmp$(DOCDIR)/copyright
#
# do 'make install'
	$(MAKE) prefix=`pwd`/debian/tmp/usr \
		datadir=`pwd`/debian/tmp/usr/lib \
		PERL=/usr/bin/perl \
		mandir=`pwd`/debian/tmp/usr/share/man \
		bindir=`pwd`/debian/tmp/usr/bin install
# 
# some Debian specific work
	find debian/tmp$(DOCDIR)/ -type f \
	     -not \( -name \*.gz -o -name copyright \) | xargs gzip -9f
	find debian/tmp$(DOCDIR)/html -type f -name '*.gz'| xargs gzip -d
	install -d debian/tmp$(INFODIR)
	mv debian/tmp$(DOCDIR)/guide.info.gz \
		debian/tmp$(INFODIR)/linuxdoc-sgml.info.gz
	(cd debian/tmp$(DOCDIR) && \
		ln -s ../../info/linuxdoc-sgml.info.gz . )
	install -d debian/tmp/usr/lib/sgml/
	mv debian/tmp/usr/lib/linuxdoc-tools/dtd \
		debian/tmp/usr/lib/sgml/
	ln -s ../sgml/dtd debian/tmp/usr/lib/linuxdoc-tools/
	install -d debian/tmp/usr/share/texmf/tex/latex/misc/
	mv debian/tmp/usr/lib/linuxdoc-tools/{linuxdoc-sgml,linuxdoctr-sgml,qwertz,null}.sty \
		debian/tmp/usr/share/texmf/tex/latex/misc
	rm -f debian/tmp/usr/lib/linuxdoc-tools/*sty
#
# doc-base support
	install -d debian/tmp/usr/share/doc-base/
	cp debian/doc-base.linuxdoc-tools debian/tmp/usr/share/doc-base/linuxdoc-tools
#
	strip debian/tmp/usr/bin/{rtf2rtf,sgmlsasp}
	rm -f debian/tmp/usr/bin/*~
	gzip -9f debian/tmp$(MANDIR)/man?/*
	cp debian/changelog debian/tmp$(DOCDIR)/changelog.Debian
	cp ChangeLog debian/tmp$(DOCDIR)/changelog
	gzip -9f debian/tmp$(DOCDIR)/changelog*
	dpkg-shlibdeps sgmls-1.1/sgmlsasp
	dpkg-gencontrol -isp
	chown -R root.root debian/tmp
	chmod -R a+r debian/tmp$(DOCDIR)
	chmod -R u+w debian/tmp
	chmod -R g-ws debian/tmp
	dpkg --build debian/tmp ..

define checkdir
	test -f bin/linuxdoc.in
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

