summaryrefslogtreecommitdiff
path: root/tex.mk
blob: 1c6ec1cdd7e4d2961eb2ce43ca252bc81187c653 (plain)
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
# -*- make -*-
# (C) 2013 by Eugeniy Mikhailov, <evgmik@gmail.com>

CLEAN_TARGETS      += clean_tex
REAL_CLEAN_TARGETS += real_clean_tex

dest_dir_tex ?= $(dest_dir)
destination_dirs += $(dest_dir_tex)

pdf_from_independent_tex= $(tex_independent:%.tex=%.pdf)
tex_independent_bases= $(tex_independent:%.tex=%)

tex_includes_bases = $(tex_includes:%.tex=%)

pdf_tex:  $(pdf_from_independent_tex)

pdf_tex_dest_targets = $(pdf_from_independent_tex:%=$(dest_dir_tex)/%)

tex_dest_targets = $(tex_independent:%=$(dest_dir_tex)/%)
ifneq ($(strip $(tex_includes)),)
tex_dest_targets += $(tex_includes:%=$(dest_dir_tex)/%)
endif
ifneq ($(strip $(tex_fig_files)),)
tex_dest_targets += $(tex_fig_files:%=$(dest_dir_tex)/%)
endif

# rubber does not deal with nicely with subfiles
# thus force switch below
$(pdf_from_independent_tex): %.pdf : %.tex $(tex_fig_files) $(tex_includes)
ifndef USE_PDF_LATEX
	rubber -f -d  $< 
else
	pdflatex $<
	bibtex $(<:%.tex=%) || ( if [ "$?" eq "2" ]; then echo "looks like not citations were used"; fi )
	pdflatex $<
	pdflatex $<
endif

install_pdf_tex: $(pdf_tex_dest_targets)

$(pdf_tex_dest_targets): $(dest_dir_tex)/% : % | $(dest_dir_tex)
ifneq ($(strip $(pdf_from_independent_tex)),)
	$(INSTALL) -m 0644 '$<' '$@'
endif

install_tex_src: $(tex_dest_targets)

$(tex_dest_targets): $(dest_dir_tex)/% : % | $(dest_dir_tex)
ifneq ($(strip $(tex_independent)),)
	$(INSTALL) -m 0644 '$<' '$@'
endif

clean_tex: clean_tex_aux

clean_tex_aux:
ifneq ($(strip $(tex_independent_bases)),)
	rm -f $(tex_independent_bases:%=%.dvi)
	rm -f $(tex_independent_bases:%=%.log)
	rm -f $(tex_independent_bases:%=%.aux)
	rm -f $(tex_independent_bases:%=%.nav)
	rm -f $(tex_independent_bases:%=%.out)
	rm -f $(tex_independent_bases:%=%.snm)
	rm -f $(tex_independent_bases:%=%.toc)
	rm -f $(tex_independent_bases:%=%.vrb)
	rm -f $(tex_independent_bases:%=%.blg)
	rm -f $(tex_independent_bases:%=%.bbl)
	rm -f missfont.log
	rm -f *Notes.bib
endif
ifneq ($(strip $(tex_includes_bases)),)
	rm -f $(tex_includes_bases:%=%.aux)
endif

real_clean_tex: clean_tex_aux
ifneq ($(strip $(pdf_from_independent_tex)),)
	rm -f $(pdf_from_independent_tex)
endif

.INTERMEDIATE: $(tex_independent_bases)