#
# Generic Makefile for multi-part latex document with no bibliographic
# data.
#
# The main file is assumed to be called $(MAIN).ltx.
#
# List names of component files in the TEXFILES variable.
# This makefile keeps rerunning latex until all cross-references
# are resolved. 
#

MAIN = main

TEXFILES = \

OTHERDEPS = \

TABSUF = lof lot toc

all: $(MAIN).dvi

$(MAIN).PS: $(MAIN).dvi
	dvips -o $(MAIN).PS $(MAIN)

$(MAIN).lj: $(MAIN).dvi
	dvilj -s2 $(MAIN).dvi

$(MAIN).dvi: $(MAIN).aux.no-unres
	echo done

tabcheck:
	@for i in $(TABSUF); do \
		if test -f $(MAIN).$$i; then \
			diff $(MAIN).$$i.old $(MAIN).$$i >/dev/null 2>&1; \
		fi; \
	done

$(MAIN).aux.no-unres: $(MAIN).ltx $(TEXFILES) $(OTHERDEPS)
	-@for i in $(TABSUF); do \
		cp $(MAIN).$$i $(MAIN).$$i.old >/dev/null 2>&1; \
	done
	latex $(MAIN).ltx
	if grep "cross-references right" $(MAIN).log >/dev/null 2>&1; then \
		make $(MAIN).aux.no-unres; fi
	if make tabcheck >/dev/null 2>&1; then true; else latex $(MAIN).ltx; fi
	touch $(MAIN).aux.no-unres

clean:
	-rm -f *.aux *.dvi *.log *.toc *.bbl *.blg *.lof *.lot
	-rm -f *~ *.bak *.aux.*
	-rm -f *.PS TAGS
	-for i in $(TABSUF); do \
		rm -f *.$$i.old; \
	done
