#
# makefile for generating PDF from .tex source and various kinds of 
# figure input
#
LATEX = latex -interaction nonstopmode
BIBTEX = bibtex
LATEXMK = latexmk -latex="$(LATEX)"
DVIPDF = dvipdf

FIG2DEV = fig2dev
MAGNIFICATION="-m 0.5"

GNUPLOT_SCRIPT = ./gnuplot-to-tex

#
# "source" files (LaTeX, xfig, gnuplot)
#
tex_src = $(wildcard *.tex)
xfig_in = $(wildcard *.fig)
gnuplot_in = $(wildcard *.plotin)
tikz_src = $(wildcard tikz*.tex)

#
# intermediate files for xfig, gnuplot
#
xfig_out = $(xfig_in:.fig=.pstex) $(xfig_in:.fig=.pstex_t) 
gnuplot_out = $(gnuplot_in:.plotin=.tex)

#
# main filename
#
main = examples

#
# rules to generate .tex source (.pstex_t) and EPS (.pstex) from .fig
# 
%.pstex: %.fig
	$(FIG2DEV) -L pstex $(MAGNIFICATION) $*.fig >$*.pstex
%.pstex_t: %.fig
	$(FIG2DEV) -L pstex_t $(MAGNIFICATION) -p $*.pstex $*.fig >$*.pstex_t

#
# rule to generate .tex source and EPS from .plotin
#
%.tex: %.plotin
	$(GNUPLOT_SCRIPT) $< $@

$(main).dvi: $(tex_src) $(xfig_out) $(gnuplot_out) 
	$(LATEXMK) $(main).tex

%.pdf: %.dvi
	$(DVIPDF) $<

.PHONY: clean
	
clean:
	$(LATEXMK) -c
	-rm -v `ls $(xfig_out) $(gnuplot_out) *.eps *.dvi`

