# Makefile to generate documentation in HTML (+.plt), PS and PDF
# format, with no rerun necessary.

# Copyright (C) 2004  Sylvain Beucler
# Copyright (C) 2004  Julien Charles
# Copyright (C) 2004  Pierre Chtel
# Copyright (C) 2004  Cyril Rodas

# This file is part of SpcialK

# SpcialK is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# SpcialK is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with program; see the file COPYING. If not, write to the Free
# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.

# $Header: /cvs/ter/specialk/doc/Makefile,v 1.16 2004/06/14 09:59:10 sylvain Exp $

TEX=latex
DOCUMENTS=specialk specialk-fr

.PHONY: clean veryclean all

all: specialk.html

%-doc.plt: DIR=$(shell cat $*.hdir | sed 's/\jobname/$*/')
%-doc.plt: DESCRIPTION=$(shell cat $*-doc.description)
%-doc.plt: %.html
	rm -rf collects
	mkdir -p collects/doc/$*
	mzscheme -r makehdindex.ss --docname $* --keywords $(DIR)
	cp -a $(DIR)/* collects/doc/$*
	-rm -f collects/doc/$*/$*.hlog
	-rm -f collects/doc/$*/$*--h.*
	-rm -f collects/doc/$*/$*-Z*.scm
	mzc --replace --all-users --plt $*-doc.plt --plt-name "$(DESCRIPTION)" collects/doc/$*

%.html: DIR=$(shell cat $*.hdir | sed 's/\jobname/$*/')
%.html: %.tex
	while (tex2page $<; grep 'Rerun: tex2page ' $(DIR)/$*.hlog 2>&1 > /dev/null); do true; done

%.dvi: %.tex
	while (makeindex $*.idx; $(TEX) $<; grep -E 'Rerun|Undefined references|has been referenced but' $*.log 2>&1 > /dev/null); do true; done

%.ps: %.dvi
	dvips $< -o $@

%.eps: %.png
	pngtopnm $< | pnmtops -noturn > $@

%.pdf: TEX=pdflatex
%.pdf: %.dvi
	@true

veryclean: clean
	-for i in $(DOCUMENTS); do rm -f $$i.pdf $$i.ps $$i-doc.plt; done

clean:
	-rm -f *.aux *.dvi *.idx *.ind *.ilg *.log *.out *.toc
	-for i in $(DOCUMENTS); do rm -rf `cat $$i.hdir | sed 's/\\\\jobname/$(DOCUMENT)/'`; done
	-for i in $(DOCUMENTS); do rm -rf $$i-Z*; done # TeX2Page temporary files
	-rm -f *~ .*~
	-rm -rf collects
