Makefile 5.49 KB
Newer Older
Sergey Goncharov's avatar
Sergey Goncharov committed
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
# Create a list of all latex files, which look like root documents
SRCNAMES = $(shell grep -l "^[^%]*{document}" *.tex)

ifdef SRCNAME
	SRCNAMES := $(SRCNAME).tex
endif

ifeq ($(words $SRCNAMES), 1)
	SRCNAME = $(SRCNAMES)
endif

PDFNAMES = $(foreach FILE, $(SRCNAMES:.tex=.pdf), $(FILE))
DVINAMES = $(foreach FILE, $(SRCNAMES:.tex=.dvi), $(FILE))
BBLNAMES = $(foreach FILE, $(SRCNAMES:.tex=.bbl), $(FILE))

#$(warning SRCNAMES: $(SRCNAMES))
#$(warning PDFNAMES: $(PDFNAMES))
#$(warning BBLNAMES: $(BBLNAMES))
#$(warning SRCNAME: $(SRCNAME))

# The resource file for bibtool
BIBRCNAME = bibtool.rc

# Calculate the path to the current dir when run recursively
THISDIR = $(dir $(lastword $(MAKEFILE_LIST)))

export TEXINPUTS:=${TEXINPUTS};$(THISDIR)//;$(THISDIR)/Corporate/4-3

BIBSRC	=	$(wildcard *.bib)
TEXSRC	=	$(wildcard *.tex)

#-- Software Environment Setup -------------------------------
SHELL	= /bin/bash
LATEX	= latex -src
BIBTEX	= bibtex
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
36
DVIPS	= dvips
Sergey Goncharov's avatar
Sergey Goncharov committed
37
PDFPS	= pdftops
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
38
PDF	= max_print_line=1000 pdflatex -shell-escape -src -halt-on-error -synctex=1 -interaction nonstopmode -file-line-error-style
Sergey Goncharov's avatar
Sergey Goncharov committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
OPEN    = xdg-open

# Mac-specific definitions
ifeq ($(shell uname), Darwin)
<------>OPEN=open
endif

.PHONY: default
default: pdf				# Default goal

.PHONY: dvi
dvi : $(DVINAMES) 			# Compile dvi's

.PHONY: pdf
pdf : $(PDFNAMES) 			# Compile pdf's

.PHONY: over
over : clean pdf			# Force recompile

.PHONY: clean
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
59
clean :
Sergey Goncharov's avatar
Sergey Goncharov committed
60
	@echo Soft clean
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
61
	-rm *.blg *.log *.out $(DVINAMES) $(PDFNAMES) 2>/dev/null ; true
Sergey Goncharov's avatar
Sergey Goncharov committed
62
63
64
65
66
67
68

.PHONY: cleanall
cleanall : clean
	@echo Hard clean
	-rm *~ *.aux *.bbl *.lof *.lot *.toc *.ps *.cit *.synctex.gz 2>/dev/null ; true

.PHONY: cleanaux
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
69
cleanaux :
Sergey Goncharov's avatar
Sergey Goncharov committed
70
71
72
73
74
75
76
77
78
79
	-rm *.blg *.log *.out *.dvi*.aux *.bbl *.lof *.lot *.toc *.ps *.cit *.synctex.gz 2>/dev/null ; true

.PHONY: show
show: $(PDFNAMES)
	for file in $(PDFNAMES); do $(OPEN) $$file; done

.PHONY: edit
edit: $(SRCNAMES)
	for file in $(SRCNAMES); do $(OPEN) $$file; done

Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
80
%.bbl: $(BIBSRC)
Sergey Goncharov's avatar
Sergey Goncharov committed
81
82
83
84
85
86
87
88
89
90
91
92
93
	@echo Recreate the .aux file
	$(PDF) $(@:.bbl=.tex) >/dev/null || cat $(@:.bbl=.log)

	@echo Recreate the .bbl file
	$(BIBTEX) $(@:.bbl=.aux) | true

	@echo Flush the citation hash
	test -s $(@:.pdf=.cit) || echo '' | md5sum > $(@:.pdf=.cit)

%.aux : %.pdf;

%.dvi: %.tex	# Cancel the default rule

Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
94
%.dvi: $(TEXSRC) $(wildcard $(THISDIR)*.tex)
Sergey Goncharov's avatar
Sergey Goncharov committed
95
96
	@echo If compilation fails manipuate the timestamp to prevent recognission of .dvi as ready
	$(LATEX) $(@:.dvi=.tex) || (touch --date="`date -R -r $(@:.dvi=.tex)`" $@ & false)
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
97

Sergey Goncharov's avatar
Sergey Goncharov committed
98
99
	@echo If the citations were updated recompile the .bbl file
	grep -o -G "Citation \`[^']*" $(@:.dvi=.log) | md5sum -c $(@:.dvi=.cit) || $(BIBTEX) $(@:.dvi=.aux)
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
100

Sergey Goncharov's avatar
Sergey Goncharov committed
101
102
	while grep -q "Rerun to get cross-references right." $(@:.dvi=.log); \
	do $(LATEX) $(@:.dvi=.tex); done
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
103

Sergey Goncharov's avatar
Sergey Goncharov committed
104
105
106
107
108
109
	@echo Update the missing citation hash
	grep -o -G "Citation \`[^']*" $(@:.dvi=.log) | md5sum > $(@:.dvi=.cit)

%.pdf: %.tex	# Cancel the default rule

%.pdf: $(TEXSRC) $(wildcard $(THISDIR)*.tex) %.bbl
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
110
	@echo Compiling $@
Sergey Goncharov's avatar
Sergey Goncharov committed
111
112
113
114
115
116
117
	($(PDF) $(@:.pdf=.tex) >/dev/null) || (touch --date="`date -R -r $(@:.pdf=.tex)`" $@ & cat $(@:.pdf=.log) & false)

	@echo Recompile tikz images
	@if [ -s $(@:.pdf=.makefile) ]; \
	then \
	    $(MAKE) -e -f $(@:.pdf=.makefile); \
	    $(PDF) $(@:.pdf=.tex) >/dev/null;  \
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
118
  fi
Sergey Goncharov's avatar
Sergey Goncharov committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

	@echo Create $(@:.pdf=.cit) if it does not exist
	test -s $(@:.pdf=.cit) || echo '' | md5sum > $(@:.pdf=.cit)

	@echo If the citations were updated recompile the .bbl file
	grep -o -G "Citation \`[^']*" $(@:.pdf=.log) | md5sum -c $(@:.pdf=.cit) || ($(BIBTEX) $(@:.pdf=.aux); $(PDF) $(@:.pdf=.tex) >/dev/null)

	@echo -n "Search for dangling references.. "
	@if grep -q "Rerun to get cross-references right." $(@:.pdf=.log); \
	then \
	    echo "Run LaTeX twice no matter how silly it is" \
	    $(PDF) $(@:.pdf=.tex) >/dev/null; \
	    $(PDF) $(@:.pdf=.tex) >/dev/null; \
	else \
	    echo "None"; \
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
134
	fi
Sergey Goncharov's avatar
Sergey Goncharov committed
135
136
137
138

	@echo Update the citation hash
	grep -o -G "Citation \`[^']*" $(@:.pdf=.log) | md5sum > $(@:.pdf=.cit)

Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
139
%.ps : %.pdf
Sergey Goncharov's avatar
Sergey Goncharov committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	$(PDFPS) -level1 $<  		# Create .ps from .pdf

.PHONY: bib
bib:  bibtex

.PHONY: bibtool
bibtool: $(BIBSRC)
	#Normalise all bibfiles
	for bf in $(BIBSRC); do \
               bibtool -s -v -i $$bf -o $$bf -r $(THISDIR)/$(BIBRCNAME); \
        done

.PHONY: bibtex
bibtex: $(BBLNAMES)

.PHONY: pack
pack: $(TEXSRC)
	make cleanall
	$(MAKE) pdf
	mkdir -p submission
Sergey Goncharov's avatar
Sergey Goncharov committed
160
	# purging old files if any
Sergey Goncharov's avatar
Sergey Goncharov committed
161
	rm -Rf submission/*
Sergey Goncharov's avatar
Sergey Goncharov committed
162
163
164
165
166
	# copying all files from TexCommon mentioned in log-file
	for file in $(THISDIR)/*; do \
                 if grep --quiet $(shell basename $(THISDIR))/$$(basename $$file) *.log; \
                    then cp -v $$file submission; \
                 fi; done
Sergey Goncharov's avatar
Sergey Goncharov committed
167
168
169
	cp *.bib submission || echo "There are no bib-file!"
	cp *.bbl submission || echo "There are no bbl-file!"
	cp *.bst submission || echo "There are no bst-file!"
Sergey Goncharov's avatar
Sergey Goncharov committed
170
	# copying all files from the current directory mentioned in log-file
Sergey Goncharov's avatar
Sergey Goncharov committed
171
	for file in *; do if grep --quiet $$file *.log; then cp $$file submission; fi; done
Sergey Goncharov's avatar
Sergey Goncharov committed
172
	# remove comments
Sergey Goncharov's avatar
Sergey Goncharov committed
173
	for file in submission/*.tex; do perl -i -pe 's/(^|[^\\])%.*/\1%/' $$file; done
Sergey Goncharov's avatar
Sergey Goncharov committed
174
175
176
	# remove appendix
	for file in submission/*.tex; do sed -i '/\\appendix/,$$c \\\end{document}' $$file ; done
	cd submission; rm *.aux *.blg *.log *.out; rm -f ../submission.zip; zip -r ../submission.zip *
Sergey Goncharov's avatar
Sergey Goncharov committed
177
178
179
180
181
182
183
184

.PHONY: up
up: $(PDFNAMES)
	for fn in $(PDFNAMES); do rcp $$fn www8.informatik.uni-erlangen.de:/home/$(USER)/$$fn ; done
#	rcp $(SRCNAME).ps  www8.informatik.uni-erlangen.de:/home/$(USER)/$(EXTNAME).ps

# Check common text writting issues
.PHONY: check
Sergey Goncharov's avatar
minor    
Sergey Goncharov committed
185
check:
Sergey Goncharov's avatar
Sergey Goncharov committed
186
187
	-echo "Checking duplicates.."
	-grep -Eon -r --include "*.tex" '(\b[[:alpha:]]+\b) \1\b' .