My first Makefile

I’ve been playing a lot with MetaPost lately. I really like the way you construct your figures — it’s clean, precise and mathematical.

But there’s one problem: I now have to first run mpost to generate the figures, and then dvips to put them into my document. I can’t just view the figures in xdvi together with the text, as there’s some problems with the fonts used in the figures. The only good way to view it is in gv, which means that I also have to run dvips.

But this Makefile solves that — I can now just run make, and then it will re-run all necessary programs:

#
# This Makefile re-runs all the necessary programs, so that the
# PostScript-file is updated whenever the LaTeX- or MetaPost-files
# change.
#
# Martin Geisler <[email protected]> — Just use it :-)
#
all: main.ps
.mpost: *.mp
    TEX=latex mpost -interaction nonstopmode $?
    touch .mpost
.gnuplot: *.gnuplotrc *.data
    gnuplot $?
    touch .gnuplot
%.dvi: %.tex
    latex ‘\nonstopmode\input $<’ && latex ‘\nonstopmode\input $<’
%.ps: .mpost %.dvi
    dvips $*.dvi -o

(Please remember that there should be a tab in front of the command-lines — those that does not start with a blue word.)

As I’ve never written a Makefile before, I’m pretty certain that there’s something in it, that can be done in a better way. But at least this one works for me :-)

If you can suggest some improvements, then please write me.

Leave a comment