#
# Makefile   <<   MetaPost>>.
#
# 2006 (c)  .. 
#

mpfile := intro

RESULT := hello.1.eps hello.2.eps intro.1.eps intro.2.eps intro.3.eps \
    hello.1.pdf hello.2.pdf intro.1.pdf intro.2.pdf intro.3.pdf

# 
tmp_file := tmp_file

#
LATEX := latex 
MPOST := mpost -tex=latex 
DVIPS := dvips
MPTOPDF := mptopdf


all:
	@echo "run: make mpfile.n.eps for making eps fig number \"n\""
	@echo "run: make mpfile.n.pdf for making pdf fig number \"n\""
	@echo "run: make pics for making all \"$(mpfile)\" figs"
	@echo "run: make clean for cleaning all \"$(mpfile)\" figs"

pics: $(RESULT)

%.eps:  % 
	@echo  "\documentclass{article}">$(tmp_file).tex
	@echo  "\usepackage[warn]{mathtext}">>$(tmp_file).tex
	@echo  "\usepackage[T2A]{fontenc}">>$(tmp_file).tex
	@echo  "\usepackage[koi8-r]{inputenc}">>$(tmp_file).tex
	@echo  "\usepackage[english,russian]{babel}">>$(tmp_file).tex
	@echo  "\usepackage{graphicx}">>$(tmp_file).tex
	@echo  "\DeclareGraphicsRule{*}{eps}{*}{}">>$(tmp_file).tex
	@echo  "\nofiles">>$(tmp_file).tex
	@echo  "\begin{document}">> $(tmp_file).tex
	@echo  "\thispagestyle{empty}">> $(tmp_file).tex
	@echo  "\includegraphics{$(basename $@)}">> $(tmp_file).tex
	@echo  "\end{document}">> $(tmp_file).tex
	@$(LATEX) $(tmp_file)
	@$(DVIPS) -E -o $@ $(tmp_file)
	@rm $(tmp_file).*

%.pdf:  % 
	@$(MPTOPDF) $<
	@mv `echo $< | sed -e \
           "s/\.\([0-9]\+\)$$/-\1.pdf/"` $<.pdf


clean:
	@rm -f $(RESULT)
	@rm  -f mpx* *~ *.log *.mpx
	@rm -f $(tmp_file).*


#
%.1: %.mp 
	$(MPOST) $<
%.2: %.mp 
	$(MPOST) $<
%.3: %.mp 
	$(MPOST) $<
%.4: %.mp 
	$(MPOST) $<
%.5: %.mp 
	$(MPOST) $<
%.6: %.mp 
	$(MPOST) $<
%.7: %.mp 
	$(MPOST) $<
%.8: %.mp 
	$(MPOST) $<
%.9: %.mp 
	$(MPOST) $<
%.10: %.mp 
	$(MPOST) $<
%.11: %.mp 
	$(MPOST) $<
%.12: %.mp 
	$(MPOST) $<
%.13: %.mp 
	$(MPOST) $<
%.14: %.mp 
	$(MPOST) $<
%.15: %.mp 
	$(MPOST) $<
%.16: %.mp 
	$(MPOST) $<
%.17: %.mp 
	$(MPOST) $<
%.18: %.mp 
	$(MPOST) $<
%.19: %.mp 
	$(MPOST) $<
%.20: %.mp 
	$(MPOST) $<
%.21: %.mp 
	$(MPOST) $<
%.22: %.mp 
	$(MPOST) $<
%.23: %.mp 
	$(MPOST) $<
%.24: %.mp 
	$(MPOST) $<
%.25: %.mp 
	$(MPOST) $<
%.26: %.mp 
	$(MPOST) $<
%.27: %.mp 
	$(MPOST) $<
%.28: %.mp 
	$(MPOST) $<
%.29: %.mp 
	$(MPOST) $<
%.30: %.mp 
	$(MPOST) $<
%.31: %.mp 
	$(MPOST) $<
%.32: %.mp 
	$(MPOST) $<
%.33: %.mp 
	$(MPOST) $<
%.34: %.mp 
	$(MPOST) $<
%.35: %.mp 
	$(MPOST) $<
%.36: %.mp 
	$(MPOST) $<
%.37: %.mp 
	$(MPOST) $<
%.38: %.mp 
	$(MPOST) $<
%.39: %.mp 
	$(MPOST) $<
%.40: %.mp 
	$(MPOST) $<
%.41: %.mp 
	$(MPOST) $<
%.42: %.mp 
	$(MPOST) $<
%.43: %.mp 
	$(MPOST) $<
%.44: %.mp 
	$(MPOST) $<
%.45: %.mp 
	$(MPOST) $<
%.46: %.mp 
	$(MPOST) $<
%.47: %.mp 
	$(MPOST) $<
%.48: %.mp 
	$(MPOST) $<
%.49: %.mp 
	$(MPOST) $<
%.50: %.mp 
	$(MPOST) $<
%.51: %.mp 
	$(MPOST) $<
%.52: %.mp 
	$(MPOST) $<
%.53: %.mp 
	$(MPOST) $<
%.54: %.mp 
	$(MPOST) $<
%.55: %.mp 
	$(MPOST) $<
%.56: %.mp 
	$(MPOST) $<
%.57: %.mp 
	$(MPOST) $<
%.58: %.mp 
	$(MPOST) $<
%.59: %.mp 
	$(MPOST) $<
