# LaTeX -*-Makefile-*-
# Contributors: Jeff Squyres, Kyle Wheeler, Branden Moore
# This first section contains macros whose values that you probably
# should fill in.
#
# ****** THIS RELIES ON GNU MAKE *******
# ************* (a lot) ****************
#

# MAIN_TEX: The name of the primary .tex file (unnecesary if there's only one
# or only one with a \documentclass declaration in it)

MAIN_TEX    =

# FIGURES: should be the list of .fig files

FIGURES     = $(wildcard *.fig)

# GRAPHICS: the list of additional .eps files

GRAPHICS    =

# GRAPHS: dot files

GRAPHS      = $(wildcard *.dot)

# BIB_FILES: These are the bibliographical databases (.bib) that are
# required for your document.

BIB_FILES   =

# OTHER_SRC_FILES: Put in the names of all the other files that your
# thesis depends on (e.g., other .tex files, figures, etc.) in the
# OTHER_SRC_FILES macro.  This is ensure that whenever one of the
# "other" files changes, "make" will rebuild your paper.

OTHER_SRC_FILES =

# If you get a "command not found" for the "dvips" command, uncomment
# one of the two commented out DVIPS macros; the first one is for running
# on Sun (Solaris) machines, the second is for running on IBM RS/6000
# (AIX) machines.


#LATEX_HOME = /sw/bin
#LATEX      = $(LATEX_HOME)/latex
#DVIPS      = $(LATEX_HOME)/dvips 

LATEX       = latex
DVIPS       = dvips
BIBTEX      = bibtex
L2H         = latex2html

#DISTILL        = distill -maxsubsetpct 99 -subsetfonts on -pairs 
DISTILL     = ps2pdf
FIGTODEV    = fig2dev

DOT         = dot

#########################################################################
#
# You should not need to edit below this line
#
#########################################################################

# if MAIN_TEX is unset
ifeq ($(words $(MAIN_TEX)), 0)
    TEXFILES = $(wildcard *.tex)
    ifeq ($(words $(TEXFILES)), 1)
        MAIN_TEX = $(TEXFILES)
    else
        TEXDOCS = $(shell egrep -li "^\\documentclass" $(TEXFILES))
        ifeq ($(words $(TEXDOCS)), 1)
            MAIN_TEX = $(TEXDOCS)
        else
            MAIN_TEX = report.tex
        endif
    endif
endif

.SUFFIXES: 
.SUFFIXES: .tex .dvi .ps .pdf .bib .bbl .eps .fig

SHELL       = /bin/sh

CHAP_CITE   = $(CHAP_CITE_TEX:.tex=)
MAIN_DVI    = $(MAIN_TEX:.tex=.dvi)
MAIN_PS     = $(MAIN_TEX:.tex=.ps)
MAIN_PDF    = $(MAIN_TEX:.tex=.pdf)
MAIN_BBL    = $(MAIN_TEX:.tex=.bbl)
BIB_PREFIX  = $(BIB_FILES:.bib=)
EPSFILES    = $(FIGURES:.fig=.eps) $(GRAPHICS) $(GRAPHS:.dot=.eps)

#
# Some common target names
# Note that the default target is "ps"
#

.PHONY: ps postscript pdf acrobat thesis all clean silly-clean

ps: $(MAIN_PS)
postscript: ps
pdf: $(MAIN_PDF)
acrobat: pdf

thesis: ps
all: pdf

#
# Make the dependencies so that things build when they need to
#

DVIDEPENDS = $(MAIN_TEX) $(OTHER_SRC_FILES) $(EPSFILES)

$(MAIN_PS): $(MAIN_DVI)
$(MAIN_PDF): $(MAIN_PS)

ifeq "$(BIB_FILES)" ""
else
$(MAIN_BBL): $(BIB_FILES)
DVIDEPENDS += $(MAIN_BBL)
endif

$(MAIN_DVI): $(DVIDEPENDS)

# Search Strings

REFERENCES = "(There were undefined references|Rerun to get (cross-references|the bars) right)"
NEEDINDEX = "Writing index file"
RERUNBIB = "No file.*\.bbl|Citation.*undefined|LaTeX Warning: Label\(s\) may"


#
# General rules
#

%.bbl: %.bib
    @[ ! -f $*.aux ] && ( $(LATEX) $* ) ; true
    $(BIBTEX) $*

%.dvi: %.tex
    $(LATEX) $*
    @egrep $(NEEDINDEX) $*.log >/dev/null && ($(MAKEINDEX) $* ; $(LATEX) $*) ; true
    @egrep $(RERUNBIB) $*.log >/dev/null && ($(BIBTEX) $(BIB_PREFIX) ; $(LATEX) $*) ; true
    @egrep $(REFERENCES) $*.log >/dev/null && ($(LATEX) $*) ; true
    @egrep $(REFERENCES) $*.log >/dev/null && ($(LATEX) $*) ; true
# display relevant warnings
    @egrep -i '(Reference|Citation).*undefined' $*.log ; true
    @rm -f .success

%.ps: %.dvi
    $(DVIPS) -Ppdf -o $*.ps $*

%.pdf: %.ps
    $(DISTILL) $*.ps $*.pdf

%.eps: %.fig
    $(FIGTODEV) -L eps $< $@

%.eps: %.dot
    $(DOT) -Tps2 $< -o $@

#
# Standard targets
#

silly-clean:
    /bin/rm -f *~ *.bak *%

clean:
    /bin/rm -f *.log *.aux *.dvi *.blg *.toc *.bbl *.lof *.lot *.out \
        $(MAIN_PS) $(MAIN_DVI) $(MAIN_PDF) $(FIGURES:.fig=.eps) $(GRAPHS:.dot=.eps) $(GRAPHS:.dot=.ps)