# LaTeX -*-Makefile-*-
#
# Copyright (c) 2001-2003 The Trustees of Indiana University.  
#                         All rights reserved.
# Copyright (c) 1998-2001 University of Notre Dame. 
#                         All rights reserved.
# Copyright (c) 1994-1998 The Ohio State University.  
#                         All rights reserved.
# 
# This file is part of the LAM/MPI software package.  For license
# information, see the LICENSE file in the top level directory of the
# LAM/MPI source distribution.
#
# $Id: Makefile.latex,v 1.9 2003/09/21 23:52:37 jsquyres Exp $
#
# This first section contains macros whose values that you need to
# fill in.
#

# MAIN_TEX: In order to build your document, fill in the MAIN_TEX
# macro with the name of your main .tex file -- the one that you
# invoke LaTeX on.

MAIN_TEX        = user.tex

# 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.

LISTINGS_FILES	= \
		  listings.cfg \
		  listings.sty \
		  lstdoc.sty \
		  lstlang1.sty \
		  lstlang2.sty \
		  lstlang3.sty \
		  lstmisc.sty \
		  lstpatch.sty

OTHER_SRC_FILES = \
                  defs.tex \
		  version.tex \
                  titlepage.tex \
		  audience.tex \
                  introduction.tex \
		  release-notes.tex \
                  getting-started.tex \
                  mpi-details.tex \
		  ssi.tex \
                  commands.tex \
                  lam-ssi.tex \
                  mpi-ssi.tex \
                  debuggers.tex \
		  troubleshooting.tex \
                  misc.tex \
                  bibliography.tex \
		  $(LISTINGS_FILES)

# Bibtex source files

BIBTEX_SOURCES	= refs.bib

# xfig figures.  .eps and .pdf files will be automatically generated
# from these.

FIG_FILES       =
PNG_FILES       = \
                lam-logo.png \
                ptl-logo.png

# Required commands

LATEX           = latex
PDFLATEX        = pdflatex
DVIPS           = dvips
MAKEINDEX       = makeindex
BIBTEX          = bibtex
FIG2DEV         = fig2dev
PNGTOPNM        = pngtopnm
PNMTOPS         = pnmtops

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

SUFFIXES        = .tex .dvi .ps .pdf .fig .eps .png

MAIN_DVI        = $(MAIN_TEX:.tex=.dvi)
MAIN_PS         = $(MAIN_TEX:.tex=.ps)
MAIN_PDF        = $(MAIN_TEX:.tex=.pdf)
MAIN_BBL	= $(MAIN_TEX:.tex=.bbl)
MAIN_BASENAME	= $(MAIN_TEX:.tex=)
EPS_FILES       = $(PNG_FILES:.png=.eps)
EPS_FIG_FILES   = $(FIG_FILES:.fig=.eps)
PDF_FIG_FILES   = $(FIG_FILES:.fig=.pdf)

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

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

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

$(MAIN_PS): $(MAIN_DVI)
$(MAIN_DVI): $(MAIN_TEX) $(CITE_TEX) $(OTHER_SRC_FILES) $(EPS_FIG_FILES) $(EPS_FILES) $(MAIN_BBL)
$(MAIN_PDF): $(MAIN_TEX) $(CITE_TEX) $(OTHER_SRC_FILES) $(PDF_FIG_FILES) $(PNG_FILES) $(MAIN_BBL)

#
# 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
#

.fig.eps:
	$(FIG2DEV) -L eps $< $@

.fig.pdf:
	$(FIG2DEV) -L pdf $< $@

.png.eps:
	$(PNGTOPNM) $< | $(PNMTOPS) -noturn > $*.eps

# Only run bibtex if latex has already been run (i.e., if there is
# already a .aux file).  If .aux file does not exist, then bibtex will
# be run during the .tex.dvi / .tex.pdf rules.  We don't run latex
# here to generate the .aux file because a) we don't know whether to
# run latex or pdflatex, and b) the dependencies are wrong for
# pdflatex because we may need to generate some pdf images first.

$(MAIN_BBL): $(BIBTEX_SOURCES)
	@if (test -f $(MAIN_BASENAME).aux); then \
		echo "### Running BibTex"; \
		$(BIBTEX) $(MAIN_BASENAME); \
	fi

# Main workhorse for .tex -> .dvi.  Run latex, makeindex, and bibtex
# as necessary.

.tex.dvi:
	echo "### Running LaTeX (1)"
	$(LATEX) $*
	@if (egrep $(REFERENCES) $*.log > /dev/null); then \
		echo "### Running LaTeX to fix references (2)"; \
		($(LATEX) $*); \
	fi
	@if (egrep $(NEEDINDEX) $*.log >/dev/null); then \
		echo "### Running makeindex to generate index"; \
		$(MAKEINDEX) $*; \
		echo "### Running LaTeX after generating index"; \
		$(LATEX) $*; \
	fi
	@if (egrep $(RERUNBIB) $*.log >/dev/null); then \
		echo "### Running BibTex because references changed"; \
		$(BIBTEX) $(MAIN_BASENAME); \
		echo "### Running LaTeX after generating bibtex"; \
		$(LATEX) $*; \
	fi
	@if (egrep $(REFERENCES) $*.log > /dev/null); then \
		echo "### Running LaTeX to fix references (3)"; \
		($(LATEX) $*); \
	fi
	@if (egrep $(REFERENCES) $*.log > /dev/null); then \
		echo "### Running LaTeX to fix references (4)"; \
		($(LATEX) $*); \
	fi

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

# Main workhorse for .tex -> .pdf.  Run latex, makeindex, and bibtex
# as necessary.  Essentially the same as .tex.dvi, except
# s/latex/pdflatex/g.

.tex.pdf:
	echo "### Running pdfLaTeX (1)"
	$(PDFLATEX) $*
	@if (egrep $(REFERENCES) $*.log > /dev/null); then \
		echo "### Running pdfLaTeX to fix references (2)"; \
		($(PDFLATEX) $*); \
	fi
	@if (egrep $(NEEDINDEX) $*.log >/dev/null); then \
		echo "### Running makeindex to generate index"; \
		$(MAKEINDEX) $*; \
		echo "### Running pdfLaTeX after generating index"; \
		$(PDFLATEX) $*; \
	fi
	@if (egrep $(RERUNBIB) $*.log >/dev/null); then \
		echo "### Running BibTex because references changed"; \
		$(BIBTEX) $(MAIN_BASENAME); \
		echo "### Running pdfLaTeX after generating bibtex"; \
		$(PDFLATEX) $*; \
	fi
	@if (egrep $(REFERENCES) $*.log > /dev/null); then \
		echo "### Running pdfLaTeX to fix references (3)"; \
		($(PDFLATEX) $*); \
	fi
	@if (egrep $(REFERENCES) $*.log > /dev/null); then \
		echo "### Running pdfLaTeX to fix references (4)"; \
		($(PDFLATEX) $*); \
	fi

#
# Standard targets
#

clean:
	/bin/rm -f *~ *.bak *%
	/bin/rm -f *.log *.aux *.dvi *.blg *.toc *.bbl *.lof *.lot \
		*.ind *.idx *.ilg *.int *.out \
		$(MAIN_PS) $(MAIN_DVI) $(MAIN_PDF) \
		$(EPS_FILES) $(EPS_FIG_FILES) $(PDF_FIG_FILES)


syntax highlighted by Code2HTML, v. 0.9.1