-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmakefile
135 lines (105 loc) · 5.9 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
SHELL = /bin/bash
# The method Pollen provides for generating the static files for your book is
# to build individual target files, or to build an entire ptree. The principle
# of ‘The book is a program’ means that any one source file/template could
# theoretically affect the output generated by any of the others. So rebuilding
# entire ptrees is the safest, simplest way to ensure that any updates propagate
# fully throughout the entire generated book.
# A makefile allows us to specify more specific dependency relationships between
# files in our particular project. We can now just type ‘make’ from the
# project directory to re-generate only those files that actually need it.
# This makefile is more complicated than it would need to be in a ‘normal’
# project because I have a bunch of different kinds of content in various
# directories.
core-files := pollen.rkt index.ptree
# Create variables with lists of all source files in the posts/ folder,
# then generate lists of target files.
posts-sourcefiles := $(wildcard posts/*.poly.pm)
# I want to show off my Pollen source files, so I name them .pollen.html
posts-sourcelistings := $(patsubst %.poly.pm,%.pollen.html,$(posts-sourcefiles))
posts-html := $(patsubst %.poly.pm,%.html,$(posts-sourcefiles))
posts-pdf := $(patsubst %.poly.pm,%.pdf,$(posts-sourcefiles))
# Same for files in the flatland/ folder:
flatland-sourcefiles := $(wildcard flatland/*.poly.pm)
flatland-sourcelistings := $(patsubst %.poly.pm,%.pollen.html,$(flatland-sourcefiles))
flatland-html := $(patsubst %.poly.pm,%.html,$(flatland-sourcefiles))
flatland-pdf := $(patsubst %.poly.pm,%.pdf,$(flatland-sourcefiles))
other-html := posts.html series.html
# The ‘all’ rule references the rules BELOW it (the above are just variable
# definitions, not rules).
all: $(posts-sourcelistings) $(posts-html) $(flatland-sourcelistings) $(flatland-html) \
$(posts-pdf) $(flatland-pdf) $(other-html) flatland/flatland-book.pdf index.html feed.xml bookindex.html
all: ## Re-generate site including PDFs and RSS
# My dependencies are roughly as follows: for each .poly.pm file I want to
# generate an HTML file, a PDF file, and a .pollen.html file (so people can see
# the Pollen source). The index.html, book-index and Atom feed should be rebuilt
# if any of the source files change. Pretty much
# The two rules allow us to say, in effect, “each source listing .pollen.html
# depends on its corresponding .poly.pm file, but also on util/make-html-source.sh.”
# So it will run its recipe if any of those dependencies have changed.
$(posts-sourcelistings): util/make-html-source.sh
$(posts-sourcelistings): %.pollen.html: %.poly.pm
util/make-html-source.sh $< > $@
$(posts-html): $(core-files) template.html.p
$(posts-html): %.html: %.poly.pm
raco pollen render -t html $<
# My pdf files depend on pollen.rkt, but are not particularly affected by
# changes to index.ptree. So I just use pollen.rkt instead of $(core-files) here.
$(posts-pdf): pollen.rkt template.pdf.p
$(posts-pdf): %.pdf: %.poly.pm
raco pollen render -t pdf $<
$(flatland-sourcelistings): util/make-html-source.sh
$(flatland-sourcelistings): %.pollen.html: %.poly.pm
util/make-html-source.sh $< > $@
$(flatland-html): $(core-files) flatland/template.html.p
$(flatland-html): %.html: %.poly.pm
raco pollen render -t html $<
$(flatland-pdf): pollen.rkt flatland/template.pdf.p
$(flatland-pdf): %.pdf: %.poly.pm
raco pollen render -t pdf $<
flatland/flatland-book.pdf: flatland/flatland-book.pdf.pp flatland/flatland-book.ltx
raco pollen render $@
flatland/flatland-book.ltx: $(core-files) $(flatland-sourcefiles) flatland/flatland-book.ltx.pp
raco pollen render $@
feed.xml: $(core-files) $(posts-sourcefiles) feed.xml.pp
raco pollen render feed.xml.pp
index.html: $(core-files) $(posts-sourcefiles) $(flatland-sourcefiles) \
template-index.html.p index.html.pm
raco pollen render $@
bookindex.html: $(core-files) $(posts-sourcefiles) $(flatland-sourcefiles) \
bookindex.html.pm template-bookindex.html.p
raco pollen render $@
colophon.html: pollen.rkt colophon.poly.pm template.html.p
raco pollen render $@
colophon.pdf: pollen.rkt colophon.poly.pm template.pdf.p
raco pollen render $@
$(other-html): pollen.rkt template.html.p
$(other-html): %.html: %.html.pm
raco pollen render $@
.PHONY: all publish spritz zap help
# Doing ‘make publish’ automatically upload everything except the Pollen source
# files to the public web server. The SECRETARY_SRV is defined as an environment
# variable for security reasons (never put credentials in a script if you can avoid it!)
# Make sure yours is of the form ‘[email protected]:public_html/’
# See also the docs for ‘raco pollen publish’:
# http://pkg-build.racket-lang.org/doc/pollen/raco-pollen.html
publish: ## Rsync the website to the public web server
rm -rf posts/pollen-latex-work flatland/pollen-latex-work pollen-latex-work; \
raco pollen publish; \
rsync -av ~/Desktop/publish/ -e 'ssh -p $(WEB_SRV_PORT)' $(SECRETARY_SRV) --delete-before --exclude=.git --exclude=.DS_Store --exclude=.gitignore --exclude 'template*.*'; \
rm -rf ~/Desktop/publish
# ‘make spritz’ just cleans up the pollen-latex-work files; ‘make zap’ deletes
# all output files as well.
spritz: ## Just cleans up LaTeX working folders
rm -rf posts/pollen-latex-work flatland/pollen-latex-work pollen-latex-work
zap: ## Resets Pollen cache, deletes LaTeX working folders, feed.xml and all .html, .ltx files
rm -rf posts/pollen-latex-work flatland/pollen-latex-work pollen-latex-work; \
rm posts/*.html posts/*.ltx; \
rm flatland/*.html flatland/*.pdf flatland/*.ltx; \
rm feed.xml; \
rm *.html *.pdf *.xml *.ltx; \
raco pollen reset
# Self-documenting make file (http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html)
help: ## Displays this help screen
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
.DEFAULT_GOAL := help