RM = rm -f
GNUPLOT =  gnuplot
EPSDIR = eps

# all: $(patsubst   %.gnuplot, %.ps, $(wildcard *.gnuplot))

all: $(addprefix $(EPSDIR)/,$(patsubst   %.gnuplot, %.eps, $(wildcard *.gnuplot)))

$(EPSDIR)/%.ps: $(EPSDIR)/%.tex
	latex $<
	dvips -o $(basename $<).ps $(notdir $(basename $<).dvi)

$(EPSDIR)/%.tex: %.tex
	echo \\documentclass\{article\}\\usepackage\{graphicx\}> $(EPSDIR)/$<
	echo \\usepackage\{amsmath\}\\pagestyle\{empty\} >> $(EPSDIR)/$<
	/bin/echo \\begin\{document\} >> $(EPSDIR)/$<
	echo \\input\{$<\}\\end\{document\} >> $(EPSDIR)/$<

$(EPSDIR)/%.eps: $(EPSDIR)/%.ps
	ps2eps -f $<


%.tex: %.gnuplot
	$(GNUPLOT) -e "set terminal epslatex; set output \"$@\" " $<

clean:
	$(RM) *.tex *~ *.backup *.log $(EPSDIR)/*.tex  $(EPSDIR)/*.*ps *.aux *.dvi *.eps
