-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile.paper
133 lines (113 loc) · 4.98 KB
/
Makefile.paper
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
NAME := $(shell grep 'newcommand.wgDocumentNumber' main.tex|cut -f2 -d'{'|cut -f1 -d'}')
DRAFT := $(NAME)_draft
TEXINPUTS := ..:.:
PDFLATEX := TEXINPUTS=$(TEXINPUTS) flock . lualatex --shell-escape --halt-on-error --file-line-error --interaction nonstopmode
BIBER := biber --input-directory .. --output-directory .
MAKEINDEX := makeindex
SHELL := /bin/bash
EXTRA_DEPS := $(wildcard *.sty ../*.sty) ._dummy.tex
CREATEMD5 := md5sum `find . -regex '.*\.\(aux\|bbl\|toc\|tex\|ind\)'` > ._aux-md5sums
CHECKMD5 := md5sum --quiet -c ._aux-md5sums
UPLOADNAME := D$(shell echo $(NAME)|cut -c2-5).pdf
all: final
._dummy.tex:
touch $@
help:
@echo "all"
@echo "devel"
@echo "draft-loop"
@echo "final-loop"
@echo "final-figure<number>-loop"
@echo "draft"
@echo "final"
@echo "clean"
@echo "autocommit"
TEX_INPUTS := $(shell egrep '^[^%]*\\in(put|clude){.*?}' main.tex|sed 's@^.*{\(.*\)}.*$$@\1.tex@')
TEX_INPUTS2 := $(shell test -n "$(TEX_INPUTS)" && egrep '^[^%]*\\in(put|clude){.*?}' $(TEX_INPUTS) ._dummy.tex|sed -e 's@^.*{\([^.]*\)}.*$$@\1.tex@' -e 's@^.*{\(.*\)}.*$$@\1@') $(TEX_INPUTS)
TEX_INPUTS := $(shell test -n "$(TEX_INPUTS2)" && egrep '^[^%]*\\in(put|clude){.*?}' $(TEX_INPUTS2) ._dummy.tex|sed -e 's@^.*{\([^.]*\)}.*$$@\1.tex@' -e 's@^.*{\(.*\)}.*$$@\1@') $(TEX_INPUTS2) $(TEX_INPUTS) main.tex
TEX_LISTINGS := $(shell test -n "$(TEX_INPUTS)" && awk -F '{|}' -- '/lstinputlisting\[[^\]]*$$/ { getline; while($$0 !~ /\] *{.*\..*}$$/) getline; sub(/^.*\]/, ""); print } /lstinputlisting\[.*\] *{.*}/ { print }' $(TEX_INPUTS) |sed 's=.*\(\[[^]]*\]\)\?{\([^}]*\)}.*=\2='| sort -u)
TEX_PLOTDATA := $(shell grep '\\addplot.* file' $(TEX_INPUTS)|sed 's=^.*\\addplot.* file *{\(.*\)}.*$$=\1=')
GRAPHICS := $(shell grep 'includegraphics' main.tex $(TEX_INPUTS)|grep -v newcommand|sed -e 's=.*\\includegraphics[^{]*{\([^}]*\)}.*=\1=' |sort -u|while read f; do for d in $(subst :, ,$(TEXINPUTS)); do test -f $$d/$$f && echo $$d/$$f && break; done; done)
ALL_DEPS := $(TEX_INPUTS) $(TEX_LISTINGS) $(TEX_PLOTDATA) $(GRAPHICS) $(EXTRA_DEPS)
devel: final-loop
draft: $(DRAFT).pdf
final: $(NAME).pdf
mobile: $(NAME)_mobile.pdf
upload: $(NAME).pdf
@echo -n "Uploading $< ."
@while ! timeout 120s scp -B $< lxpool.gsi.de:web-docs/$(UPLOADNAME); do echo -n .; done
@echo .
loop-internal:
@screenTitle() { case "$$TERM" in screen*|tmux*) printf '\ek%s\e\\' "$$*";; *) printf '\e]1;%s:q\a' "$$*";; esac }; \
while true; do \
while true; do \
screenTitle 'LaTeX waiting: $(loopinternaltarget)'; \
if ! $(MAKE) -q $(loopinternaltarget).pdf>/dev/null; then \
screenTitle 'LaTeX build: $(loopinternaltarget)'; \
ls -lt $(ALL_DEPS) | head -n1 > ._stamp; \
nice ionice -c idle $(MAKE) $(loopinternaltarget).pdf || break; \
fi; \
sleep 1s; \
done; \
screenTitle 'failed'; \
kdialog --passivepopup "LaTeX ($(NAME)) failed" 1; \
echo -e '\a'; \
ls -lt $(ALL_DEPS) $(MORE_DEPS) | head -n1 > ._stamp.new; \
while diff -q ._stamp ._stamp.new; do \
sleep 1s; \
ls -lt $(ALL_DEPS) $(MORE_DEPS) | head -n1 > ._stamp.new; \
done; \
done
draft-loop:
$(MAKE) loopinternaltarget=$(DRAFT) MORE_DEPS=../draft.tex loop-internal
final-loop:
$(MAKE) loopinternaltarget=$(NAME) MORE_DEPS=../final.tex loop-internal
%-loop:
$(MAKE) loopinternaltarget=$(NAME)_$* MORE_DEPS=../$*.tex loop-internal
final-figure%-loop:
@while true; do $(MAKE) -q final-figure$*.pdf || $(MAKE) final-figure$*.pdf && sleep 1s; done
clean:
rm -f $(NAME).pdf $(DRAFT).pdf *.aux *.bbl *.blg *.brf *.lof *.log *.lol *.lot *.out *.toc */*.aux *.auxlock ._aux-md5sums *.bcf *.run.xml ._stamp ._stamp.new
ALL_DEPS=$(TEX_INPUTS) $(TEX_LISTINGS) $(EXTRA_DEPS) $(TEX_PLOTDATA)
$(DRAFT).pdf: ../draft.tex $(ALL_DEPS)
$(PDFLATEX) ../draft
@test -s draft.pdf && mv draft.pdf $@
$(BIBER) draft || true
$(NAME).pdf: ../final.tex $(ALL_DEPS)
@$(CREATEMD5)
$(PDFLATEX) ../final
@test -s final.pdf && mv final.pdf $@
$(BIBER) final || true
@while ! $(CHECKMD5); do \
$(CREATEMD5); \
$(PDFLATEX) ../final; \
test -s final.pdf && mv final.pdf $@; \
done
test "$(USER)" = "mkretz" && timeout 20s scp -B $@ lxpool.gsi.de:web-docs/$(UPLOADNAME) &
$(NAME)_%.pdf: ../%.tex $(ALL_DEPS)
@$(CREATEMD5)
$(PDFLATEX) ../$*
@test -s $*.pdf && mv $*.pdf $@
test -f $*.bcf && $(BIBER) $* || true
test -f $*.ind && $(MAKEINDEX) $* || true
while ! $(CHECKMD5); do \
$(CREATEMD5); \
$(PDFLATEX) ../$*; \
test -s $*.pdf && mv $*.pdf $@; \
test -f $*.ind && $(MAKEINDEX) $*; \
done
final-figure%.pdf: final.tex $(ALL_DEPS)
$(PDFLATEX) --halt-on-error --interaction=nonstopmode --jobname "final-figure$*" "\def\tikzexternalrealjob{final}\input{final}"
autocommit:
@screenTitle() { echo $$TERM|grep -q screen && printf '\ek%s\e\\' "$$*"; }; \
screenTitle 'autocommit' \
while true; do \
git commit -am "auto: `git status --porcelain|grep -v '^??'|cut -c4-|paste -s -d' '`" && \
screenTitle 'committed' && \
git push && \
screenTitle 'committed & pushed'; \
sleep 5s; \
screenTitle 'autocommit'; \
sleep 55s; \
done
.PHONY: clean