forked from SELinuxProject/selinux-notebook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
139 lines (128 loc) · 5.03 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
##
# The SELinux Notebook
#
SED = sed
PANDOC = pandoc
# Find if Calibre ebook-convert command is installed, if so produce a
# Kindle version in azw3 format
EBOOK_CONVERT = $(shell whereis -b ebook-convert | cut -f 2 -d :)
CWD ?= $(shell pwd)
SCRIPTS = $(CWD)/scripts
SRCDIR = $(CWD)/src
HTMLDIR ?= $(CWD)/html
PDFDIR ?= $(CWD)/pdf
EPUBDIR ?= $(CWD)/epub
IMAGES = $(SRCDIR)/images
EXAMPLES = $(SRCDIR)/notebook-examples
EXAMPLES_EPUB = $(shell echo $(EXAMPLES) | $(SED) 's;/;\\/;g')
METADATA = $(SRCDIR)/metadata.yaml
HTML_OUT = SELinux_Notebook.html
PDF_OUT = SELinux_Notebook.pdf
EPUB_OUT = SELinux_Notebook.epub
AZW3_OUT = SELinux_Notebook.azw3
PANDOC_OPTS = --from markdown+pipe_tables
PANDOC_OPTS += -V mainfont='DejaVu Serif' -V monofont='DejaVu Sans Mono'
# the individual section files, in order
FILE_LIST = $(shell cat src/section_list.txt)
DEP_FILE_LIST = $(addprefix src/,$(FILE_LIST))
help:
@echo "targets:"
@grep "^#@ " Makefile | cut -c4-
#@ all build the PDF, HTML, and EPUB versions
all: html pdf epub
#@ navlinks update the navigation links in the markdown sources
.PHONY: navlinks
navlinks:
for i in $(DEP_FILE_LIST); do \
file=$$(basename $$i); \
prev=$$(sed -n "/$$file/{x;p;d;}; x" src/section_list.txt); \
next=$$(sed -n "/$$file/{n;p;}" src/section_list.txt); \
sed "/<!-- %CUTHERE% -->/q" -i $$i; \
echo "" >> $$i; \
echo "---" >> $$i; \
[[ "x$$prev" != "x" ]] && echo -n "**[[ PREV ]]($$prev)**" >> $$i; \
echo -n " **[[ TOP ]](#)** " >> $$i; \
[[ "x$$next" != "x" ]] && echo -n "**[[ NEXT ]]($$next)**" >> $$i; \
echo "" >> $$i; \
done
#@ pdf build PDF version
.PHONY: pdf
pdf: $(DEP_FILE_LIST) $(METADATA)
mkdir -p $(PDFDIR)
cat $(METADATA) > $(PDFDIR)/.full_document.md
cat $(SRCDIR)/cover.md | $(SCRIPTS)/macros_section.sh \
>> $(PDFDIR)/.full_document.md
for i in $(DEP_FILE_LIST); do \
cat $$i | $(SCRIPTS)/macros_section.sh \
>> $(PDFDIR)/.full_document.md; \
echo '<!-- %PAGEBREAK% -->' \
>> $(PDFDIR)/.full_document.md; \
done
$(SCRIPTS)/macros_doc.sh $(PDFDIR)/.full_document.md
# embed the images into the PDF
$(SED) -i 's/!\[].*\images/!\[]('"$(subst /,\/,./images)"'/' \
$(PDFDIR)/.full_document.md
$(SED) -i 's/](.*\.md#/](#/' $(PDFDIR)/.full_document.md
# remove the section file name from all HTML links
$(SED) -i 's/href=.*\.md#/href="#/' $(PDFDIR)/.full_document.md
[ -e $(PDFDIR)/images ] || ln -s $(IMAGES) $(PDFDIR)
[ -e $(PDFDIR)/notebook-examples ] || ln -s $(EXAMPLES) $(PDFDIR)
(cd $(PDFDIR); $(PANDOC) --pdf-engine=weasyprint $(PANDOC_OPTS) \
--css=$(SRCDIR)/styles_pdf.css --self-contained \
$(PDFDIR)/.full_document.md -o $(PDFDIR)/$(PDF_OUT))
#@ html build HTML version
.PHONY: html
html: $(DEP_FILE_LIST) $(METADATA)
mkdir -p $(HTMLDIR)
cat $(METADATA) > $(HTMLDIR)/.full_document.md
cat $(SRCDIR)/cover.md | $(SCRIPTS)/macros_section.sh \
>> $(HTMLDIR)/.full_document.md
for i in $(DEP_FILE_LIST); do \
cat $$i | $(SCRIPTS)/macros_section.sh \
>> $(HTMLDIR)/.full_document.md; \
echo '<!-- %PAGEBREAK% -->' \
>> $(HTMLDIR)/.full_document.md; \
done
$(SCRIPTS)/macros_doc.sh $(HTMLDIR)/.full_document.md
# remove the section file name from all MD links
$(SED) -i 's/](.*\.md#/](#/' $(HTMLDIR)/.full_document.md
# remove the section file name from all HTML links
$(SED) -i 's/href=.*\.md#/href="#/' $(HTMLDIR)/.full_document.md
[ -e $(HTMLDIR)/images ] || ln -s $(IMAGES) $(HTMLDIR)
[ -e $(HTMLDIR)/notebook-examples ] || ln -s $(EXAMPLES) $(HTMLDIR)
(cd $(HTMLDIR); $(PANDOC) $(PANDOC_OPTS) \
--css=$(SRCDIR)/styles_html.css --self-contained \
$(HTMLDIR)/.full_document.md -o $(HTMLDIR)/$(HTML_OUT))
#@ epub build EPUB version
.PHONY: epub
epub: $(DEP_FILE_LIST) $(METADATA)
mkdir -p $(EPUBDIR)
cat $(METADATA) > $(EPUBDIR)/.full_document.md
cat $(SRCDIR)/cover_epub.md | $(SCRIPTS)/macros_section.sh \
>> $(EPUBDIR)/.full_document.md
for i in $(DEP_FILE_LIST); do \
cat $$i | $(SCRIPTS)/macros_section.sh \
>> $(EPUBDIR)/.full_document.md; \
echo '<!-- %PAGEBREAK% -->' \
>> $(EPUBDIR)/.full_document.md; \
done
$(SCRIPTS)/macros_doc.sh $(EPUBDIR)/.full_document.md
$(SED) -i 's/](.*\.md#/](#/' $(EPUBDIR)/.full_document.md
# remove the section file name from all HTML links
$(SED) -i 's/href=.*\.md#/href="#/' $(EPUBDIR)/.full_document.md
# fixup path for examples, otherwise defaults to file:///EPUB/text
$(SED) -i 's/](.\/notebook-examples/](file:\/\/$(EXAMPLES_EPUB)/g' \
$(EPUBDIR)/.full_document.md
[ -e $(EPUBDIR)/images ] || ln -s $(IMAGES) $(EPUBDIR)
[ -e $(EPUBDIR)/notebook-examples ] || ln -s $(EXAMPLES) $(EPUBDIR)
(cd $(EPUBDIR); $(PANDOC) $(PANDOC_OPTS) \
--epub-cover-image=$(SRCDIR)/images/selinux-penguin.png \
--css=$(SRCDIR)/styles_epub.css --self-contained \
$(EPUBDIR)/.full_document.md -o $(EPUBDIR)/$(EPUB_OUT))
# Convert to Kindle format if Calibre ebook-convert is installed
[ -b $(EBOOK_CONVERT) ] || $(EBOOK_CONVERT) $(EPUBDIR)/$(EPUB_OUT) \
$(EPUBDIR)/$(AZW3_OUT)
#@ clean clean any build artifacts
.PHONY: clean
clean:
rm -rf $(HTMLDIR) $(PDFDIR) $(EPUBDIR)