-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
82 lines (62 loc) · 2.01 KB
/
makefile
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
# Global parameters for PDF creation
BUILD_DIR ?=./build
TMP_DIR =$(BUILD_DIR)/tmp
TARGET_NAME ?=$(notdir $(basename $(RECP)))
TARGET_FILE =$(TMP_DIR)/$(TARGET_NAME).pdf
TARGET_LETTER =$(TMP_DIR)/$(TARGET_NAME)_letter.pdf
PDFLATEX_ARGS ?= \
-synctex=1 \
-file-line-error \
-interaction=errorstopmode
TEMPLATE_LETTER ?=src/template_letter.tex
TEMPLATE_CV ?=src/template_cv.tex
TEMPLATE_CORE ?=src/template_core.tex
PDFLATEX_TEX_ARGS := \
"\\input{$(CV)} \
\\input{$(RECP)} \
\\input{$(TEMPLATE_CORE)} \
\\def\\CVDataPath{$(dir $(CV))}"
# helper function to check existence of env vars
define check_env_var
$(if $(value $(1)),,$(error "'$(1)' not passed. Use 'make $(1)=file.tex'."))
$(if $(wildcard ./$(value $(1))),,$(error "'$(1)'-file '$(value $(1))' not found."))
endef
$(TARGET_FILE): check_env_args $(BUILD_DIR) $(TARGET_LETTER)
$(eval jobname :=$(notdir $(basename $(TARGET_FILE))))
# pdflatex parses its input once and is thus not able to create a TOC
# index ahead. Therefore we need to execute it twice to create a complete
# TOC file for the the second run.
@echo -e "\n\n--- Building TOC index. ---\n\n"
pdflatex \
-output-directory=$(TMP_DIR) \
-jobname=$(jobname) \
$(PDFLATEX_ARGS) \
$(PDFLATEX_TEX_ARGS) \
"\\def\\InputLetter{$(TARGET_LETTER)} \
\\input{$(TEMPLATE_CV)}"
@echo -e "\n\n--- Creating CV PDF. ---\n\n"
pdflatex \
-output-directory=$(TMP_DIR) \
-jobname=$(jobname) \
$(PDFLATEX_ARGS) \
$(PDFLATEX_TEX_ARGS) \
"\\def\\InputLetter{$(TARGET_LETTER)} \
\\input{$(TEMPLATE_CV)}"
mv $(TARGET_FILE) $(BUILD_DIR)
$(TARGET_LETTER): check_env_args $(BUILD_TMP)
@echo -e "\n\n--- Creating letter PDF. ---\n\n"
pdflatex \
-output-directory=$(TMP_DIR) \
-jobname=$(notdir $(basename $(TARGET_LETTER))) \
$(PDFLATEX_ARGS) \
$(PDFLATEX_TEX_ARGS) \
"\\input{$(TEMPLATE_LETTER)}"
.PHONY: check_env_args
check_env_args:
$(call check_env_var,CV)
$(call check_env_var,RECP)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
$(BUILD_DIR):
mkdir -p $(BUILD_DIR) $(TMP_DIR)