-
Notifications
You must be signed in to change notification settings - Fork 14
/
Make.rules
179 lines (136 loc) · 6.85 KB
/
Make.rules
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
#-*- makefile -*-
ALL=pdf
OS=$(shell uname -s)
TAR=tar
TEXLINT_OPTS?=
FORCE?=no
ifeq ($(FORCE),yes)
TEXLINT_OPTS=--permissive
endif
GENERATED_TEX+=libpaper_metadata.tex #REMOVE_FOR_ARXIV
TEX_FILES+=$(wildcard *.tex *.sty libpaper/*.tex libpaper/*.sty libpaper/*.cls libpaper/*/*.cls) $(GENERATED_TEX)
FIGS+=$(shell find ./Figures -name '*.pdf' -o -name '*.jpg' -o -name '*.png' 2>/dev/null )
GRAPHS+=$(shell find ./Graphs -name '*.pdf' -o -name '*.jpg' -o -name '*.png' 2>/dev/null )
DATA+=$(wildcard ./Data/*.csv)
TEXLINT_IGNORE?=diff.tex new.tex old.tex
LIBPAPER_BIN='./libpaper/bin/'
ALL_INPUTS=$(TEX_FILES) $(FIGS) $(GRAPHS)
PDFLATEX_BATCH_OPTIONS=-interaction=errorstopmode -halt-on-error $(EXTRA_TEX_OPTIONS)
PANDOC ?= pandoc
PDF_TARGETS ?= paper.pdf
TEX_TARGETS = $(patsubst %.pdf,%.tex,$(PDF_TARGETS))
# Note that if there is more than one target, the rest won't get built - JI
GENERATED+=$(PDF_TARGETS) $(GENERATED_TEX)
ARXIV_INPUTS=$(ALL_INPUTS) 00README.XXX
PDFLATEX=pdflatex
LATEXMK=TEXINPUTS=./:./libpaper/:./libpaper/acmart-master/:./libpaper/usenix/: latexmk
.PHONY: test_build clean
default: all
@echo "Built successfully"
#@(echo ==========; date; uname -a; which pdflatex; pdflatex -v |head -1; pwd; echo $$USER; echo 'paper: '; git rev-parse @; echo 'libpaper: '; cd libpaper; git rev-parse @) >> .last_good_libpaper_build; git add .last_good_libpaper_build #REMOVE_FOR_ARXIV
all: check check_repo $(ALL)
.PHONY: check_repo
check_repo:
#(cd $(LIBPAPER_BIN); ./check_repo) #REMOVE_FOR_ARXIV
.PHONY: check_pandoc
check_pandoc:
@if ! command -v $(PANDOC) >/dev/null; then echo You need to install pandoc; false; fi;
.PHONY: wc
wc: paper.grammarly.txt
wc -w $<
singlefile.tex: $(filter-out singlefile.tex,$(TEX_FILES))
echo "" > singlefile.tex
while read line; do if [ "`echo $$line | grep '^\\input{' | tr '{' ' ' | tr '}' ' ' | awk '{print $$2}'`" == "" ]; then echo $$line >> singlefile.tex; else cat `echo $$line | grep '^\\input{' | tr '{' ' ' | tr '}' ' ' | awk '{print $$2}'`.tex >> singlefile.tex; fi; done < paper.tex
.PHONY: test
test:
rm -rf /tmp/test_build
git clone . /tmp/test_build -b $$(git rev-parse --abbrev-ref HEAD) # checkout and test the current branch
git clone ./libpaper/ /tmp/test_build/libpaper -b $$(cd libpaper; git rev-parse --abbrev-ref HEAD) # for libpaper too.
(cd /tmp/test_build; $(MAKE))
.PHONY: pdf
pdf: $(PDF_TARGETS)
%.pdf %.log %.aux: %.tex $(TEX_FILES)
$(LIBPAPER_BIN)/texlint $(TEXLINT_OPTS) $^ --ignore-files $(TEXLINT_IGNORE)
$(LATEXMK) $(LATEXMK_OPTS) -pdf -pdflatex="$(PDFLATEX) $(PDFLATEX_BATCH_OPTIONS)" -use-make $*
%.docx: $(TEX_FILES)
$(PANDOC) $*.tex -w docx -o $@
%.table.tex: %.csv
csvtotabular $< -o $@
TEMP_DIR=/tmp/$(shell basename $(CURDIR))
%.grammarly.txt: check_pandoc $(TEX_FILES)
rm -rf $(TEMP_DIR)
mkdir -p $(TEMP_DIR)
$(TAR) cf - $(ALL_INPUTS) paper.bbl | (cd $(TEMP_DIR); $(TAR) xf -)
(cd $(TEMP_DIR); for i in $$(find . -name '*.tex'); do mv $$i $$i.bak; perl -ne 's/\~\\(footnote|cite)/\\$$1/g;print;' < $$i.bak > $$i;done)
(cd $(TEMP_DIR); sed -i '/\\begin{abstract}/d' *.tex)
(cd $(TEMP_DIR); sed -i '/\\end{abstract}/d' *.tex)
(cd $(TEMP_DIR); sed -i '/\LetLtxMacro/,+2 d' libpaper/macros.tex)
(cd $(TEMP_DIR); $(PANDOC) $*.tex -w plain -o - --wrap=none) > $@
%.txt: $(TEX_FILES)
$(PANDOC) $*.tex -w plain -o $@
#%%-strip.tex: $(TEX_FILES)
# $(PANDOC) $*.tex -w latex -o $@
.PHONY: libpaper_metadata.tex #REMOVE_FOR_ARXIV
libpaper_metadata.tex:
$(LIBPAPER_BIN)/check_release > $@ || true #REMOVE_FOR_ARXIV
.PHONY: release
release: $(patsubst %.pdf,%-release.pdf,$(PDF_TARGETS))
diff:
@$(LIBPAPER_BIN)/diff
%-release.pdf:
@if $(LIBPAPER_BIN)/check_release > /dev/null; then $(MAKE) default; else echo "Commit changes first"; false ;fi
mv $*.pdf $@
ARXIV_NAME=$(shell basename $(CURDIR))-arxiv
.PHONY: .gitignore
.gitignore:
if ! [ -e .gitignore ]; then touch .gitignore; git add .gitignore; fi
(cat .gitignore; echo $(GENERATED) | perl -ne 's/ /\n/g;print' | sort |uniq) > .gitignore.new; mv .gitignore.new .gitignore
.PHONY: arxiv
arxiv: paper-arxiv.tgz
mv paper-arxiv.tgz $(ARXIV_NAME).tgz
.PHONY:
%-arxiv.tgz: %.pdf %.aux %.log $(ARXIV_INPUTS)
rm -rf $*-arxiv
mkdir -p $*-arxiv
# copy over tex files s
$(TAR) cf - Makefile libpaper/Make.rules $(ARXIV_INPUTS) $< | (cd $*-arxiv; $(TAR) xf -)
# remove comments
(cd $*-arxiv; for i in $$(find . -name '*.tex'); do mv $$i $$i.bak; perl -pe 's/(^|[^\\])%.*/\1%/' < $$i.bak > $$i; rm $$i.bak; done)
# copy over figs,graphs
(grep -q IncludeInArxiv $*-arxivdeps.log && cat $*-arxivdeps.log | awk -F"[ ',]+" '/IncludeInArxiv:/{print $$2}' | $(TAR) cf - -T -| (cd $*-arxiv; $(TAR) xf -) ) || true
# copy over bib files
(grep -q bibdata $*.aux && cat $*.aux | awk -F",|[{}]" '/bibdata/{sep=""; for (i=2; i<NF; i++) {printf("%s%s.bib",sep,$$i); sep="\n"};}' | $(TAR) cf - -T -| (cd $*-arxiv; $(TAR) xf -) ) || true
# define arxiv variables
(cd $*-arxiv && echo "\\def\\\arxivbuild{}" >> libpaper_metadata.tex)
# build arxiv pdf
(cd $*-arxiv && $(LATEXMK) -pdf -pdflatex="$(PDFLATEX) $(PDFLATEX_BATCH_OPTIONS)" -use-make $*.tex)
# copy over data
(grep -q ArxivData $*-arxivdeps.log && mkdir -p $*-arxiv/anc && cat $*-arxivdeps.log | awk -F"[ ',]+" '/ArxivData:/{print $$2 " " $$4}' | xargs -n 2 sh -c 'mkdir -p `dirname $*-arxiv/anc/"$$1"` && cp -Lr "$$0" $*-arxiv/anc/"$$1"' ) || true
# remove libpaper checks in arxiv directory Makefile
(cd $*-arxiv; sed -i 's/.*REMOVE\_FOR\_ARXIV//g' libpaper/Make.rules)
#(cd $*-arxiv; sed -i -e 's/all\: check\ check\_repo/all\:/g' libpaper/Make.rules)
#(cd $*-arxiv; sed -i -e 's/.PHONY\:\ libpaper\_metadata.tex//g' libpaper/Make.rules)
#(cd $*-arxiv; sed -i -e 's/GENERATED\_TEX+=libpaper\_metadata.tex//g' libpaper/Make.rules)
# clean build artifacts
(cd $*-arxiv && rm -rf $$(find . -name '*.bib'))
(cd $*-arxiv && rm -rf *.aux *.log *.blg *.out *.toc *.fls *.fdb_latexmk *.bak)
$(TAR) czf $@ $*-arxiv
.PHONY: watch
watch:
@when-changed -h >/dev/null 2>&1 || (echo "ERROR: when-changed not install. Run pip install when-changed."; exit 1)
@when-changed -s `bash -c '( GLOBIGNORE="libpaper_metadata.tex"; ls libpaper/*.tex libpaper/*.bib *.bib *.tex Figures/* Graphs/* )'` -c 'make'
.PHONY: clean
clean:
rm -rf *.aux *.log *.bbl *.blg *.out *.toc *.fdb_latexmk
rm -rf _test_build
rm -rf $(GENERATED)
$(LATEXMK) -CA
.PHONY: check #REMOVE_FOR_ARXIV
check:
@if ! [ -d libpaper/.git ]; then echo "Your libpaper is not in its own git repo. You _should_not_ include the contents of libpaper in your paper directory. You should checkout libpaper, so the improvement you make will be available to other students"; false; fi #REMOVE_FOR_ARXIV
.PHONY: git-hooks #REMOVE_FOR_ARXIV
git-hooks: check
[ -d libpaper ] && git config core.hooksPath libpaper/git_hooks #REMOVE_FOR_ARXIV
.PHONY: locker
locker:
@bash -c 'echo -ne "/locker create "' && grep input paper.tex | grep -Ev '%|libpaper' | perl -ne '/\{(.*)\}/; print "$$1.tex "'; echo