Makefile 3.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Makefile for LaTeX documents.
#

# LaTeX core binaries.
TEX := latex
BIBTEX := bibtex
GLOSSARY := makeglossaries

# Conversion to other formats.
DVIPS := dvips
PS2PDF := ps2pdf14
LATEX2RTF := latex2rtf
LIBREOFFICE := libreoffice

# Pictures.
DIA := dia
DOT := dot
18
FIG2DEV := fig2dev
19 20 21 22 23 24 25 26 27 28
CONVERT := convert
GNUPLOT := gnuplot
FONTSIZE := 20

# Load the configuration file.
-include config.mkc

# Find the input files.
SRC := $(basename $(shell grep -l '\\begin{document}' *.tex))
DIA_PIC := $(basename $(shell ls *.dia))
29
FIG_PIC := $(basename $(shell ls *.fig))
30
GNP := $(basename $(shell ls *.gnp))
31 32
PIC_EXT := .dot .gif .jpg .png .ppm .svg .xcf .bmp
PIC := $(foreach I, $(PIC_EXT), $(basename $(shell ls *$I)))
33 34 35 36 37 38 39

# Output.
PDF := $(addsuffix .pdf, $(SRC))
RTF := $(addsuffix .rtf, $(SRC))
DOC := $(addsuffix .docx, $(SRC))

# Temporary files.
40
TMP := .blg .log .nav .out .snm .toc .dvi .aux .idx .vrb .ps .glg .glo .ist -blx.bib .run.xml
41 42 43 44 45 46
PNG := $(addsuffix .png, $(DIA_PIC))
TNP := $(addsuffix .tnp, $(GNP))

# Semi-permanent files.
BIB := $(addsuffix .bbl, $(SRC))
GLS := $(addsuffix .gls, $(GLS))
47 48
EPS := $(addsuffix .eps, $(DIA_PIC) $(FIG_PIC) $(GNP) $(PIC))
TEX_T_EXT := pstex pstex_t
49
TEX_T := $(foreach I, $(TEX_T_EXT), $(addsuffix $I, $(FIG_PIC)))
50 51

# Do not delete the semi-permanent files automatically.
52
.PRECIOUS: $(BIB) $(GLS) $(EPS) $(TEX_T)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69

# Disable built-in rules.
.SUFFIXES:

# Targets that are not associated with files.
.PHONY: all rtf doc clean distclean release


# Main targets

all: $(PDF)

rtf: $(RTF)

doc: $(DOC)

clean:
70
	rm -f $(foreach I, $(TMP), $(addsuffix $I, $(SRC))) $(PNG) $(TNP)
71 72

distclean: clean
73
	rm -f $(PDF) $(RTF) $(DOC) $(BIB) $(EPS) $(TEX_T)
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103

release: all clean


# Picture targets.

%.png: %.dia
	$(DIA) -e $@ -t png-libart $<

%.eps: %.png
	$(CONVERT) $< $@

%.eps: %.dot
	$(DOT) -Teps -o $@ $<

%.eps: %.gif
	$(CONVERT) $< $@

%.eps: %.jpg
	$(CONVERT) $< $@

%.eps: %.ppm
	$(CONVERT) $< $@

%.eps: %.svg
	$(CONVERT) $< $@

%.eps: %.xcf
	$(CONVERT) $< $@

104 105 106
%.eps: %.bmp
	$(CONVERT) $< $@

107
%.tnp: %.gnp $(DEP)
108
	echo "set terminal postscript color eps font \"Helvetica,$(FONTSIZE)\"" > $@ ;\
109 110 111 112 113
	cat $< >> $@

%.eps: %.tnp
	$(GNUPLOT) < $< > $@

114 115 116 117 118 119 120 121 122
%.eps: %.fig
	$(FIG2DEV) -L eps $< $@

%.pstex: %.fig
	$(FIG2DEV) -L pstex $< $@

%.pstex_t: %.fig %.pstex
	$(FIG2DEV) -L pstex_t -p $(word 2, $^) $< $@

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147

# BibTeX targets (called recursively).

%.blg: %.aux
	$(BIBTEX) $(basename $^)

%.bbl: %.blg
	@

# Glossary targets (called recursively).

%.glg: %.aux
	$(GLOSSARY) $*

%.glo: %.glg
	@

%.ist: %.glg
	@

%.gls: %.aux %.glg %.glo %.ist
	@

# LaTeX build targets.

148
%.aux: %.tex $(EPS) $(TEX_T)
149
	$(TEX) $< ;\
150
	if (grep -s "Package biblatex Warning: Please (re)run BibTeX" $*.log); then \
151 152 153 154 155 156 157 158 159
	  $(MAKE) $*.bbl ;\
	  $(TEX) $< ;\
	fi ;\
	if (grep -s "No file $*.gls" $*.log); then \
	  $(MAKE) $*.gls ;\
	fi ;\
	while (grep -s "Rerun to get cross-references right." $*.log); do \
	  $(TEX) $< ;\
	done ;\
160 161 162
	while (grep -s "Rerun to get /PageLabels entry." $*.log); do \
	  $(TEX) $< ;\
	done ;\
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
	while (grep -s "LaTeX Warning: There were undefined references" $*.log); do \
	  $(TEX) $< ;\
	done ;\
	while (grep -s "Package rerunfilecheck Warning: File" $*.log); do \
	  $(TEX) $< ;\
	done

%.log: %.aux
	@

%.dvi: %.aux
	@

%.idx: %.aux
	@

%.nav: %.aux
	@

%.out: %.aux
	@

%.snm: %.aux
	@

%.toc: %.aux
	@

%.vrb: %.aux
	@

%.ps: %.dvi %.log %.aux %.idx %.nav %.out %.snm %.toc %.vrb
	$(DVIPS) $< -o $@


# Output targets.

%.pdf: %.ps
	$(PS2PDF) $^

%.rtf: %.tex %.dvi %.log %.aux %.idx %.nav %.out %.snm %.toc %.vrb
	$(LATEX2RTF) -o $@ $<

%.docx: %.rtf
	$(LIBREOFFICE) --headless --invisible --convert-to docx $< -o $@