mario::konrad
programming / C++ / sailing / nerd stuff
Makefile
© 2002-06-25 / Mario Konrad

This is the makefile I use to deal with LaTeX documents. It is flexible and very easy to use and extend.

To use this, you will need make, of course. It is designed to handle one target: one latex source file, one destination. However, it is very easly possible to use it even if you have more than one document.

Makefile.latex:

#
# Makefile for LaTeX
#

# Date: 2002-06-25
# Written by Mario Konrad
#

### programs

LATEX=latex
DVIPS=dvips
DVIPDF=dvipdf
MAKEINDEX=makeindex

### targets

ps: $(TARGET).ps

pdf: $(TARGET).pdf

dvi: $(TARGET).dvi

### clean up

clean:
    find . -maxdepth 1 -name $(TARGET).log -exec rm {} \;
    find . -maxdepth 1 -name $(TARGET).aux -exec rm {} \;
    find . -maxdepth 1 -name $(TARGET).toc -exec rm {} \;
    find . -maxdepth 1 -name $(TARGET).lof -exec rm {} \;
    find . -maxdepth 1 -name $(TARGET).lot -exec rm {} \;

clean-dvi:
    find . -maxdepth 1 -name $(TARGET).dvi -exec rm {} \;

clean-ps:
    find . -maxdepth 1 -name $(TARGET).ps -exec rm {} \;

clean-all: clean clean-dvi clean-ps

### implicit rules

.dvi.ps:
    $(DVIPS) $< -o $@

.dvi.pdf:
    $(DVIPDF) $< -o $@

.tex.dvi:
    $(LATEX) $<     # do this two times to generate the TOC
    $(LATEX) $<

### misc

.SUFFIXES: .tex .aux .toc .lof .lot .log .dvi .ps .pdf

Features

This is a list of the features of the current makefile:

The default setting is to create a postscript file. If you like to choose your target file format use the following parameters:

Simple Use

First, we have a look at the most simple usage possible. Let’s assume that we have a single LaTeX document test.tex. If you like to build a postscript file file, just type:

$ make -f Makefile.latex TARGET=test

This will create a postscript file per default. If you like a PDF file, use the following command:

$ make -f Makfile.latex TARGET=test pdf

Your own Makefile

If you like your own makefile instead of typing the command above every time you like to build your document, you may want to take advantage of the makefile provided on this site. Let’s assume the same situation as above: one simple LaTeX document test.tex. Your own makefile could have the following content (minimum, without the line numbers):

TARGET=test
include Makefile.latex

The invocation of the build is now easy:

$ make

of if you like to produce a PDF file:

$ make pdf

Note: the include statemant has to be at the very bottom of your own makefile, otherwise make will try to build the first target it can find. Maybe at this time variable TARGET is not set properly.

Multiple Documents

Sometimes it’s useful to build several documents at once (with the same target file format or different formats). In this case you need your own makefile. This could be like the following one:

all:
    $(MAKE) -f Makefile.latex TARGET=test ps
    $(MAKE) -f Makefile.latex TARGET=test1 ps

clean:
    $(MAKE) -f Makefile.latex TARGET=test clean
    $(MAKE) -f Makefile.latex TARGET=test1 clean

clean-all:
    $(MAKE) -f Makefile.latex TARGET=test clean-all
    $(MAKE) -f Makefile.latex TARGET=test1 clean-all