This repository has been archived by the owner on Sep 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
175 lines (122 loc) · 3.76 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
SRC_TEX=main.tex
SRC_BIB=bibliography.bib
SECTION_DIR=section
SECTION_FILES=$(shell find $(SECTION_DIR) -type f)
APPENDIX_DIR=appendix
APPENDIX_FILES=$(shell find $(APPENDIX_DIR) -type f)
META_DIR=meta
META_FILES=$(shell find $(META_DIR) -type f)
SRC_DIR=src
OUT_DIR=out
OUT_PDF_NAME=main.pdf
OUT_PDF=$(OUT_DIR)/$(OUT_PDF_NAME)
DIST_PDF=sewera-eng-thesis.pdf
CHART_DIR=chart
CHART_SRC_DIR=$(CHART_DIR)/$(SRC_DIR)
CHART_OUT_DIR=$(CHART_DIR)/$(OUT_DIR)
CHART_SRC_FILES=$(shell find $(CHART_SRC_DIR) -type f -name '*.mmd')
CHART_OUT_FILES=$(CHART_SRC_FILES:$(CHART_SRC_DIR)/%.mmd=$(CHART_OUT_DIR)/%.pdf)
META_SRC_DIR=$(META_DIR)/$(SRC_DIR)
META_OUT_DIR=$(META_DIR)/$(OUT_DIR)
ACRONYMS_FILE=acronyms.tex
ACRONYMS_SORTED_FILE=acronyms-sorted.tex
ACRONYMS_SRC_FILE=$(META_SRC_DIR)/$(ACRONYMS_FILE)
ACRONYMS_OUT_FILE=$(META_OUT_DIR)/$(ACRONYMS_SORTED_FILE)
DEPENDENCIES_DIR=node_modules
IGNORED_FILES=indent.log *.bib.blg
.PHONY: all install install-hooks clean-hooks pdf chart sa sort-acronyms sb sort-bibliography dist release version rerender rmout clean nuke tidy watch open
LATEXMK_OPTIONS=-output-directory=$(OUT_DIR) -bibtex -pdf -pdflatex=pdflatex
all: install $(OUT_PDF)
# Build PDF
pdf: $(OUT_PDF)
$(OUT_PDF): $(ACRONYMS_OUT_FILE) $(CHART_OUT_FILES) $(SRC_TEX) $(SRC_BIB) $(SECTION_FILES) $(APPENDIX_FILES) $(META_FILES)
@latexmk \
$(LATEXMK_OPTIONS) \
-synctex=1 \
-f \
-interaction=nonstopmode \
$(SRC_TEX) > /dev/null
@echo "> $@ rendered"
# Generate charts
chart: $(CHART_OUT_FILES)
$(CHART_OUT_DIR)/%.pdf: $(CHART_SRC_DIR)/%.mmd | $(CHART_OUT_DIR)
@yarn mmdc --pdfFit -b transparent -i $< -o $@ > /dev/null
@echo "> chart $@ rendered"
$(CHART_OUT_DIR):
@mkdir -p $(CHART_OUT_DIR)
@echo "> $(CHART_OUT_DIR) created"
# Sort acronyms
sa: sort-acronyms
sort-acronyms: $(ACRONYMS_OUT_FILE)
$(ACRONYMS_OUT_FILE): $(ACRONYMS_SRC_FILE) | $(META_OUT_DIR)
@sort $< > $@
@echo "> acronyms sorted"
$(META_OUT_DIR):
@mkdir -p $(META_OUT_DIR)
@echo "> $(META_OUT_DIR) created"
# Sort bibliography
sb: sort-bibliography
sort-bibliography:
@biber --tool $(SRC_BIB) --output-file=$(SRC_BIB) > /dev/null
# Project management
install: install-hooks
@yarn
@echo "> dependencies installed"
HOOKS_DIR=$(shell git rev-parse --show-toplevel)/.hooks
GIT_DIR=$(shell git rev-parse --absolute-git-dir)
GIT_HOOKS_DIR=$(GIT_DIR)/hooks
COMMIT_MSG_HOOK=commit-msg
PRE_COMMIT_HOOK=pre-commit
install-hooks: clean-hooks
@ln -s $(HOOKS_DIR)/$(COMMIT_MSG_HOOK) $(GIT_HOOKS_DIR)/$(COMMIT_MSG_HOOK)
@ln -s $(HOOKS_DIR)/$(PRE_COMMIT_HOOK) $(GIT_HOOKS_DIR)/$(PRE_COMMIT_HOOK)
@echo "> hooks installed"
clean-hooks:
@rm -f $(GIT_HOOKS_DIR)/*
pre-commit: sort-bibliography
@git add $(SRC_BIB)
@echo "> pre-commit ok"
rerender: rmout pdf
@echo "> rerender done"
release: $(DIST_PDF) version
@gh release create $(shell git tag --sort=-v:refname | head -n 1) $(DIST_PDF) --generate-notes
version:
@yarn version --minor --message "chore: release"
@git push --follow-tags
dist: $(DIST_PDF)
$(DIST_PDF): $(OUT_PDF)
@cp $(OUT_PDF) $(DIST_PDF)
@echo "> $(DIST_PDF) created"
rmout:
@rm -f $(DIST_PDF)
@echo "> rm $(DIST_PDF)"
@rm -rf $(OUT_DIR)
@echo "> rm $(OUT_DIR)"
clean: rmout
@rm -rf $(CHART_OUT_DIR)
@echo "> rm $(CHART_OUT_DIR)"
@rm -rf $(META_OUT_DIR)
@echo "> rm $(META_OUT_DIR)"
@rm -f $(IGNORED_FILES)
@echo "> rm $(IGNORED_FILES)"
nuke: clean
@rm -rf $(DIST_PDF)
@rm -rf $(DEPENDENCIES_DIR)
@echo "> rm $(DEPENDENCIES_DIR)"
# Development
watch:
@echo "> rendering pdf in continuous watch mode"
@echo "> ctrl+c to stop"
@while :; do \
if ! $(MAKE) pdf > /dev/null; then \
echo "> error when rendering pdf, see $(OUT_DIR)/main.log"; \
fi; \
sleep 5; \
done
# Open
OPEN_CMD=xdg-open
ifeq (, $(shell which xdg-open))
OPEN_CMD=open
endif
open: pdf
@$(OPEN_CMD) $(OUT_PDF)