-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
139 lines (119 loc) · 3.77 KB
/
Makefile
File metadata and controls
139 lines (119 loc) · 3.77 KB
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
# default parameters
ROOT:="$(PWD)"
SRCDIR:=src
HEADERDIR:=src/header
BIBDIR:=src/bib
BINDIR:=bin
FIGDIR:=figures
VIDEODIR:=video
BUILDDIR:=build
# useful parameter from above
# assumes there is a tikz folder in figures to compile them
TIKZDIR:=$(shell find $(SRCDIR) -name "tikz" -type d)
# get the main tex and save the name wihtout extension in TARGETNAME
TARGETNAME:=$(shell grep -Elr 'documentclass' `find $(SRCDIR) -name "*.tex"`)
TARGETNAME:=$(notdir $(TARGETNAME))
TARGETNAME:=$(basename $(TARGETNAME))
$(info The main tex is $(TARGETNAME))
DEPEND_SRCS:= $(shell find $(SRCDIR) -name '*.tex')
DEPEND_SRCS_FIG:= $(shell find $(TIKZDIR) -name '*.tex')
# export this variable to access the .cls in the header folder
export TEXINPUTS=.:./header/:
define link_bst_bib_sty
for f in $(shell find $(SRCDIR) -name "*.sty" | sed -e "s/^/\"/g" -e 's/$$/"/g' ) \
$(shell find $(SRCDIR) -name "*.bib" | sed -e "s/^/\"/g" -e 's/$$/"/g' ) \
$(shell find $(SRCDIR) -name "*.bst" | sed -e "s/^/\"/g" -e 's/$$/"/g' ) \
$(shell find $(SRCDIR) -name "*.cls" | sed -e "s/^/\"/g" -e 's/$$/"/g' ) ; do \
echo $$f ; \
ln -sf $(ROOT)/$$f $(ROOT)/$(BUILDDIR)/ ;\
done
ln -sf $(ROOT)/$(VIDEODIR) $(ROOT)/$(BUILDDIR)/
endef
define prepare_build
if [ ! -d "$(BUILDDIR)" ]; then mkdir $(BUILDDIR); fi
if [ ! -d "$(BINDIR)" ]; then mkdir $(BINDIR); fi
$(call link_bst_bib_sty)
endef
define end_build
echo "copy of \"" $(1) "\" in the build folder"
for pdffile in $(1) ; do \
if [ -f $(ROOT)/$(BUILDDIR)/$$pdffile.pdf ]; then \ \
echo "Copying file :" $$pdffile.pdf ; \
cp $(ROOT)/$(BUILDDIR)/$$pdffile.pdf $(ROOT)/$(BINDIR)/ ; \
else \
echo "Error: file $$pdffile.pdf not found in build folder!" ; \
fi ; \
done
endef
define pdf_latex
echo "pdf_latex arguments are :" $(1) $(2)
for targetname in $(2) ; do \
cd $(1) ;\
texfile=`find . -name "$$targetname.tex"` ;\
working_dir=`echo $$texfile | sed 's|/[^/]*$$||'` ;\
cd $$working_dir ;\
texfile=`find . -name "$$targetname.tex"` ;\
pdflatex -shell-escape -interaction=nonstopmode --output-directory=$(ROOT)/$(BUILDDIR) $$texfile;\
cd $(ROOT) ; pwd ;\
done
endef
define pdf_latex_debug
echo "pdf_latex arguments are :" $(1) $(2)
for texfiles in $(2) ; do \
echo "Compiling :" $$texfiles.tex ;\
cd $(1) ; pdflatex -shell-escape --output-directory=$(ROOT)/$(BUILDDIR) $$texfiles.tex ; cd $(ROOT) ; pwd ;\
done
endef
define biber
for bibfiles in $(1) ; do \
echo "biber on :" $$bibfiles ;\
cd $(ROOT)/$(BUILDDIR) ; biber $$bibfiles ; cd $(ROOT)/ ; \
done
endef
define build
$(call pdf_latex, $(1), $(2))
$(call biber, $(2))
$(call pdf_latex, $(1), $(2))
$(call pdf_latex, $(1), $(2))
endef
define build_fast
$(call pdf_latex, $(1), $(2))
$(call biber, $(2))
endef
define build_debug
$(call pdf_latex_debug, $(1), $(2))
$(call biber, $(2))
endef
define build_figure
$(call build, $1, $(basename $2))
cp $(ROOT)/$(BUILDDIR)/$(basename $(notdir $2)).pdf $(ROOT)/$(FIGDIR)
echo "End of build_figure"
endef
all: $(DEPEND_SRCS)
$(call prepare_build)
$(call build, $(ROOT)/$(SRCDIR), $(TARGETNAME))
$(call end_build, $(TARGETNAME))
$(TARGETNAME): $(DEPEND_SRCS)
$(call prepare_build)
$(call build_fast, $(ROOT)/$(SRCDIR), $@)
$(call end_build, $@)
figures: $(DEPEND_SRCS_FIG)
$(call prepare_build)
$(foreach source, $(DEPEND_SRCS_FIG), $(call build_figure, $(TIKZDIR), $(source)))
fast: $(DEPEND_SRCS)
$(call prepare_build)
$(call build_fast, $(ROOT)/$(SRCDIR), $(TARGETNAME))
$(call end_build, $(TARGETNAME))
count: $(DEPEND_SRCS)
wc -w $(DEPEND_SRCS)
bib : $(DEPEND_SRCS)
$(call prepare_build)
$(call biber,$(TARGETNAME))
debug: $(DEPEND_SRCS)
$(call prepare_build)
$(call build_debug, $(ROOT)/$(SRCDIR), $(TARGETNAME))
$(call end_build, $(TARGETNAME))
clean:
rm -f ./build/*
bash_instruction:
$(call link_bst_bib_sty)