# Jam rules for Tex and LaTeX

# Usage:

# include "Jamrules-tex" ;
# Latex foo.tex bar.tex ;
# Tex hello.tex ;

# Then call jam with one of "pdf", "ps", or "dvi" targets


NOTFILE dvi ps pdf ;

rule Latex
{
	LatexDvi $(<:S=.dvi) : $(<) ;
	DviPs $(<:S=.ps) : $(<:S=.dvi) ;
	Depends dvi : $(<:S=.dvi) ;

	LatexPdf $(<:S=.pdf) : $(<) ;
	Depends pdf : $(<:S=.pdf) ;
}

rule Tex
{
	TexDvi $(<:S=.dvi) : $(<) ;
	DviPs $(<:S=.ps) : $(<:S=.dvi) ;
	Depends dvi : $(<:S=.dvi) ;

	TexPdf $(<:S=.pdf) : $(<) ;
	Depends pdf : $(<:S=.pdf) ;
}

rule LatexDvi
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) $(<:S=.log) $(<:S=.toc) $(<:S=.aux) ;
}

actions LatexDvi
{
	# FIXME: should use rlatex
	while latex $(>) |
		tee /dev/tty |
		fgrep "Label(s) may have changed." >/dev/null
	do :
	done
}

rule LatexPdf
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) $(<:S=.log) $(<:S=.toc) $(<:S=.aux) ;
}

actions LatexPdf
{
	while pdflatex $(>) |
		tee /dev/tty |
		fgrep "Label(s) may have changed." >/dev/null
	do :
	done
}

rule TexDvi
{
	Depends $(<) : $(>) ;
	Clean clean : $(<) $(<:S=.log) ;
}

actions TexDvi
{
	tex $(>)
}

rule TexPdf
{
	Depends $(<) : $(>) ;
	Depends all : $(<) ;
	Depends pdf : $(<) ;
	Clean clean : $(<) $(<:S=.log) ;
}

actions TexPdf
{
	pdftex $(>)
}


rule DviPs
{
	Depends $(<) : $(>) ;
	Depends all : $(<) ;
	Depends ps : $(<) ;
	Clean clean : $(<) ;
}

actions DviPs
{
	dvips $(>) -o $(<)
}
