# Makefile for Eplain manuals.  This file is public domain.

MAKEINFO        = makeinfo
MAKEINFO_FLAGS  = 

TEXI2PDF        = texi2dvi
TEXI2PDF_FLAGS  = --pdf

TEXI2DVI        = texi2dvi
TEXI2DVI_FLAGS  = 

DVIPS           = dvips
DVIPS_FLAGS     = -t letter

LATEX           = latex
LATEX_FLAGS     = 

BIBTEX          = bibtex
BIBTEX_FLAGS    = 

LATEX2HTML      = latex2html
LATEX2HTML_FLAGS= 

PDFTOPS         = pdftops
PDFTOPS_FLAGS   = 

PDFCROP         = ../util/pdfcrop.pl
PDFCROP_FLAGS   = 

CONVERT         = convert
CONVERT_FLAGS   = -quality 75


DEMO_DIR   = ../demo
PDF_DEMOS  = xhyper.pdf lscommnt.pdf
EPS_DEMOS  = $(PDF_DEMOS:%.pdf=%.eps)
JPG_DEMOS  = $(PDF_DEMOS:%.pdf=%.jpg)

.PHONY: all doc dvi ps pdf html info btxdoc
.PHONY: clean mostlyclean distclean maintainer-clean
.DELETE_ON_ERROR:


all: doc ../INSTALL btxdoc

doc: dvi pdf html info

dvi: eplain.dvi
eplain.dvi: *.texi $(EPS_DEMOS)
	$(TEXI2DVI) $(TEXI2DVI_FLAGS) eplain.texi

ps: eplain.ps
eplain.ps: eplain.dvi
	$(DVIPS) $(DVIPS_FLAGS) $< -o

pdf: eplain.pdf
eplain.pdf: *.texi $(PDF_DEMOS)
	$(TEXI2PDF) $(TEXI2PDF_FLAGS) eplain.texi

html: eplain/index.html
eplain/index.html: *.texi $(JPG_DEMOS)
	$(MAKEINFO) $(MAKEINFO_FLAGS) --html eplain.texi
	$(MAKEINFO) $(MAKEINFO_FLAGS) --html --no-split eplain.texi
	cp $(JPG_DEMOS) eplain

info: eplain.info
eplain.info: *.texi
	$(MAKEINFO) $(MAKEINFO_FLAGS) --no-split eplain.texi

btxdoc: btxdoc/index.html
btxdoc/index.html: btxdoc.tex btxdoc.bib
	$(LATEX) $(LATEX_FLAGS) btxdoc
	$(BIBTEX) $(BIBTEX_FLAGS) btxdoc
	$(LATEX) $(LATEX_FLAGS) btxdoc
	$(LATEX2HTML) $(LATEX2HTML_FLAGS) -local_icons btxdoc

../INSTALL: install.texi
	$(MAKEINFO) $(MAKEINFO_FLAGS) --no-number-section \
	  --no-warn --no-headers eplain.texi -o - \
	  | sed -n '/^Installation/,/^Invoking/'p \
	  | sed '$$d' > ../INSTALL

#
# Images for the "Demo files" section of the manual.
#
$(PDF_DEMOS):
	$(MAKE) -C $(DEMO_DIR) $@
	$(PDFCROP) $(PDFCROP_FLAGS) $(DEMO_DIR)/$@ $@

$(EPS_DEMOS): %.eps: %.pdf
	$(PDFTOPS) $(PDFTOPS_FLAGS) -eps $<

$(JPG_DEMOS): %.jpg: %.pdf
	$(CONVERT) $(CONVERT_FLAGS) $< $@

#
# Clean-up.
#
clean mostlyclean:
	rm -f eplain.?? eplain.{aux,cps,fns,log,toc}
	rm -f btxdoc.{aux,bbl,blg,dvi,log}
	rm -f $(PDF_DEMOS)
	rm -f $(EPS_DEMOS)

distclean: clean
	rm -rf eplain.dvi eplain btxdoc

maintainer-clean: distclean
	rm -f $(JPG_DEMOS)
	rm -f ../INSTALL eplain.info eplain.pdf eplain.html
