-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathMakefile
103 lines (85 loc) · 3.41 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
# Makefile
# -----------------------------------------------------------------------------
# Converts Markdown to various formats (HTML via MkDocs, PDF, DOCX, EPUB)
# using Pandoc and MkDocs.
#
# Usage:
# make - Convert Markdown files to PDF, DOCX, EPUB and build the MkDocs site.
# make mkdocs - Build the MkDocs site.
# make serve - Serve the MkDocs site locally.
# make copy-pdfs - Copy all PDF files from the docs folder to build/pdf.
# make zip-pdfs - Create a zip file of all files in the build/pdf folder.
# make clean - Delete all generated files.
#
# Prerequisites:
# - pandoc (Ubuntu: `sudo apt-get install pandoc`)
# - a LaTeX distribution (for PDF conversion, e.g., xelatex)
# - mkdocs (and optionally, mkdocs-material and mike)
#
# -----------------------------------------------------------------------------
# Source Files
MAIN_DOC := docs/architecture-and-reference-framework-main.md
ANNEXES_DOCS := $(wildcard docs/annexes/annex-[1-3]/*.md)
SOURCE_DOCS := $(MAIN_DOC) $(ANNEXES_DOCS)
# Directories and Build Information
BUILD_DIR := ./build
SITE_DIR := ./site
VERSION := 1.6.0
BUILD := $(shell date +%Y%m%d.%H%M%S)
# Pandoc configuration
PANDOC_DATA_DIR := ./pandoc
PDF_TEMPLATE := eisvogel
# Exported Documents (the target names are based on the source file names)
EXPORTED_DOCS := \
$(SOURCE_DOCS:.md=.pdf) \
$(SOURCE_DOCS:.md=.docx) \
$(SOURCE_DOCS:.md=.epub)
# Tools
RM := /bin/rm
PANDOC := pandoc
MKDOCS := mkdocs
# Pandoc Options
PANDOC_OPTIONS := --toc --from markdown+gfm_auto_identifiers --data-dir $(PANDOC_DATA_DIR) --metadata date="v$(VERSION) $(BUILD)"
PANDOC_PDF_OPTIONS := --pdf-engine=pdflatex --template=$(PDF_TEMPLATE) --listings $(PANDOC_DATA_DIR)/metadata.yml
PANDOC_DOCX_OPTIONS :=
PANDOC_EPUB_OPTIONS := --to epub3
# Pattern Rules for Conversions
# -----------------------------------------------------------------------------
# Convert Markdown to PDF
%.pdf : %.md
@mkdir -p $(BUILD_DIR)/pdf
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_PDF_OPTIONS) -o $(BUILD_DIR)/pdf/$(notdir $@) $<
# Convert Markdown to DOCX
%.docx : %.md
@mkdir -p $(BUILD_DIR)/docx
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_DOCX_OPTIONS) -o $(BUILD_DIR)/docx/$(notdir $@) $<
# Convert Markdown to EPUB
%.epub : %.md
@mkdir -p $(BUILD_DIR)/epub
$(PANDOC) $(PANDOC_OPTIONS) $(PANDOC_EPUB_OPTIONS) -o $(BUILD_DIR)/epub/$(notdir $@) $<
# Targets
# -----------------------------------------------------------------------------
.PHONY: all mkdocs serve copy-pdfs zip-pdfs clean
# Default target: build all exported documents and the MkDocs site.
all: $(EXPORTED_DOCS) zip-pdfs
# Build the MkDocs site
mkdocs:
$(MKDOCS) build
# Serve the MkDocs site locally
serve:
$(MKDOCS) serve
# Copy all PDF files from the docs folder to the build/pdf directory.
copy-pdfs:
@echo "Copying PDF files from docs/ to $(BUILD_DIR)/pdf/..."
@mkdir -p $(BUILD_DIR)/pdf
@find docs -maxdepth 3 -type f -iname "*.pdf" -exec cp {} $(BUILD_DIR)/pdf \;
@echo "PDF files have been copied."
# Create a zip archive of all files in the build/pdf folder.
zip-pdfs: copy-pdfs
@echo "Creating zip archive of PDFs in $(BUILD_DIR)/pdf..."
@cd $(BUILD_DIR) && zip -r arf-pdfs-v$(VERSION).zip pdf/*
@echo "Zip archive created at $(BUILD_DIR)/pdf.zip."
# Clean generated files and directories.
clean:
@echo "Cleaning build and site directories..."
-$(RM) -rf $(BUILD_DIR) $(SITE_DIR)