Makefile 5.39 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
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
# 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
DVIPS	= dvips 
PDFPS	= pdftops
PDF	= max_print_line=1000 pdflatex -shell-escape -src -halt-on-error -synctex=1 -interaction nonstopmode -file-line-error-style 
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
clean : 
	@echo Soft clean
	-rm *.blg *.log *.out $(DVINAMES) $(PDFNAMES) 2>/dev/null ; true 

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

.PHONY: cleanaux
cleanaux : 
	-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

%.bbl: $(BIBSRC) 
	@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

%.dvi: $(TEXSRC) $(wildcard $(THISDIR)*.tex) 
	@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)
	
	@echo If the citations were updated recompile the .bbl file
	grep -o -G "Citation \`[^']*" $(@:.dvi=.log) | md5sum -c $(@:.dvi=.cit) || $(BIBTEX) $(@:.dvi=.aux)
	
	while grep -q "Rerun to get cross-references right." $(@:.dvi=.log); \
	do $(LATEX) $(@:.dvi=.tex); done
	
	@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
	@echo Compiling $@ 
	($(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;  \
        fi

	@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"; \
	fi 

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

%.ps : %.pdf 
	$(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
167
168
	# 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
	cp *.bib *.bbl *.bst submission
	# copying all files from the current directory mentioned in log-file
Sergey Goncharov's avatar
Sergey Goncharov committed
169
	for file in *; do if grep --quiet $$file *.log; then cp $$file submission; fi; done
Sergey Goncharov's avatar
Sergey Goncharov committed
170
	# remove comments
Sergey Goncharov's avatar
Sergey Goncharov committed
171
	for file in submission/*.tex; do perl -i -pe 's/(^|[^\\])%.*/\1%/' $$file; done
Sergey Goncharov's avatar
Sergey Goncharov committed
172
173
174
	# 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
175
176
177
178
179
180
181
182
183
184
185

.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
check: 
	-echo "Checking duplicates.."
	-grep -Eon -r --include "*.tex" '(\b[[:alpha:]]+\b) \1\b' .