SHELL  := /bin/bash

out    := derivations

def    := def.tex
main0  := main
bib    := bib.bib
tmpl0  := template

main   := $(main0).tex
ch     := $(filter-out $(main) $(def) $(wildcard $(tmpl0)-*.tex), \
  $(wildcard *.tex))

all : $(out).ps $(out).pdf
.PHONY: all

$(out).dvi : $(main) $(def) $(ch) $(bib)
	rubber $<
	mv -v $(main0).dvi $@
%.dvi      : %.tex $(def)
	rubber $<
%.ps       : %.dvi
	dvips -t letter -o $@ $<
# See the dvipdf(1) and gs(1) manpages for explanation
# of the following rule.
%.pdf      : %.ps
	gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sPAPERSIZE=letter \
	  -sOutputFile=$@ $<

# To "make cleanless" removes the various intermediate TeX working
# files, but leaves intact the final output document files.  The "check"
# target circumvents rubber(1), which quashes LaTeX warnings; with "make
# check", you get an extra latex(1) run which shows any warnings.
.PHONY: check cleanless clean
check      : $(out).dvi
	latex $(main)
cleanless  :
	rm -fv *.{dvi,aux,bbl,blg,idx,ilg,ind,log,lof,lot,toc,bak}
clean      : cleanless
	rm -fv *.{ps,pdf}

