about summary refs log tree commit diff stats
path: root/makefile
blob: 5ba127cce841f822db3e30e9c380df26774ceeee (plain)
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
140
141
142
143
144
145
146
147
148
149
# Makefile for Autocento of the breakfast table
# by Case Duckworth | autocento.me
# vim: fdm=marker

# variables {{{
appendixd  := appendix
backlinkd  := backlinks
hapaxd     := hapax
scriptd    := scripts
templated  := templates
textd      := text
trunkd     := trunk
wipd       := wip

compiler := bash $(scriptd)/compile.sh
texts    := $(wildcard $(textd)/*.txt)

htmls          = $(patsubst $(textd)/%.txt,%.html,$(texts))
htmlWriter    := html5
htmlTemplate  := $(templated)/page.html
htmlFilter    := $(scriptd)/versify.exe
htmlFilterSrc := $(scriptd)/versify.hs      # Converts <br />s to <span>s
htmlOptions   := --template=$(htmlTemplate)
htmlOptions   += --filter=$(htmlFilter)
htmlOptions   += --smart        # Smart "correct" typeography
htmlOptions   += --mathml       # Use mathml for TeX math in HTML
htmlOptions   += --section-divs # Add a <section> around sections
htmlOptions   += --normalize    # merge adjacent `Str`, `Emph`, `Space`

randomize := $(scriptd)/randomize.js

backTexts         = $(patsubst $(textd)/%.txt,$(backlinkd)/%.back,$(texts))
backTextHead     := $(trunkd)/backlink.head
backHtmls        := $(patsubst %.back,%.html,$(backTexts))
backHtmlWriter   := $(htmlWriter)
backHtmlTemplate := $(templated)/backlinks.html
backHtmlOptions  := --template=$(backHtmlTemplate)
backHtmlOptions  += --smart

hapaxSrcs       = $(patsubst $(textd)/%.txt,$(hapaxd)/%.hapax,$(texts))
hapax          := $(appendixd)/hapax.txt
hapaxWriter    := $(scriptd)/hapax.lua
hapaxFilter    := $(scriptd)/forceascii.exe
hapaxFilterSrc := $(scriptd)/forceascii.hs
hapaxOptions   := --filter=$(hapaxFilter)
hapaxHead      := $(trunkd)/hapax.head
hapaxTmp       := $(trunkd)/_HAPAXTMP.tmp
hapaxHtml      := hapax.html

island           := $(appendixd)/islands.txt
islandHead       := $(trunkd)/islands.head
islandHtml       := islands.html
firstLines       := $(appendixd)/first-lines.txt
firstLinesHead   := $(trunkd)/first-lines.head
firstLinesHtml   := first-lines.html
commonTitles     := $(appendixd)/common-titles.txt
commonTitlesHead := $(trunkd)/common-titles.head
commonTitlesHtml := common-titles.html
toc              := $(appendixd)/toc.txt
tocHead          := $(trunkd)/toc.head
tocHtml          := toc.html
appendices       := $(firstLines) $(commonTitles) $(toc) $(hapax)
appendixHtmls    := $(patsubst $(appendixd)/%.txt,%.html,$(appendices))
# }}}
# PHONY TARGETS {{{
.PHONY: all clean again appendices htmls backlinks
all : appendices backlinks htmls
htmls: $(htmls)
backlinks: $(backHtmls) $(islandHtml)
appendices: $(appendixHtmls)
clean :
	-rm -f $(htmls)
	-rm -f $(backlinkd)/*
	-rm -f $(appendixd)/*
	-rm -f $(hapaxd)/*
	-rm -f $(appendixHtmls)
again : clean all
# }}}
# HTMLS {{{
%.html : $(textd)/%.txt $(htmlFilter) $(htmlTemplate)
	pandoc $< -t $(htmlWriter) $(htmlOptions) -o $@

$(htmlFilter) : $(htmlFilterSrc)
	ghc --make $<
# }}}
# RANDOMIZE.JS {{{
$(randomize) : $(htmls)
	@echo "Updating $@..."
	@$(compiler) $@ $^
# }}}
# BACKLINKS {{{
$(backlinkd)/%.back : $(textd)/%.txt $(backTextHead)
	cat $(backTextHead) > $@
	$(compiler) $@ $< >> $@
	$(compiler) --fix-head $@ $<

$(backlinkd)/%.html : $(backlinkd)/%.back $(backHtmlTemplate)
	pandoc $< -t $(backHtmlWriter) $(backHtmlOptions) -o $@
# }}}
# APPENDICES {{{
$(island) : $(backTexts)
	cat $(islandHead) > $@
	@echo "Compiling $@..."
	@$(compiler) $@ $^ >> $@

$(islandHtml) : $(island)
	pandoc $< -t $(htmlWriter) $(htmlOptions) -o $@

$(firstLines) : $(texts)
	cat $(firstLinesHead) > $@
	@echo "Compiling $@..."
	@$(compiler) $@ $^ >> $@

$(firstLinesHtml) : $(firstLines)
	pandoc $< -t $(htmlWriter) $(htmlOptions) -o $@

$(commonTitles) : $(texts)
	cat $(commonTitlesHead) > $@
	@echo "Compiling $@..."
	@$(compiler) $@ $^ >> $@

$(commonTitlesHtml) : $(commonTitles)
	pandoc $< -t $(htmlWriter) $(htmlOptions) -o $@

$(toc) : $(texts)
	cat $(tocHead) > $@
	@echo "Compiling $@..."
	@$(compiler) $@ $^ >> $@

$(tocHtml) : $(toc)
	pandoc $< -t $(htmlWriter) $(htmlOptions) -o $@
# }}}
# HAPAX LEGOMENA {{{
$(hapaxd)/%.hapax : $(textd)/%.txt $(hapaxWriter)
	pandoc $< -t $(hapaxWriter) $(hapaxOptions) -o $@

$(hapaxFilter) : $(hapaxFilterSrc)
	ghc --make $<

$(hapax) : $(hapaxSrcs)
	pandoc $^ -t $(hapaxWriter) $(hapaxOptions) -o $@
	cat $(hapaxHead) > $(hapaxTmp)
	@echo "Linking $@..."
	@$(compiler) $@ $^ >> $(hapaxTmp)
	mv $(hapaxTmp) $@

$(hapaxHtml) : $(hapax)
	pandoc $< -t $(htmlWriter) $(htmlOptions) -o $@
# }}}