|
| 1 | +# Copyright (C) 2004, 2005, 2006, 2007 Philipp Benner <[email protected]> |
| 2 | +# |
| 3 | +# This makefile is free software; you can redistribute it and/or modify |
| 4 | +# it under the terms of the GNU General Public License as published by |
| 5 | +# the Free Software Foundation; either version 2 of the License, or |
| 6 | +# any later version. |
| 7 | +# |
| 8 | +# This makefile is distributed in the hope that it will be useful, |
| 9 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +# GNU General Public License for more details. |
| 12 | +# |
| 13 | +# You should have received a copy of the GNU General Public License |
| 14 | +# along with this makefile; if not, write to the Free Software |
| 15 | +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 16 | + |
| 17 | +# There are quite some problems one has to deal with when using LaTeX and |
| 18 | +# gnu make. First, there is no easy way to calculate dependencies for |
| 19 | +# tex files. Second, several programs generate pdf output, hence there |
| 20 | +# is no distinct target rule for pdf files. What one needs is a make |
| 21 | +# system that knows how to distinguish between e.g. a pdf target generated |
| 22 | +# from a dot graph or a tex file. Furthermore, the make system should |
| 23 | +# know which files depend on each other according to their file names, |
| 24 | +# to avoid having to parse tex files for dependencies. Another issue |
| 25 | +# is that some files might exist or not. E.g. a tex document might have |
| 26 | +# a bibliography based on bibtex and if that is the case the make |
| 27 | +# system should recognize the corresponding bibtex file as dependency. |
| 28 | + |
| 29 | +SHELL = /bin/sh -e |
| 30 | + |
| 31 | +LATEX = pdflatex -halt-on-error -shell-escape |
| 32 | +TEXI2DVI = texi2dvi -p |
| 33 | +MAKEINDEX = makeindex |
| 34 | +BIBTEX = bibtex |
| 35 | +DOT = dot |
| 36 | + |
| 37 | +TEXINPUTS = .:../share:../../share: |
| 38 | + |
| 39 | +L2HTML = latex2html |
| 40 | +L2HTMLFLAGS = -no_math -html_version 4.0,math -accent_images textrm -scalable_fonts -split 0 |
| 41 | + |
| 42 | +DOT_OUTPUT = $(patsubst %.dot,%.pdf,$(wildcard *.dot)) |
| 43 | +TEX_OUTPUT = $(patsubst %.tex,%.pdf,$(wildcard *.tex)) |
| 44 | + |
| 45 | +## default build rule |
| 46 | +all: |
| 47 | + @echo "Usage: make <pdf-output>" |
| 48 | + @echo " make html" |
| 49 | + |
| 50 | +## dynamic dependency calculation |
| 51 | +# naming scheme: |
| 52 | +# -> <basename>.tex depends on |
| 53 | +# -> <basename>.bib and |
| 54 | +# -> <basename>_*.dot/texinput/pdf |
| 55 | +define DYN_dep |
| 56 | +$(1): $(patsubst %.dot,%.pdf,$(wildcard $(basename $(1))_*.dot)) |
| 57 | +$(1): $(wildcard $(basename $(1))_*.texinput) |
| 58 | +$(1): $(wildcard $(basename $(1))_*.pdf) |
| 59 | +$(1): $(shell if [ -f $(1:.pdf=.bib) ]; then echo $(1:.pdf=.bib); fi) |
| 60 | +endef |
| 61 | + |
| 62 | +$(foreach target,$(TEX_OUTPUT),$(eval $(call DYN_dep,$(target)))) |
| 63 | + |
| 64 | +## latex&co build rules |
| 65 | +$(TEX_OUTPUT): %.pdf: %.tex |
| 66 | +# texi2dvi runs latex as often as needed and generates a |
| 67 | +# bibliography by invoking bibtex |
| 68 | + TEXINPUTS=$(TEXINPUTS) PDFLATEX="$(LATEX)" $(TEXI2DVI) $< |
| 69 | + if [ -f $*.nlo ]; then $(MAKE) $*.nls; fi |
| 70 | + TEXINPUTS=$(TEXINPUTS) $(LATEX) $* |
| 71 | + |
| 72 | +$(DOT_OUTPUT): %.pdf: %.dot |
| 73 | + $(DOT) -Tpdf $< > $@ |
| 74 | + |
| 75 | +.SUFFIXES: .nlo .nls |
| 76 | +.nlo.nls: |
| 77 | + $(MAKEINDEX) $< -s nomencl.ist -o $@ |
| 78 | +# $(MAKEINDEX) $< -s nomentbl.ist -o $@ |
| 79 | + |
| 80 | +## latex2html |
| 81 | +html: $(TEX_OUTPUT) $(DOT_OUTPUT) |
| 82 | + $(L2HTML) $(L2HTMLFLAGS) $(TEX_OUTPUT:.pdf=.tex) |
| 83 | + |
| 84 | +## clean rules |
| 85 | +clean: |
| 86 | + $(RM) -r $(TEX_OUTPUT:.pdf=) |
| 87 | + $(RM) -r input/auto |
| 88 | + $(RM) -r auto |
| 89 | + $(RM) tmp.inputs |
| 90 | + $(RM) *.table |
| 91 | + $(RM) *.gnuplot |
| 92 | + $(RM) *.aux |
| 93 | + $(RM) *.blg |
| 94 | + $(RM) *.bbl |
| 95 | + $(RM) *.dvi |
| 96 | + $(RM) *.log |
| 97 | + $(RM) *.ps |
| 98 | + $(RM) *.toc |
| 99 | + $(RM) *.out |
| 100 | + $(RM) *.nav |
| 101 | + $(RM) *.snm |
| 102 | + $(RM) *.nlo |
| 103 | + $(RM) *.nls |
| 104 | + $(RM) *.ilg |
| 105 | + $(RM) *.idx |
| 106 | + $(RM) *.ind |
| 107 | + |
| 108 | +distclean: clean |
| 109 | + $(RM) $(TEX_OUTPUT) |
| 110 | + $(RM) $(DOT_OUTPUT) |
| 111 | + |
| 112 | +.PHONY: all clean distclean html |
0 commit comments