-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
156 lines (122 loc) · 5.25 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
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
vectorsources := $(shell find rawfigs/ ../common/rawfigs/ -name '*.dia' -o -name '*.eps' -o -name '*.m' -o -name '*.pdf' -o -name '*.ps' -o -name '*.py' -o -name '*.svg' 2>/dev/null)
rastersources := $(shell find rawfigs/ ../common/rawfigs/ -name '*.jpg' -o -name '*.gif' 2>/dev/null)
readysources := $(shell find rawfigs/ ../common/rawfigs/ -name '*.png' -o -name '*.pdf' -o -name '*mpg' -o -name '*.mpeg' 2>/dev/null)
texsource := $(wildcard main.tex paper.tex poster.tex proposal.tex report.tex talk.tex)
ifeq "$(texsource)" ""
texsource := $(wildcard abstract.tex)
endif
vectorfigs := $(shell echo ' ' $(patsubst %_fm.eps,%.eps,$(vectorsources)) ' ' | sed -e 's> \(../common/\)*raw> >g' -e 's/\.[^. ]* /.pdf /g')
rasterfigs := $(shell echo ' ' $(rastersources) ' ' | sed -e 's> \(../common/\)*raw> >g' -e 's/\.[^. ]* /.png /g')
readyfigs := $(shell echo ' ' $(readysources) ' ' | sed -e 's> \(../common/\)*raw> >g')
figsources := $(vectorsources) $(rastersources) $(readysources)
figures := $(vectorfigs) $(rasterfigs) $(readyfigs)
dirname := $(shell basename $(shell pwd))
ifeq ($(words $(texsource)),'1')
texfinal := $(dirname).pdf
texroot = $(patsubst %.pdf,%,$(1))
else
texfinal := $(patsubst %.tex,$(dirname)-%.pdf,$(texsource))
texroot = $(patsubst $(dirname)-%,%,$(patsubst %.pdf,%,$(1)))
endif
bibfiles := $(wildcard *.bib)
styfiles := $(wildcard *.sty ../common/*.sty)
clsfiles := $(wildcard *.cls ../common/*.cls)
alldeps := *.tex $(bibfiles) $(figures) $(figsources) $(clsfiles) $(styfiles)
BIBTEX ?= bibtex
PDFLATEX ?= pdflatex
LATEX ?= latex
PYTHON ?= python
OCTAVE ?= octave
INKSCAPE ?= inkscape
FRAGMASTER ?= fragmaster
MYPDFLATEX = TEXINPUTS=$(abspath ../common):$$TEXINPUTS $(PDFLATEX) -halt-on-error -interaction=nonstopmode
MYLATEX = TEXINPUTS=$(abspath ../common):$$TEXINPUTS $(LATEX) -halt-on-error -interaction=nonstopmode
MYFRAGMASTER = TEXINPUTS=$(abspath ../common):$$TEXINPUTS $(FRAGMASTER)
.PHONY: all figures clean cleanlatex cleanfigs
all: $(texfinal)
figures: $(figures)
continuous: all
while true; do \
inotifywait -e close_write -e delete_self -e move $(alldeps) || break; \
$(MAKE) all; \
done
$(texfinal): $(alldeps)
if ls *.bib 2>&1; then $(MYPDFLATEX) -draftmode $(call texroot,$@); fi
if (ls *.bib 2>&1 && ls $(call texroot,$@).aux 2>&1); then $(BIBTEX) $(call texroot,$@); fi
$(MYPDFLATEX) -draftmode $(call texroot,$@) && $(MYPDFLATEX) -draftmode $(call texroot,$@) && $(MYPDFLATEX) $(call texroot,$@)
if [ "$@" != "$(call texroot,$@).pdf" ]; then mv "$(call texroot,$@).pdf" "$@"; fi
clean: cleanlatex cleanfigs
cleanlatex:
rm -f $(patsubst %.tex, %.aux, $(wildcard *.tex))
rm -f $(foreach ext,.bbl .blg .log .dvi .nav .nlo .out .pdf .snm .spl .toc .vrb Notes.bib,$(patsubst %.tex,%$(ext),$(texsource)))
rm -f $(texfinal)
cleanfigs:
rm -rf figs/
figs/%.pdf: rawfigs/%.dia
@mkdir -p $(dir $@)
dia -t eps-builtin -e $?_roytemp.eps $? && epstopdf $?_roytemp.eps -o=$@
@rm -f $?_roytemp.eps
figs/%.pdf: rawfigs/%.eps
@mkdir -p $(dir $@)
epstopdf $? -o=$@ || (rm $@; exit 1)
figs/%.pdf: rawfigs/%_fm rawfigs/%_fm.eps # fragmaster(1) with optional control file
@mkdir -p $(dir $@)
@(test -f rawfigs/fragmaster.dfm && (cd $(dir $@) && ln -sf -t . ../rawfigs/fragmaster.dfm) || true)
@(cd $(dir $@) && ln -sf -t . $(addprefix ../,$+) && $(MYFRAGMASTER))
figs/%.pdf: rawfigs/%.m
@mkdir -p $(dir $@)
@cd $(dir $?) && $(OCTAVE) $(notdir $?)
@(test -f $(dir $?)/$*.eps && (epstopdf $(dir $?)/$*.eps -o=$@; rm -f $(dir $?)/$*.eps) || true)
@(test -f $(dir $?)/$*.pdf && mv $(dir $?)/$*.pdf $@ || true)
figs/%.pdf: rawfigs/%.py
@mkdir -p $(dir $@)
@cd $(dir $?) && $(PYTHON) $(notdir $?)
@(test -f $(dir $?)/$*.eps && (epstopdf $(dir $?)/$*.eps -o=$@; rm -f $(dir $?)/$*.eps) || true)
@(test -f $(dir $?)/$*.pdf && mv $(dir $?)/$*.pdf $@ || true)
figs/%.pdf: rawfigs/%.ps
@mkdir -p $(dir $@)
ps2pdf $? $@
#figs/%.pdf: rawfigs/%.png
# convert $? $@
figs/%.pdf: rawfigs/%.svg
@mkdir -p $(dir $@)
$(INKSCAPE) $? -z --export-pdf=$@
figs/%.png: rawfigs/%.jpg
@mkdir -p $(dir $@)
convert $? $@
figs/%.png: ../common/rawfigs/%.jpg
@mkdir -p $(dir $@)
convert $? $@
figs/%.png: rawfigs/%.gif
@mkdir -p $(dir $@)
convert $? $@
figs/%.png: ../common/rawfigs/%.gif
@mkdir -p $(dir $@)
convert $? $@
figs/%.mpeg: rawfigs/%.mpeg
@mkdir -p $(dir $@)
@reldir=`echo $(dir $@) | sed -e 's>[^/]*/*>../>g'`; ln -sf $${reldir}$? $@
figs/%.mpg: rawfigs/%.mpg
@mkdir -p $(dir $@)
@reldir=`echo $(dir $@) | sed -e 's>[^/]*/*>../>g'`; ln -sf $${reldir}$? $@
figs/%.pdf: rawfigs/%.pdf
@mkdir -p $(dir $@)
@reldir=`echo $(dir $@) | sed -e 's>[^/]*/*>../>g'`; ln -sf $${reldir}$? $@
figs/%.png: rawfigs/%.png
@mkdir -p $(dir $@)
@reldir=`echo $(dir $@) | sed -e 's>[^/]*/*>../>g'`; ln -sf $${reldir}$? $@
figs/%.pdf: ../common/rawfigs/%.pdf
@mkdir -p $(dir $@)
@reldir=`echo $(dir $@) | sed -e 's>[^/]*/*>../>g'`; ln -sf $${reldir}$? $@
figs/%.png: ../common/rawfigs/%.png
@mkdir -p $(dir $@)
@reldir=`echo $(dir $@) | sed -e 's>[^/]*/*>../>g'`; ln -sf $${reldir}$? $@
figs/%.pdf: ../common/rawfigs/%.eps
@mkdir -p $(dir $@)
epstopdf $? -o=$@
figs/%.pdf: ../common/rawfigs/%.ps
@mkdir -p $(dir $@)
ps2pdf $? $@
figs/%.pdf: ../common/rawfigs/%.svg
@mkdir -p $(dir $@)
$(INKSCAPE) $? -z --export-pdf=$@