about summary refs log tree commit diff stats
path: root/makefile
blob: 4808e11fcb91de6fbccb0533a89c408a7c1ba795 (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
# 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
metas     += $(templates)

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
backPandocOptions = --template=$(htmlTemplate) --smart
# }}}

.PHONY: all
all: $(hapaxOut)\
     $(htmlPre) $(htmls) $(lozengeOut)\
     $(backTxts) $(backHtms)

# 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) $(htmls)

%_backlinks.htm: %.back | $(htmlTemplate)
	pandoc $< -t html5 $(backPandocOptions) -o $@ && rm $<
# }}}
# HAPAX {{{
$(hapaxPre): $(hapaxPreSrc)
	ghc --make $(hapaxPreSrc)

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

$(hapaxOut): $(hapaxs) | $(hapaxPre) $(hapaxLinker) $(hapaxHead)
	pandoc $^ -t $(hapaxer) -o $(hapaxOut)
	@bash $(hapaxLinker) $@ $(hapaxHead) $^
	-rm *.hapax
# }}}
# FIRST LINES & COMMON TITLES {{{
# TODO
# }}}
# CLEAN {{{
.PHONY: clean
clean:
	-rm -f $(hapaxs) $(hapaxOut)
	-rm -f $(htmls)
	-rm -f $(backHtms)
	-rm -f *.tmp trunk/*.tmp

.PHONY: nuke
nuke: clean
	-rm -f $(hapaxPre) $(htmlPre)

.PHONY: again
again: clean all
# }}}