diff options
author | Case Duckworth | 2015-04-01 23:16:18 -0700 |
---|---|---|
committer | Case Duckworth | 2015-04-01 23:20:18 -0700 |
commit | d161be120c22faf222ec15ca618ee367e4d56575 (patch) | |
tree | b945633e680e5682a967f63bad88a2b262b4d4c6 /makefile | |
parent | Merge branch 'gh-pages' of https://github.com/duckwork/autocento into gh-pages (diff) | |
download | autocento-d161be120c22faf222ec15ca618ee367e4d56575.tar.gz autocento-d161be120c22faf222ec15ca618ee367e4d56575.zip |
Refactor makefile; Add hapax preprocessor
Diffstat (limited to 'makefile')
-rw-r--r-- | makefile | 189 |
1 files changed, 87 insertions, 102 deletions
diff --git a/makefile b/makefile index 56b4f6a..4808e11 100644 --- a/makefile +++ b/makefile | |||
@@ -1,110 +1,95 @@ | |||
1 | # Produce HTML & RIVER outputs with pandoc | 1 | # MAKEFILE for Autocento of the breakfast table |
2 | # Case Duckworth | autocento.me | 2 | # by Case Duckworth | case.duckworth@gmail.com | autocento.me |
3 | # inspired by Lincoln Mullen | lincolnmullen.com | 3 | # inspired by Lincoln Mullen | lincolnmullen.com |
4 | 4 | # vim: fdm=marker | |
5 | # Define directories, file lists, and options | 5 | |
6 | TEXTs := $(wildcard *.txt) | 6 | # Define variables {{{ |
7 | 7 | srcs := $(wildcard *.txt) | |
8 | VERSIFYer = trunk/versify.exe | 8 | templates := $(wildcard _template.*) |
9 | 9 | trunk := trunk | |
10 | HTMLbl := index.html template.html index-txt.html | 10 | metas = hapax first-lines common-titles index |
11 | HTMLs := $(filter-out $(HTMLbl),$(patsubst %.txt,%.html,$(TEXTs))) | 11 | metas += $(templates) |
12 | HTMopts = --template=template.html | 12 | |
13 | HTMopts+= --filter=$(VERSIFYer) | 13 | htmls = $(filter-out \ |
14 | HTMopts+= --smart --mathml --section-divs | 14 | $(patsubst %,%.html,$(metas)),\ |
15 | 15 | $(patsubst %.txt,%.html,$(srcs))) | |
16 | BKTXTbl = "hapax.txt|first-lines.txt|common-titles.txt" | 16 | htmlPre = $(trunk)/versify.exe |
17 | BKTXTs = $(patsubst %.html,%.back,$(HTMLs)) | 17 | htmlPreSrc = $(trunk)/versify.hs |
18 | BKTXThd = trunk/backlink.head | 18 | htmlTemplate = _template.html |
19 | BKHTMLs = $(patsubst %.back,%_backlinks.htm,$(BKTXTs)) | 19 | htmlPandocOptions = --template=$(htmlTemplate) |
20 | 20 | htmlPandocOptions+= --filter=$(htmlPre) | |
21 | RIVERbl:= first-lines.river common-titles.river hapax.river | 21 | htmlPandocOptions+= --smart --mathml --section-divs |
22 | RIVERer = trunk/river.lua | 22 | |
23 | RIVERs := $(filter-out $(RIVERbl),$(patsubst %.txt,%.river,$(TEXTs))) | 23 | lozenger = $(trunk)/lozenge.sh |
24 | 24 | lozengeOut = $(trunk)/lozenge.js | |
25 | HAPAXs := $(RIVERs) | 25 | |
26 | HAPAXer = trunk/hapax.lua | 26 | hapaxs = $(filter-out \ |
27 | HAPAXhd:= trunk/hapax.head | 27 | $(patsubst %,%.hapax,$(metas)),\ |
28 | HAPAXtmp= hapax.tmp | 28 | $(patsubst %.txt,%.hapax,$(srcs))) |
29 | HAPAX = hapax.txt | 29 | hapaxer = $(trunk)/hapax.lua |
30 | 30 | hapaxPre = $(trunk)/forceascii.exe | |
31 | LOZENGE = trunk/lozenge.js | 31 | hapaxPreSrc = $(trunk)/forceascii.hs |
32 | hapaxPandocOptions = --filter=$(hapaxPre) | ||
33 | hapaxOut = hapax.txt | ||
34 | hapaxHead = $(trunk)/hapax.head | ||
35 | hapaxLinker = $(trunk)/hapaxlink.sh | ||
36 | |||
37 | backTxts = $(patsubst %.html,%.back,$(htmls)) | ||
38 | backHtms = $(patsubst %.back,%_backlinks.htm,$(backTxts)) | ||
39 | backHead = $(trunk)/backlink.head | ||
40 | backlinker = $(trunk)/backlink.sh | ||
41 | backPandocOptions = --template=$(htmlTemplate) --smart | ||
42 | # }}} | ||
32 | 43 | ||
33 | .PHONY: all | 44 | .PHONY: all |
34 | all : river hapax $(VERSIFYer) html lozenge backlinks | 45 | all: $(hapaxOut)\ |
35 | 46 | $(htmlPre) $(htmls) $(lozengeOut)\ | |
36 | .PHONY: hapax | 47 | $(backTxts) $(backHtms) |
37 | hapax : $(HAPAX) | 48 | |
38 | .PHONY: html | 49 | # HTML {{{ |
39 | html : $(HTMLs) | 50 | $(htmlPre): $(htmlPreSrc) |
40 | .PHONY: river | 51 | ghc --make $(htmlPreSrc) |
41 | river : $(RIVERs) | 52 | |
42 | .PHONY: lozenge | 53 | %.html: %.txt | $(htmlTemplate) $(htmlPre) |
43 | lozenge : $(LOZENGE) | 54 | pandoc $< -t html5 $(htmlPandocOptions) -o $@ |
44 | .PHONY: backlinks | 55 | |
45 | backlinks : $(BKHTMLs) | 56 | $(lozengeOut): $(htmls) |
46 | 57 | @bash $(lozenger) $(lozengeOut) $(htmls) | |
47 | %.html : %.txt template.html $(VERSIFYer) | 58 | # }}} |
48 | pandoc $< -f markdown -t html5 $(HTMopts) -o $@ | 59 | # BACKLINKS {{{ |
49 | 60 | %.back: %.html | $(backHead) | |
50 | %_backlinks.htm : %.back | 61 | @bash $(backlinker) $< $@ $(backHead) $(htmls) |
51 | pandoc $< -f markdown -t html5 $(HTMopts) -o $@ | 62 | |
52 | 63 | %_backlinks.htm: %.back | $(htmlTemplate) | |
53 | %.back : %.txt $(BKTXThd) | 64 | pandoc $< -t html5 $(backPandocOptions) -o $@ && rm $< |
54 | @echo -n "Back-linking $<" | 65 | # }}} |
55 | @cat $(BKTXThd) > $@ | 66 | # HAPAX {{{ |
56 | -@grep -ql "$(patsubst %.txt,%.html,$<)" *.txt |\ | 67 | $(hapaxPre): $(hapaxPreSrc) |
57 | grep -vE $(BKTXTbl) >> $@ || \ | 68 | ghc --make $(hapaxPreSrc) |
58 | echo "_Nothing links here!_" >> $@; | 69 | |
59 | @echo -n "." | 70 | %.hapax: %.txt | $(hapaxPre) |
60 | @title=`grep '^title:' $< | cut -d' ' -f2-`; \ | 71 | pandoc $< -t $(hapaxer) $(hapaxPandocOptions) -o $@ |
61 | sed -i "s/_TITLE_/$$title/" $@; | 72 | |
62 | @echo -n "." | 73 | $(hapaxOut): $(hapaxs) | $(hapaxPre) $(hapaxLinker) $(hapaxHead) |
63 | @for file in `cat $@ | grep '.txt'`; do \ | 74 | pandoc $^ -t $(hapaxer) -o $(hapaxOut) |
64 | title=`grep '^title:' $$file | cut -d' ' -f2-`; \ | 75 | @bash $(hapaxLinker) $@ $(hapaxHead) $^ |
65 | replace=`basename $$file .txt`; \ | 76 | -rm *.hapax |
66 | sed -i "s/^\($$replace\).txt$$/- [$$title](\1.html)/" $@;\ | 77 | # }}} |
67 | echo -n "."; \ | 78 | # FIRST LINES & COMMON TITLES {{{ |
68 | done | 79 | # TODO |
69 | @echo "Done." | 80 | # }}} |
70 | 81 | # CLEAN {{{ | |
71 | %.river : %.txt | ||
72 | @echo River-ing $@ | ||
73 | @sed -e '/^---$$/,/^...$$/d'\ | ||
74 | -e "s/[^][A-Za-z0-9\/\"':.-]/ /g" $< |\ | ||
75 | pandoc - -f markdown -t $(RIVERer) -o $@ | ||
76 | |||
77 | $(VERSIFYer) : trunk/versify.hs | ||
78 | ghc --make trunk/versify.hs | ||
79 | |||
80 | $(LOZENGE) : $(HTMLs) | ||
81 | @echo "Updating lozenge.js..." | ||
82 | @list=`echo $(HTMLs) |\ | ||
83 | sed -e 's/\(\S\+.html\) \?/"\1",/g'\ | ||
84 | -e 's/^\(.*\),$$/var files=[\1]/'` &&\ | ||
85 | sed -i "s/var files=.*/$$list/" $(LOZENGE) | ||
86 | |||
87 | $(HAPAX) : $(RIVERs) $(HAPAXhd) | ||
88 | -rm -f $(HAPAXbl) | ||
89 | @echo "Compiling $(HAPAX)..." | ||
90 | pandoc -f markdown -t $(HAPAXer) -o $(HAPAX) *.river | ||
91 | @echo -n "Linking $(HAPAX)" | ||
92 | @cat $(HAPAXhd) > $(HAPAXtmp) &&\ | ||
93 | for word in `sort hapax.txt`; do\ | ||
94 | file=`grep -liwq "^$$word$$" *.river | grep -v '$(HAPAX)'`;\ | ||
95 | echo "[$$word](`basename $$file river`html)">>$(HAPAXtmp);\ | ||
96 | echo -n '.';\ | ||
97 | done && mv $(HAPAXtmp) $(HAPAX) | ||
98 | @echo "Done." | ||
99 | |||
100 | # TODO: Add indices compilers (first-lines, common-titles) | ||
101 | |||
102 | .PHONY: clean | 82 | .PHONY: clean |
103 | clean: | 83 | clean: |
104 | -rm -f hapax.txt hapax.tmp | 84 | -rm -f $(hapaxs) $(hapaxOut) |
105 | -rm -f $(RIVERs) | 85 | -rm -f $(htmls) |
106 | -rm -f $(HTMLs) | 86 | -rm -f $(backHtms) |
107 | -rm -f $(BKTXTs) $(BKHTMLs) | 87 | -rm -f *.tmp trunk/*.tmp |
88 | |||
89 | .PHONY: nuke | ||
90 | nuke: clean | ||
91 | -rm -f $(hapaxPre) $(htmlPre) | ||
108 | 92 | ||
109 | .PHONY: again | 93 | .PHONY: again |
110 | again: clean all | 94 | again: clean all |
95 | # }}} | ||