##
##  wml_backend/p2_mhc/doc/Makefile
##  Copyright (c) 1999 Denis Barbier
##
## This file is part of the WML program, see the file
## ../../../COPYRIGHT for details on copyright

## Maintaining accurate documentation on wml_p2_mhc is not an
## easy task, because the way mhc is used inside meta-html and wml
## are very different.
## As for now, the wml_p2_mhc documentation is a stripped down version
## of the meta-html doc, containing only the chapters included into
## wml_p2_mhc. To help maintenance, i wrote make-doc.mhtml, which is a
## modified version of make-printable.mhtml. It allows automatic
## generation from the documented sources.

## The metahtml.txt is included into distributions, because it needs
## some packages people may not have (tex, texinfo, tex2html).
## The metahtml.txt should *not* be modified. Update either the C source
## files or the make-doc.mhtml files.

## To build metahtml.html,
## * get the original meta-html documentation
##   After unpacking metahtml-x.yz.tar.gz
##        mv metahtml-x.yz/doc/manual .
## * type `make'

## What is the simplest way to convert metahtml.html into metahtml.txt?

DOCDIR	= manual
MHC	= ../../mhc/mhc \
		--set mhtml::include-prefix . \
		--set header-already-included true

all: check-directory metahtml.txt

check-directory:
	@test -d manual \
		|| { echo "Please read this Makefile for instructions"; exit 1; }

metahtml.txt: $(DOCDIR)/metahtml.html
	lynx -dump -nolist $< > $@

$(DOCDIR)/metahtml.html: $(DOCDIR)/metahtml.texi
	cd $(DOCDIR); \
	  tex metahtml.texi; \
	  texindex metahtml.??; \
	  sed -e "/\\\\initial/d" -e "s/\\\\entry {\\\\code/'xrdef/" \
		-e "s/}}{/-pg}{/" metahtml.fns >> metahtml.aux; \
	  cp metahtml.aux metahtml.newaux; \
	  tex metahtml.texi; \
	  sed -e "/\\\\initial/d" -e "s/\\\\entry {\\\\code/'xrdef/" \
		-e "s/}}{/-pg}{/" metahtml.fns >> metahtml.aux; \
	  cp metahtml.aux metahtml.newaux; \
	  texi2html metahtml.texi
	sed -e 's,@xref{\([^}]*\)},\1 (<i>not included in this document</i>),' $@ > $@.tmp && mv $@.tmp $@

$(DOCDIR)/metahtml.texi: make-doc.mhtml $(DOCDIR)/sections.db.packed
	cd $(DOCDIR); $(MHC) ../make-doc.mhtml |\
	  sed -e 's/^[ 	]*@/@/' |\
	  perl -e '$$/=undef; $$_=<STDIN>; s/^[\s]*(\\input texinfo)/\1/m; print;' > ../$@
## These last 2 lines are needed to fix bugs in texi2html

$(DOCDIR)/sections.db.packed: ../libmhtml/sections.db.packed
	cp ../libmhtml/*.db.packed $(DOCDIR)

../libmhtml/sections.db.packed:
	cd ../libmhtml; $(MAKE) sections.db.packed
