-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
86 lines (62 loc) · 2.62 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
####################################################################################################
# Configuration
####################################################################################################
# Build configuration
BUILD = build
MAKEFILE = Makefile
OUTPUT_FILENAME = book
METADATA = metadata.yml
CHAPTERS_DIR=chapters
TOC = --toc --toc-depth 2
METADATA_ARGS = --metadata-file $(METADATA)
IMAGES = $(shell find images -type f)
TEMPLATES = $(shell find templates/ -type f)
COVER_IMAGE = images/cover.png
MATH_FORMULAS = --webtex
CHAPTERS=$(shell find $(CHAPTERS_DIR) -name "*.md" -type f | sort)
# Chapters content
CONTENT = awk 'FNR==1 && NR!=1 {print "\n\n"}{print}' $(CHAPTERS)
CONTENT_FILTERS = tee # Use this to add sed filters or other piped commands
# Debugging
# DEBUG_ARGS = --verbose
# Pandoc filtes - uncomment the following variable to enable cross references filter. For more
# information, check the "Cross references" section on the README.md file.
# FILTER_ARGS = --filter pandoc-crossref
# Combined arguments
ARGS = $(TOC) $(MATH_FORMULAS) $(METADATA_ARGS) $(FILTER_ARGS) $(DEBUG_ARGS)
PANDOC_COMMAND = pandoc
# Per-format options
HTML_ARGS = --template templates/html.html --katex --standalone --to html5
PDF_ARGS = -V toccolor=blue -V linkcolor=blue --template templates/pdf.latex --pdf-engine xelatex
# Per-format file dependencies
BASE_DEPENDENCIES = $(MAKEFILE) $(CHAPTERS) $(METADATA) $(IMAGES) $(TEMPLATES)
DOCX_DEPENDENCIES = $(BASE_DEPENDENCIES)
EPUB_DEPENDENCIES = $(BASE_DEPENDENCIES)
HTML_DEPENDENCIES = $(BASE_DEPENDENCIES)
PDF_DEPENDENCIES = $(BASE_DEPENDENCIES)
####################################################################################################
# Basic actions
####################################################################################################
.PHONY: all
all: book
.PHONY: book
book: html pdf
.PHONY: clean
clean:
rm -r $(BUILD)
####################################################################################################
# File builders
####################################################################################################
.PHONY: html
html: $(BUILD)/html/$(OUTPUT_FILENAME).html
.PHONY: pdf
pdf: $(BUILD)/pdf/$(OUTPUT_FILENAME).pdf
$(BUILD)/html/$(OUTPUT_FILENAME).html: $(HTML_DEPENDENCIES)
mkdir -p $(BUILD)/html
$(CONTENT) | $(CONTENT_FILTERS) | $(PANDOC_COMMAND) $(ARGS) $(HTML_ARGS) -o $@
cp --parent $(IMAGES) $(BUILD)/html/
@echo "$@ was built"
$(BUILD)/pdf/$(OUTPUT_FILENAME).pdf: $(PDF_DEPENDENCIES)
mkdir -p $(BUILD)/pdf
$(CONTENT) | $(CONTENT_FILTERS) | $(PANDOC_COMMAND) $(ARGS) $(PDF_ARGS) -o $@
@echo "$@ was built"