 # ***********************************************************
 # ** This Makefile was originally created by Richard Groff **
 # ***********************************************************
 #
 # - By convention, we have a main tex file $(FILE).tex, from which 
 # various sections of the manual are input.  
 #
 # - "make spell" will run "ispell -t" on # $(FILE).tex and on all files
 # inputed in $(FILE).tex which have the .tex suffix explicitly
 # written out.
 #
 # - In latex, \input{file.tex} and \input{file} will both input the
 # file.tex, but only the first will cause "make spell" to spell check
 # file.tex.  Thus, we input files I don't want to spell check, such as
 # macros, with \input{file}, but sections of papers with
 # \input{file.tex}
 #
 # - The TITLE variable provides the name for the generated postscript file
 # - The GRAPHICSDIR variable should be a : separated list of directories to 
 # search for latex files
 # - DVIVIEW and DVIPS specify the preferences for the dvi viewer and
 # dvi-postscript conversion, respectively.

TITLE   = ModuleManual
FILE	= body
TEXINPUTS = 

# commands
RM  = rm
LATEX = latex
BIBTEX = bibtex
MAKEINDEX = makeindex
DVIPS = dvips -t letter
DVIVIEW = xdvi -p 600 -s 8 -k
DISTILL = distill
#

all:
	@echo "Usage for Latex make file:"
	@echo "make dvi   --   run latex on $(FILE).tex, produce $(FILE).dvi"
	@echo "make full  --   run latex, bibtex, latex, latex on $(FILE).tex"
	@echo "make ps    --   Do 'make full' on $(FILE).tex and then 'dvips'"
	@echo "                to produce $(TITLE).ps"
	@echo "make view  --   start the dvi viewer, \"$(DVIVIEW)\" to look"
	@echo "                at $(FILE).dvi" 
	@echo "make spell --   run 'ispell -t' on $(FILE).tex and all *.tex"
	@echo "                files \\input-ed from $(FILE).tex" 
	@echo "make bib   --   run bibtex on $(FILE).tex"
	@echo "make clean --   remove all temp files"

dvi:
	sh -c '\
	       export TEXINPUTS=.:$(TEXINPUTS):      ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex   '

bib:
	bibtex $(FILE)

full:
	sh -c '\
	       export TEXINPUTS=.:$(TEXINPUTS):       ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(BIBTEX) $(FILE)                          ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(MAKEINDEX) $(FILE)                       ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; '


ps:
	sh -c '\
	       export TEXINPUTS=.:$(TEXINPUTS):       ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(BIBTEX) $(FILE)                          ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(MAKEINDEX) $(FILE)                       ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(DVIPS) -o $(TITLE).ps $(FILE).dvi       ; '
	@echo Wrote file $(TITLE).ps  

pdf:
	sh -c '\
	       export TEXINPUTS=.:$(TEXINPUTS):       ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(BIBTEX) $(FILE)                          ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(MAKEINDEX) $(FILE)                       ; \
	       $(LATEX) \\nonstopmode\\input $(FILE).tex  ; \
	       $(DVIPS) -Ppdf -o $(TITLE)_pdf.ps $(FILE).dvi       ; '
	@echo Wrote file $(TITLE)_pdf.ps
	$(DISTILL) $(TITLE)_pdf.ps $(TITLE).pdf  

$(FILE).dvi: 
	make full

clean:
	$(RM) *%  *~ *.dvi *.idx *.aux *.bbl *.blg *.ilg *.ind *.lof *.log *.lot *.lof *.toc *.loa 2> /dev/null ; true 

realclean:
	$(RM) *%  *~ *.dvi $(TITLE).ps $(TITLE)_pdf.ps *.idx *.aux *.bbl *.blg *.ilg *.ind *.lof *.log *.lot *.lof *.toc *.loa 2> /dev/null ; true 

view: $(FILE).dvi
	sh -c '\
	       export TEXINPUTS=.:$(TEXINPUTS):      ; \
	       $(DVIVIEW) $(FILE).dvi &'	

spell:
	ispell -t $(FILE).tex `grep '\.tex' $(FILE).tex | sed 's/.*\\input{\(.*\)\.tex}/\1.tex/'`










