-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
130 lines (96 loc) · 3.18 KB
/
Makefile
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
###########################
# Configuration variables #
###########################
PAPER ?= paper
SRCDIR = src
BUILDDIR = build
RESDIR = res
CLS =
BST =
DOCS =
GLOSSARY = $(SRCDIR)/glossary.tex
BIBLIO = $(SRCDIR)/$(PAPER).bib
RESULTS =
PAPER_FIGS = $(patsubst %.svg,%.pdf,$(wildcard fig/*.svg))
PAPER_PREREQUISITES = $(PAPER_FIGS) $(CLS) $(BST) $(RESULTS) $(GLOSSARY) $(BIBLIO)
# Diff configuration
REV1 ?= HEAD^
REV2 ?= HEAD
# Required by minted package
PDFLATEX_FLAGS = -shell-escape
######################
# Internal variables #
######################
PAPER_PDF = $(BUILDDIR)/$(PAPER).pdf
BLIND_PAPER_PDF = $(BUILDDIR)/$(PAPER)-blind.pdf
PAPER_DIFF_PDF = $(BUILDDIR)/$(PAPER).diff.pdf
DOC_PDFS = $(addprefix $(BUILDDIR)/,$(addsuffix .pdf,$(DOCS)))
DIFF = $(PAPER)-diff$(REV1)-$(REV2)
DIFF_PDF = $(BUILDDIR)/$(DIFF).pdf
BIBTEX_VARS = BIBINPUTS="$(SRCDIR):$(BUILDDIR):"
PDFLATEX_VARS = TEXINPUTS="$(SRCDIR):$(BUILDDIR):"
BIBTEX = $(BIBTEX_VARS) bibtex
PDFLATEX = $(PDFLATEX_VARS) pdflatex
#############
# Functions #
#############
define CLEANUP_LATEX_ARTIFACTS
rm -f $(1).aux
rm -f $(1).bbl
rm -f $(1).blg
rm -f $(1).log
rm -f $(1).out
rm -f $(1).glsdefs
endef
# Rule template for building simple Latex documents (i.e. without bibliography)
define BUILD_LATEX_SIMPLE
$(BUILDDIR)/$(1).pdf: $(SRCDIR)/$(1).tex | $(BUILDDIR)
$(PDFLATEX) $(PDFLATEX_FLAGS) -output-directory $(BUILDDIR) $(SRCDIR)/$(1)
$(call CLEANUP_LATEX_ARTIFACTS,$(BUILDDIR)/$(1))
endef
# Rule template for building complex LaTeX documents (i.e. with bibliography)
define BUILD_LATEX_COMPLEX
$(BUILDDIR)/$(3).pdf: $(1)/$(2).tex $(4) | $(BUILDDIR)
$(eval VARDEFS := $(foreach var,$(5),\\def\\$(var){} ))
$(PDFLATEX) $(PDFLATEX_FLAGS) -jobname $(3) -output-directory $(BUILDDIR) $(VARDEFS) "\input{$(1)/$(2)}"
$(BIBTEX) $(BUILDDIR)/$(3)
$(PDFLATEX) $(PDFLATEX_FLAGS) -jobname $(3) -output-directory $(BUILDDIR) $(VARDEFS) "\input{$(1)/$(2)}"
$(PDFLATEX) $(PDFLATEX_FLAGS) -jobname $(3) -output-directory $(BUILDDIR) $(VARDEFS) "\input{$(1)/$(2)}"
endef
#########
# Rules #
#########
.PHONY: all paper docs diff results clean clean-paper
all: results paper docs
paper: $(PAPER_PDF)
docs: $(DOC_PDFS)
diff: $(DIFF_PDF)
blind: $(BLIND_PAPER_PDF)
results: $(RESULTS)
$(RESDIR):
mkdir -p $@
$(BUILDDIR):
mkdir -p $@
$(BUILDDIR)/$(DIFF).tex: $(SRCDIR)/$(PAPER).tex
latexdiff-vc -r $(REV1) -r $(REV2) $<
rm -f $(SRCDIR)/*oldtmp*.tex $(SRCDIR)/*newtmp*.tex
mv $(SRCDIR)/$(DIFF).tex $(BUILDDIR)
# Generate rule for paper
$(eval $(call BUILD_LATEX_COMPLEX,$(SRCDIR),$(PAPER),$(PAPER),$(PAPER_PREREQUISITES)))
# Generate rule for diff
$(eval $(call BUILD_LATEX_COMPLEX,$(BUILDDIR),$(DIFF),$(DIFF),$(PAPER_PREREQUISITES)))
# Generate rule for blind paper
$(eval $(call BUILD_LATEX_COMPLEX,$(SRCDIR),$(PAPER),$(PAPER)-blind,$(PAPER_PREREQUISITES),blindreview))
# Generate rules for all docs
$(foreach doc,$(DOCS),$(eval $(call BUILD_LATEX_SIMPLE,$(doc))))
# Convert vector graphics from SVG to PDF
%.pdf: %.svg
inkscape $< --export-pdf=$@
clean-paper:
rm -rf $(BUILDDIR)
$(call CLEANUP_LATEX_ARTIFACTS,*)
clean: clean-paper
rm -rf $(RESULTS) $(PAPER_FIGS)
###########
# Results #
###########