-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.include
203 lines (177 loc) · 6.35 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
202
203
###
### 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
MAKEGLOSSARIES ?= makeglossaries
## String to find in log to check whether rerun is necessary
RERUN_PATTERN = Rerun to
ifneq ($(QUIET),)
PDFLATEX += -interaction=batchmode
ERRFILTER := > /dev/null || (egrep ':[[:digit:]]+:' *.log && false)
BIBTEX += -terse
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
## $(BIBFILES) 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.
BIBFILES += $(patsubst %,%.bib,\
$(shell grep '^[^%]*\\bibliography{' $(TEXTARGETS) | \
grep -o '\\bibliography{[^}]\+}' | \
sed -e 's/^[^%]*\\bibliography{\([^}]*\)}.*/\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)
## grab a version number from the repository (if any) that stores this.
## * REVISION is the current revision number (short form, for inclusion in text)
## * VCSTURD is a file that gets touched after a repo update
SPACE = $(empty) $(empty)
ifeq ($(shell git status >/dev/null 2>&1 && echo USING_GIT),USING_GIT)
ifeq ($(shell git svn info >/dev/null 2>&1 && echo USING_GIT_SVN),USING_GIT_SVN)
# git-svn
ifeq ($(REVISION),)
REVISION := $(shell git svn find-rev git-svn)
endif
VCSTURD := $(subst $(SPACE),\ ,$(shell git rev-parse --git-dir)/refs/remotes/git-svn)
else
# plain git
ifeq ($(REVISION),)
REVISION := $(shell git describe --always HEAD)
endif
GIT_BRANCH := $(shell git symbolic-ref HEAD 2>/dev/null)
VCSTURD := $(subst $(SPACE),\ ,$(shell git rev-parse --git-dir)/$(GIT_BRANCH))
endif
else ifeq ($(shell hg root >/dev/null 2>&1 && echo USING_HG),USING_HG)
# mercurial
ifeq ($(REVISION),)
REVISION := $(shell hg id -i)
endif
VCSTURD := $(subst $(SPACE),\ ,$(shell hg root)/.hg/dirstate)
else ifeq ($(shell svn info >/dev/null && echo USING_SVN),USING_SVN)
# subversion
ifeq ($(REVISION),)
REVISION := $(subst :,-,$(shell svnversion -n))
endif
VCSTURD := $(addsuffix /.svn/entries, $(shell svn info | grep 'Root Path' | sed -e 's/\(.*\:\)\(.*\) /\2/'))
endif
# .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)
# define a \Revision{} command you can include in your document's preamble.
# especially useful with e.g. draftfooter.sty or fancyhdr.
# usage: \input{revision}
# ... \Revision{}
ifneq ($(REVISION),)
REVDEPS += revision.tex
revision.tex: $(VCSTURD)
/bin/echo '\newcommand{\Revision}'"{$(subst _,\_,$(REVISION))}" > $@
AUXFILES += revision.aux
endif
# to generate aux but not pdf from pdflatex, use -draftmode
%.aux: %.tex $(REVDEPS)
$(PDFLATEX) -draftmode $* $(ERRFILTER)
# introduce BibTeX dependency if we found a \bibliography
ifneq ($(strip $(BIBFILES)),)
BIBDEPS = %.bbl
%.bbl: %.aux $(BIBFILES)
$(BIBTEX) $*
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
$(PDFTARGETS): %.pdf: %.tex %.aux $(GLSDEPS) $(BIBDEPS) $(INCLUDEDTEX) $(REVDEPS)
$(PDFLATEX) $* $(ERRFILTER)
ifneq ($(strip $(BIBFILES)),)
@if egrep -q "undefined (references|citations)" $*.log; then \
$(BIBTEX) $* && $(PDFLATEX) $* $(ERRFILTER); fi
endif
@while grep -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 -c .setpdfwrite -f $<
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).glg $(T).glo \
$(T).gls $(T).glsdefs $(T).glx \ $(T).gxg \
$(T).gxs $(T).idx $(T).ilg $(T).ind \
$(T).ist $(T).loa $(T).lof $(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)