about summary refs log tree commit diff stats
path: root/makefile
blob: 1c1bc7a2c14408d4206c1060f20e2b53a98b486d (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
# MAKEFILE for Autocento of the breakfast table
# by Case Duckworth | case.duckworth@gmail.com | autocento.me
# inspired by Lincoln Mullen | lincolnmullen.com
# vim: fdm=marker

# Define variables {{{
srcs      := $(wildcard *.txt)
templates := $(wildcard _template.*)
trunk     := trunk
metas      = hapax first-lines common-titles index island
metas     += $(templates) $(wildcard _*)

txts = $(filter-out \
       $(patsubst %,%.txt,$(metas)),\
       $(srcs))

htmls = $(filter-out \
        $(patsubst %,%.html,$(metas)),\
        $(patsubst %.txt,%.html,$(srcs)))
htmlPre           = $(trunk)/versify.exe
htmlPreSrc        = $(trunk)/versify.hs
htmlTemplate      = _template.html
htmlPandocOptions = --template=$(htmlTemplate)
htmlPandocOptions+= --filter=$(htmlPre)
htmlPandocOptions+= --smart --mathml --section-divs

lozenger   = $(trunk)/lozenge.sh
lozengeOut = $(trunk)/lozenge.js

hapaxs = $(filter-out \
         $(patsubst %,%.hapax,$(metas)),\
         $(patsubst %.txt,%.hapax,$(srcs)))
hapaxer            = $(trunk)/hapax.lua
hapaxPre           = $(trunk)/forceascii.exe
hapaxPreSrc        = $(trunk)/forceascii.hs
hapaxPandocOptions = --filter=$(hapaxPre)
hapaxOut           = hapax.txt
hapaxHead          = $(trunk)/hapax.head
hapaxLinker        = $(trunk)/hapaxlink.sh

backTxts   = $(patsubst %.html,%.back,$(htmls))
backHtms   = $(patsubst %.back,%_backlinks.htm,$(backTxts))
backHead   = $(trunk)/backlink.head
backlinker = $(trunk)/backlink.sh
backHtmTemplate = _backlinks_template.htm
backPandocOptions = --template=$(backHtmTemplate) --smart

islandHead = $(trunk)/island.head
islandTxt  = island.txt
islandHtm  = island.htm

firstLinesTxt    = first-lines.txt
firstLinesOut    = first-lines.html
firstLiner       = $(trunk)/first-lines.sh
firstLinesHead   = $(trunk)/first-lines.head
commonTitlesTxt  = common-titles.txt
commonTitlesOut  = common-titles.html
commonTitler     = $(trunk)/common-titles.sh
commonTitlesHead = $(trunk)/common-titles.head

tocTxt  = _toc.txt
tocHtml = _toc.html
tocer   = $(trunk)/toc.sh
tocHead = $(trunk)/toc.head
tocInc = $(hapaxOut) $(islandTxt) $(firstLinesTxt) $(commonTitlesTxt) $(txts)
# }}}
# PHONY {{{
.PHONY: all clean distclean again remake meta
all: meta \
     $(htmlPre) $(htmls) $(lozengeOut)\
     $(backHtms) $(islandHtm)

clean:
	-rm -f $(hapaxs)
	-rm -f $(firstLinesTxt)
	-rm -f $(commonTitlesTxt)
	-rm -f $(backTxts)
	-rm -f *.tmp trunk/*.tmp

distclean: clean
	-rm -f $(hapaxPre) $(htmlPre) hapax.html
	-rm -f $(hapaxOut) $(firstLinesOut) $(commonTitlesOut)
	-rm -f $(backHtms)
	-rm -f $(htmls)

again: clean all
remake: distclean all

meta: $(hapaxOut) $(firstLinesOut) $(commonTitlesOut) $(tocHtml)
# }}}
# HTML {{{
$(htmlPre): $(htmlPreSrc)
	ghc --make $(htmlPreSrc)

%.html: %.txt | $(htmlTemplate) $(htmlPre)
	pandoc $< -t html5 $(htmlPandocOptions) -o $@

$(lozengeOut): $(htmls)
	bash $(lozenger) $(lozengeOut) $(htmls)
# }}}
# BACKLINKS {{{
%.back: %.html $(backHead)
	@bash $(backlinker) $< $@ $(backHead) $(txts)

%_backlinks.htm: %.back $(backHtmTemplate)
	pandoc $< -t html5 $(backPandocOptions) -o $@

$(islandTxt): $(backTxts)

$(islandHtm): $(islandTxt) $(islandHead) $(backHtms)
	pandoc $(islandHead) $< -t html5 $(htmlPandocOptions) -o $@

$(tocTxt): $(tocInc) | $(tocead) $(tocer)
	@bash $(tocer) $(tocTxt) $(tocInc)

$(tocHtml): $(tocTxt) $(tocHead)
	pandoc $(tocHead) $< -t html5 $(htmlPandocOptions) -o $@
# }}}
# HAPAX {{{
$(hapaxPre): $(hapaxPreSrc)
	ghc --make $(hapaxPreSrc)

%.hapax: %.txt $(hapaxPre) $(hapaxLinker)
	pandoc $< -t $(hapaxer) $(hapaxPandocOptions) -o $@

$(hapaxOut): $(hapaxs)
	pandoc $^ -t $(hapaxer) -o $@
	bash $(hapaxLinker) $@ $(hapaxHead) $^
# }}}
# FIRST LINES & COMMON TITLES {{{
$(firstLinesTxt): $(txts) | $(firstLiner) $(firstLinesHead)
	bash $(firstLiner) $@ $(firstLinesHead) $^

$(firstLinesOut): $(firstLinesTxt) $(htmlTemplate) $(htmlPre)
	pandoc $< -t html5 $(htmlPandocOptions) -o $@

$(commonTitlesTxt): $(txts) | $(commonTitler) $(commonTitlesHead)
	bash $(commonTitler) $@ $(commonTitlesHead) $^

$(commonTitlesOut): $(commonTitlesTxt) $(htmlTemplate) $(htmlPre)
	pandoc $< -t html5 $(htmlPandocOptions) -o $@
# }}}