-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
211 lines (166 loc) · 6.18 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# Remove all stupid builtin rules and variables
MAKEFLAGS += --no-builtin-rules --no-builtin-variables --warn-undefined-variables
SUPPORTED_LANGUAGES = sk en cs hu pl es de fr ru fa
path := $(abspath $(lastword $(MAKEFILE_LIST)))
cdir := $(dir $(path))
version = '4.03'
date = '2023-09-14'
c_error := $(shell tput sgr0; tput bold; tput setaf 1)
c_action := $(shell tput sgr0; tput bold; tput setaf 4)
c_filename := $(shell tput sgr0; tput setaf 5)
c_extension := $(shell tput sgr0; tput bold; tput setaf 2)
c_special := $(shell tput sgr0; tput setaf 3)
c_default := $(shell tput sgr0; tput setaf 7)
# Remove all default suffixes
.SUFFIXES:
.SECONDARY:
# No interactive mode with texfot
# and ignore underfull warnings
TEXFOT_ARGS=--no-interactive \
--ignore 'Underfull.*'
# On the first run, also ignore missing cross-references and acronyms as they cannot be correct yet
TEXFOT_ARGS_FIRST=${TEXFOT_ARGS} \
--ignore 'LaTeX Warning: Hyper reference.*' \
--ignore 'LaTeX Warning: Reference.*' \
--ignore 'LaTeX Warning: Citation.*'
# xelatex(module, run, texfot_args)
# Compiles a selected target
define xelatex
@echo -e '$(c_action)[XeLaTeX] Compiling PDF file $(c_filename)$@$(c_action): $(2) run$(c_default)'
@texfot $(3) xelatex -file-line-error -shell-escape -jobname=$(subst .pdf,,$@) \
-halt-on-error -synctex=1 -interaction=nonstopmode build/$(1)/$*/$(basename $(notdir $@)).tex
endef
# _pandoc(language, format, pretty_format)
define _pandoc
@echo -e '$(c_action)[convert] Converting \
$(c_extension)Markdown$(c_action) file $(c_filename)$<$(c_action) to \
$(c_extension)$(3)$(c_action) file $(c_filename)$@$(c_action)$(c_default)'
@mkdir -p $(dir $@)
python convert.py $(2) $(1) $< $@ || exit 1;
endef
# pandoctex(language)
# Converts a file from Markdown to LaTeX
define pandoctex
$(call _pandoc,$(1),latex,TeX)
endef
# pandochtml(language)
# Converts a file from Markdown to HTML
define pandochtml
$(call _pandoc,$(1),html,HTML)
endef
# double_xelatex(module)
# Compiles a selected target twice (to ensure references are correct)
define double_xelatex
mkdir -p $(dir $@)
$(call xelatex,$(1),primary,${TEXFOT_ARGS_FIRST})
$(call xelatex,$(1),secondary,${TEXFOT_ARGS})
endef
# copy(extension)
define _copy
@echo -e '$(c_action)Copying $(c_extension)$(1)$(c_action) file $(c_filename)$<$(c_action):$(c_default)'
@mkdir -p $(dir $@)
cp $< $@
endef
include modules/*/module.mk
build/core/i18n/%.tex: \
core/templates/override.jtt
@mkdir -p $(dir $@)
python -m core.builder.i18n 'core/i18n/' 'core/templates/' $* -o $(dir $@)
build/core/i18n: \
$$(foreach lang,$$(SUPPORTED_LANGUAGES),build/core/i18n/$$(lang).tex) ;
# DeGeŠ convert Markdown file to TeX (for XeLaTeX)
# THIS IS CURRENTLY HARDCODED TO WORK IN SLOVAK ONLY, OVERRIDE THIS IN MODULE!
build/%.tex: source/%.md
ifdef lang
$(call pandoctex,$(lang))
else
$(call pandoctex,sk)
endif
# Copy TeX files from source to build
build/%.tex: source/%.tex
$(call _copy,TeX)
# Copy py files from source to build
build/%.py: source/%.py
$(call _copy,Python)
# Convert SVG image to PDF (for XeLaTeX output)
build/%.pdf: source/%.svg
@echo -e '$(c_action)[rsvg-convert] Converting $(c_filename)$<$(c_action) to $(c_extension)PDF$(c_action) file $(c_filename)$@$(c_action):$(c_default)'
@mkdir -p $(dir $@)
rsvg-convert --format pdf --keep-aspect-ratio --output $@ $<
pdfcrop $@ $@-crop
mv $@-crop $@
# Render gnuplot file to PDF (for XeLaTeX)
build/%.pdf: build/%.gp
@echo -e '$(c_action)[gnuplot] Rendering file $(c_filename)$<$(c_action) to $(c_extension)PDF$(c_action) file $(c_filename)$@$(c_action):$(c_default)'
@mkdir -p $(dir $@)
cd $(dir $@); gnuplot -e "set terminal pdf font 'TeX Gyre Pagella, 12'; set output '$(notdir $@)'; set fit quiet;" $(notdir $<)
# Copy PDF file (for XeLaTeX)
build/%.pdf: source/%.pdf
$(call _copy,PDF)
# Copy PNG file (to build)
build/%.png: source/%.png
$(call _copy,PNG)
# Copy JPG file (to build)
build/%.jpg: source/%.jpg
$(call _copy,JPG)
# Copy DAT file (to build)
build/%.dat: source/%.dat
$(call _copy,dat)
# Output PNG from SVG (for web)
output/%.png: source/%.svg
@echo -e '$(c_action)[rsvg-convert] Converting SVG file $(c_filename)$<$(c_action) to PNG file $(c_filename)$@$(c_action):$(c_default)'
@mkdir -p $(dir $@)
rsvg-convert -f png -h 500 -a -o $@ $<
# Copy SVG (for web)
output/%.svg: source/%.svg
@echo -e '$(c_action)[rsvg-convert] Converting SVG file $(c_filename)$<$(c_action) to PNG file $(c_filename)$@$(c_action):$(c_default)'
@mkdir -p $(dir $@)
rsvg-convert -f svg -h 500 -a -o $@ $<
# Copy PNG (for web)
output/%.png: source/%.png
$(call _copy,PNG)
# Copy py (for web)
output/%.py: source/%.py
$(call _copy,Python)
# Render gnuplot file to PNG (for web)
output/%.png: build/%.gp
@echo -e '$(c_action)[gnuplot] rendering file $(c_filename)$<$(c_action) to PNG file $(c_filename)$@$(c_action):$(c_default)'
@mkdir -p $(dir $@)
cd $(subst output/,build/,$(dir $@)); gnuplot -e "set terminal png font 'TeX Gyre Pagella, 12'; set output '$(notdir $@)'; set fit quiet;" $(notdir $<)
cp $(subst output/,build/,$@) $@
# Copy JPG (for web)
output/%.jpg: source/%.jpg
$(call _copy,JPG)
# DeGeŠ convert Markdown to HTML (for web)
output/%.html: source/%.md
$(call pandochtml,sk)
# DeGeŠ convert Markdown to HTML (for web)
#output/%.html: source/%.md
# $(call pandochtml,sk)
# ./wr -input $@ -template core/latex/wr.tex --engine xelatex -innerhtml -eqdir .webtex -output [email protected]
# mv [email protected] $@
.SECONDEXPANSION:
# Copy Gnuplot file to build, along with all of its possible .dat prerequisites
build/%.gp:\
source/%.gp\
$$(subst source/,build/,$$(wildcard $$(dir source/%.gp)*.dat))
@mkdir -p $(dir $@)
@echo -e '$(c_action)Copying gnuplot file $(c_filename)$<$(c_action):$(c_default)'
cp $< $@
%/copy-static: \
$$(wildcard $$(subst build/,source/,$$*)/.static/*)
@echo -e '$(c_action)Copying static files for $(c_filename)$*$(c_action):$(c_default)'
@mkdir -p $(dir $@).static/
cp -r $(subst build/,source/,$*)/.static/ $*/
output/%/clean:
rm -rf output/$*/
output/%/distclean: \
output/%/clean
rm -rf build/$*/
clean:
@echo -e '$(c_action)Clean:$(c_default)'
rm -rf build/
distclean: clean
@echo -e '$(c_action)Dist clean:$(c_default)'
rm -rf output/
.PHONY: clean distclean hello