-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.include
201 lines (174 loc) · 6.08 KB
/
Makefile.include
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
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
###
### generic GNU make Makefile for .tex -> .pdf.
### ransford at cs.washington.edu
### http://github.com/ransford/pdflatex-makefile
###
### Recommended usage:
### 1. echo 'include Makefile.include' > Makefile
### 2. Optional: Edit the Makefile to override $(TARGET)
### and anything else (e.g., PDFVIEWER, AFTERALL)
### 3. $ make snapshot
### # pass around a draft...
### 4. $ make distill
### # submit the camera-ready version with embedded fonts
###
### Final result:
### % cat Makefile
### TARGET=mypaper
### PDFVIEWER=open -a 'Adobe Acrobat Professional'
### AFTERALL=mypostprocessingstep
### include Makefile.include
###
### mypostprocessingstep:
### # do something...
###
PDFLATEX ?= pdflatex -halt-on-error -file-line-error -shell-escape
BIBTEX ?= bibtex
BIBER ?= biber
MAKEGLOSSARIES ?= makeglossaries
MAKENOMENCL ?= makeindex
## String to find in log to check whether rerun is necessary
RERUN_PATTERN = Rerun to|rerun LaTeX|run LaTeX again
ifneq ($(QUIET),)
PDFLATEX += -interaction=batchmode
ERRFILTER := > /dev/null || (egrep ':[[:digit:]]+:' *.log && false)
BIBTEX += -terse
BIBER += --quiet
MAKEGLOSSARIES += -q
MAKENOMENCL += -q
else
PDFLATEX += -interaction=nonstopmode
ERRFILTER=
endif
## Action for 'make view'
OS=$(shell uname -s)
ifeq ($(OS),Darwin)
PDFVIEWER ?= open
else
PDFVIEWER ?= xdg-open
endif
## Name of the target file, minus .pdf: e.g., TARGET=mypaper causes this
## Makefile to turn mypaper.tex into mypaper.pdf.
TARGETS += $(TARGET)
TEXTARGETS = $(TARGETS:=.tex)
PDFTARGETS = $(TARGETS:=.pdf)
AUXFILES = $(TARGETS:=.aux)
LOGFILES = $(TARGETS:=.log)
## Inkscape SVG file processing:
ifeq ($(shell which inkscape >/dev/null 2>&1 && echo USING_INKSCAPE),USING_INKSCAPE)
FIG_SVG=$(wildcard $(FIGS)/*.svg)
FIG_PDF=$(FIG_SVG:.svg=.pdf)
else
FIG_PDF=
endif
## If $(TARGET).tex refers to .bib files like \bibliography{foo,bar}, then
## $(BIBTEXFILES) will contain foo.bib and bar.bib, and both files will be added as
## dependencies to $(PDFTARGETS).
## Effect: updating a .bib file will trigger re-typesetting.
BIBTEXFILES += $(patsubst %,%.bib,\
$(shell grep '^[^%]*\\bibliography{' $(TEXTARGETS) | \
grep -o '\\bibliography{[^}]\+}' | \
sed -e 's/^[^%]*\\bibliography{\([^}]*\)}.*/\1/' \
-e 's/, */ /g'))
## If $(TARGET).tex refers to .bib files like \addbibresource{foo.bib}, then
## $(BIBLATEXFILES) will contain foo.bib and will be added as dependencies to $(PDFTARGETS).
## Effect: updating a .bib file will trigger re-typesetting.
BIBLATEXFILES += $(shell \
grep '^[^%]*\\addbibresource{' $(TEXTARGETS) | \
grep -o '\\addbibresource{[^}]\+}' | \
sed -e 's/^[^%]*\\addbibresource{\([^}]*\)}.*/\1/' \
-e 's/, */ /g')
## Add \input'ed or \include'd files to $(PDFTARGETS) dependencies; ignore
## .tex extensions.
INCLUDEDTEX = $(patsubst %,%.tex,\
$(shell grep '^[^%]*\\\(input\|include\){' $(TEXTARGETS) | \
grep -o '\\\(input\|include\){[^}]\+}' | \
sed -e 's/^.*{\([^}]*\)}.*/\1/' \
-e 's/\.tex$$//'))
AUXFILES += $(INCLUDEDTEX:.tex=.aux)
# .PHONY names all targets that aren't filenames
.PHONY: all clean pdf view snapshot distill distclean
all: pdf $(AFTERALL)
ifeq ($(shell which inkscape >/dev/null 2>&1 && echo USING_INKSCAPE),USING_INKSCAPE)
$(FIGS)/%.pdf: $(FIGS)/%.svg ## Figures for the manuscript
inkscape -C -z --file=$< --export-pdf=$@ 2> /dev/null
endif
pdf: $(FIG_PDF) $(PDFTARGETS)
view: $(PDFTARGETS)
$(PDFVIEWER) $(PDFTARGETS)
# to generate aux but not pdf from pdflatex, use -draftmode
%.aux %.bcf: %.tex $(REVDEPS)
$(PDFLATEX) -draftmode $* $(ERRFILTER)
# specify KEEPAUX=1 if you need to keep auxiliary (.aux) files for some other
# tool (e.g., an autocompleting text editor)
ifneq ($(KEEPAUX),1)
.INTERMEDIATE: $(AUXFILES)
endif
# introduce BibTeX dependency if we found a \bibliography
ifneq ($(strip $(BIBTEXFILES)),)
BIBDEPS = %.bbl
%.bbl: %.aux $(BIBTEXFILES)
$(BIBTEX) $*
endif
# introduce BibLaTeX/Biber dependency if we found a \addbibresource
ifneq ($(strip $(BIBLATEXFILES)),)
BIBDEPS = %.bbl
%.bbl: %.aux %.bcf $(BIBLATEXFILES)
$(BIBER) $*
endif
# introduce makeglossaries dependency if we found \printglossary/ies
HAS_GLOSSARIES = $(shell \
grep '^[^%]*\\printglossar\(ies\|y\)' $(TEXTARGETS) $(INCLUDEDTEX) && \
echo HAS_GLOSSARIES)
ifneq ($(HAS_GLOSSARIES),)
GLSDEPS = %.gls
%.gls: %.aux
$(MAKEGLOSSARIES) $(TARGETS)
endif
# introduce makenomenclature dependency if we found \printnomenclature
HAS_NOMENCL = $(shell \
grep '^[^%]*\\printnomenclature' $(TEXTARGETS) $(INCLUDEDTEX) && \
echo HAS_NOMENCL)
ifneq ($(HAS_NOMENCL),)
NLSDEPS = %.nls
%.nls: %.nlo
$(MAKENOMENCL) $(TARGETS).nlo -s nomencl.ist -o $(TARGETS).nls
endif
$(PDFTARGETS): %.pdf: %.tex %.aux $(GLSDEPS) $(BIBDEPS) $(INCLUDEDTEX) $(REVDEPS) $(NLSDEPS)
$(PDFLATEX) $* $(ERRFILTER)
ifneq ($(strip $(BIBTEXFILES)),)
@if egrep -q "undefined (references|citations)" $*.log; then \
$(BIBTEX) $* && $(PDFLATEX) $* $(ERRFILTER); fi
endif
ifneq ($(strip $(BIBLATEXFILES)),)
@if egrep -q "Please \(re\)run Biber on the file:" $*.log; then \
$(BIBER) $*; fi
endif
@while egrep -q "$(RERUN_PATTERN)" $*.log; do \
$(PDFLATEX) $* $(ERRFILTER); done
DRAFTS := $(PDFTARGETS:.pdf=-$(REVISION).pdf)
$(DRAFTS): %-$(REVISION).pdf: %.pdf
cp $< $@
snapshot: $(DRAFTS)
%.distilled.pdf: %.pdf
gs -q -dSAFER -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$@ \
-dCompatibilityLevel=1.5 -dPDFSETTINGS=/prepress $<
exiftool -overwrite_original -Title="" -Creator="" -CreatorTool="" $@
distill: $(PDFTARGETS:.pdf=.distilled.pdf)
distclean: clean
$(RM) $(PDFTARGETS) $(PDFTARGETS:.pdf=.distilled.pdf) $(EXTRADISTCLEAN)
clean:
$(RM) $(foreach T,$(TARGETS), \
$(T).bbl $(T).bcf $(T).bit $(T).blg \
$(T)-blx.bib $(T).brf $(T).fdb_latexmk \
$(T).fls $(T).glg $(T).glo $(T).gls \
$(T).glsdefs $(T).glx \
$(T).gxg $(T).gz $(T).synctex.gz \
$(T).gxs $(T).idx $(T).ilg $(T).ind \
$(T).ist $(T).loa $(T).lof $(T).log $(T).lol \
$(T).lot $(T).maf $(T).mtc $(T).nav \
$(T).out $(T).pag $(T).run.xml $(T).snm \
$(T).svn $(T).tdo $(T).tns $(T).toc \
$(T).vtc $(T).url) \
$(REVDEPS) $(AUXFILES) $(LOGFILES) \
$(EXTRACLEAN) $(FIG_PDF)