PREFIX=manual

DVIROOT=$(PREFIX)-dvi
DVINAME=$(PREFIX).dvi

PDFROOT=$(PREFIX)-pdf
PDFNAME=$(PREFIX).pdf

PSNAME=$(PREFIX).ps

HTMLNAME=$(PREFIX).html

TEX_SRC=packages.tex macros.tex body.tex \
        cover.tex acknow.tex intro.tex use.tex debugger.tex \
        format-defs.tex direct-cc.tex pl-bips.tex fd-cstr.tex \
        c-interface.tex references.tex tbl-contents.tex the-index.tex \
        version_no.tex

VERBOSE=0


.SUFFIXES:
.SUFFIXES: .eps .tex .aux .toc .idx .dvi .ps .hva .html .pdf $(SUFFIXES)

.eps.pdf:
	ps2pdf $< $@


help:
	@echo
	@echo '*** Please read the README file ***'
	@echo
	@echo 'make all       make DVI, PostScript, PDF and HTML versions'
	@echo 'make dvi       make DVI version        (needs LaTeX2e)'
	@echo 'make pdf       make PDF version        (needs pdflatex)'
	@echo 'make ps        make PostScript version (needs dvips)'
	@echo 'make html      make HTML version       (needs HeVeA)'
	@echo
	@echo 'make clean     remove all temporary files'
	@echo 'make distclean same as clean'
	@echo 'make clean-all remove all versions'
	@echo
	@echo 'make help      this help'
	@echo


all: dvi pdf ps html



dvi: fp-dvi $(DVINAME)

fp-dvi:
	@./check_fp dvi $(DVIROOT) $(DVINAME) $(VERBOSE)

$(DVINAME): $(TEX_SRC) compil-scheme.eps debug-box.eps
	latex $(DVIROOT).tex
	makeindex $(DVIROOT).idx
	mv $(DVIROOT).dvi $(DVINAME)
	$(MAKE) dvi



pdf: fp-pdf $(PDFNAME)

fp-pdf:
	@./check_fp pdf $(PDFROOT) $(PDFNAME) $(VERBOSE)

$(PDFNAME): $(TEX_SRC) compil-scheme.pdf debug-box.pdf
	pdflatex $(PDFROOT).tex
	makeindex $(PDFROOT).idx
	mv $(PDFROOT).pdf $(PDFNAME)
	$(MAKE) pdf



ps: dvi $(PSNAME)

$(PSNAME): $(DVINAME)
	dvips -o $(PSNAME) -D 300 $(DVINAME)



html: Html/index.html

$(HTMLNAME): custom.hva $(TEX_SRC)
	hevea -s -exec xxdate.exe -fix custom.hva $(DVIROOT).tex -o $(HTMLNAME)

Html/index.html: $(HTMLNAME)
	rm -f Html/index.html Html/$(PREFIX)*.html
	(cd Html ; hacha ../$(HTMLNAME))

clean:
	rm -f $(DVIROOT).aux $(DVIROOT).toc $(DVIROOT).idx $(DVIROOT).*.fp
	rm -f $(PDFROOT).aux $(PDFROOT).toc $(PDFROOT).idx $(PDFROOT).*.fp


distclean: clean


clean-all: distclean
	rm -f $(DVINAME) $(PDFNAME) $(PSNAME)
	rm -f $(HTMLNAME) Html/$(PREFIX)*.html Html/index.html

clean-aux:
	rm -f *.aux *.toc *.ind *.idx *.log *.haux *.hidx *.hind *.out *.ilg

clean-full: clean-all clean-aux

clean-test:
	rm -f ?.dvi ?.pdf ?.html ?.ps ?.info ?.txt
	rm -f ?.aux ?.toc ?.idx ?.ind ?.log
	rm -f ?.haux ?.hidx ?.hind ?.out ?.ilg


# distributions (DVI and HTML)

DVIDIRNAME=manual-dvi
HTMLDIRNAME=manual-html

dist-dvi: dvi $(DVIDIRNAME).tar.gz

$(DVIDIRNAME).tar.gz: $(DVINAME)
	ln -sf . $(DVIDIRNAME)
	tar cvf $(DVIDIRNAME).tar $(DVIDIRNAME)/$(DVINAME) $(DVIDIRNAME)/??*.eps
	gzip -f $(DVIDIRNAME).tar
	rm -f $(DVIDIRNAME)
	@echo DVI distribution is in $(DVIDIRNAME).tar.gz


dist-html: $(HTMLDIRNAME).tar.gz

$(HTMLDIRNAME).tar.gz: Html/index.html
	ln -sf Html $(HTMLDIRNAME)
	tar cvf $(HTMLDIRNAME).tar $(HTMLDIRNAME)/index.html $(HTMLDIRNAME)/$(PREFIX)*.html $(HTMLDIRNAME)/???*.gif
	gzip -f $(HTMLDIRNAME).tar
	rm -f $(HTMLDIRNAME)
	@echo HTML distribution is in $(HTMLDIRNAME).tar.gz


NAMES_FILE=/tmp/doc_names

names:
	@echo '# file generated by doc/Makefile'   >$(NAMES_FILE)
	@echo "PREFIX=$(PREFIX)"                  >>$(NAMES_FILE)
	@echo "DVINAME=$(DVINAME)"                >>$(NAMES_FILE)
	@echo "PDFNAME=$(PDFNAME)"                >>$(NAMES_FILE)
	@echo "PSNAME=$(PSNAME)"                  >>$(NAMES_FILE)
	@echo "HTMLNAME=$(HTMLNAME)"              >>$(NAMES_FILE)
	@echo "DVIDIRRNAME=$(DVIDIRNAME)"         >>$(NAMES_FILE)
	@echo "DVITARNAME=$(DVIDIRNAME).tar.gz"   >>$(NAMES_FILE)
	@echo "HTMLDIRNAME=$(HTMLDIRNAME)"        >>$(NAMES_FILE)
	@echo "HTMLTARNAME=$(HTMLDIRNAME).tar.gz" >>$(NAMES_FILE)

for-release: all dist-dvi dist-html names
