-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
69 lines (57 loc) · 1.89 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
# Build configuration
BUILD = assets
MAKEFILE = Makefile
OUTPUT_FILENAME = niddesa
METADATA = metadata.yml
CHAPTERS = book/*.md book/mnd/*.md book/cnd/*.md book/appdx/*.md
TOC = --toc --toc-depth 4
METADATA_ARGS = --metadata-file $(METADATA)
TEMPLATES = $(shell find templates/ -type f)
PAGEBREAK = -L templates/pagebreak.lua
# COVER_IMAGE = cover.jpg
# Chapters content
CONTENT = awk 'FNR==1 && NR!=1 {print "\n\n"}{print}' $(CHAPTERS)
# Debugging
# DEBUG_ARGS = --verbose
# Combined arguments
ARGS = $(PAGEBREAK) $(TOC) $(METADATA_ARGS) $(DEBUG_ARGS)
PANDOC_COMMAND = pandoc
# Per-format options
EPUB_ARGS = --template templates/epub.html # --epub-cover-image $(COVER_IMAGE)
HTML_ARGS = --template templates/html.html --standalone --to html5
PDF_ARGS = --template templates/pdf.latex --pdf-engine xelatex -V geometry:margin=1.5in --variable urlcolor=teal
# Per-format file dependencies
BASE_DEPENDENCIES = $(MAKEFILE) $(CHAPTERS) $(METADATA) $(TEMPLATES)
EPUB_DEPENDENCIES = $(BASE_DEPENDENCIES)
HTML_DEPENDENCIES = $(BASE_DEPENDENCIES)
PDF_DEPENDENCIES = $(BASE_DEPENDENCIES)
# Basic targets
.PHONY: all
all: book site
.PHONY: book
book: epub html pdf
.PHONY: clean
clean:
rm -rf $(BUILD)
rm -f index.html
site:
pandoc -f gfm README.md -s -t html5 --template=templates/index.html -o index.html
# Builders
.PHONY: epub
epub: $(BUILD)/$(OUTPUT_FILENAME).epub
.PHONY: html
html: $(BUILD)/$(OUTPUT_FILENAME).html
.PHONY: pdf
pdf: $(BUILD)/$(OUTPUT_FILENAME).pdf
$(BUILD)/$(OUTPUT_FILENAME).epub: $(EPUB_DEPENDENCIES)
mkdir -p $(BUILD)
$(CONTENT) | $(PANDOC_COMMAND) $(ARGS) $(EPUB_ARGS) -o $@
@echo "$@ was built"
$(BUILD)/$(OUTPUT_FILENAME).html: $(HTML_DEPENDENCIES)
mkdir -p $(BUILD)
$(CONTENT) | $(PANDOC_COMMAND) $(ARGS) $(HTML_ARGS) -o $@
@echo "$@ was built"
$(BUILD)/$(OUTPUT_FILENAME).pdf: $(PDF_DEPENDENCIES)
mkdir -p $(BUILD)
$(CONTENT) | $(PANDOC_COMMAND) $(ARGS) $(PDF_ARGS) -o $@
@echo "$@ was built"