summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile27
2 files changed, 21 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 94e96c1..37d475e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
dissertation.md
dissertation.latex
dissertation-no-references.latex
+*.wc
diff --git a/Makefile b/Makefile
index 2a2957d..d1e54aa 100644
--- a/Makefile
+++ b/Makefile
@@ -5,20 +5,25 @@ WORDCOUNT_FILTER := filters/wordcount.lua
DISSERTATION_FRONTMATTER := frontmatter.yml
DISSERTATION_MARKDOWN := dissertation.md
CHAPTER_MARKDOWN_FILES := $(wildcard chapter*.md)
+CHAPTER_MARKDOWN_FILE_PATTERN := chapter%.md
CHAPTER_INDICES := $(CHAPTER_MARKDOWN_FILES:chapter%.md=%)
+CHAPTER_WORDCOUNT_FILE_PATTERN := .chapter%.wc
+CHAPTER_WORDCOUNT_FILES := $(CHAPTER_INDICES:%=$(CHAPTER_WORDCOUNT_FILE_PATTERN))
LOG_MARKDOWN := log.md
SCRAPBOOK_MARKDOWN := scrapbook.md
DISSERTATION_LATEX := dissertation.latex
DISSERTATION_LATEX_NO_REFERENCES := dissertation-no-references.latex
+DISSERTATION_WORDCOUNT_FILE := .dissertation.wc
DISSERTATION_PDF := dissertation.pdf
DISSERTATION_PDF_NO_REFERENCES := dissertation-no-references.pdf
LOG_PDF := log.pdf
SCRAPBOOK_PDF := scrapbook.pdf
-chapter_markdown = chapter$(chapter_index).md
-chapter_title = $(shell head -n 1 $(chapter_markdown) | cut -c4-)
+chapter_markdown_file = chapter$(chapter_index).md
+chapter_wordcount_file = .chapter$(chapter_index).wc
+chapter_title = $(shell head -n 1 $(chapter_markdown_file) | cut -c4-)
-all: log scrapbook dissertation
+all: log scrapbook dissertation wordcount
watch:
ifdef TARGET
@@ -94,13 +99,21 @@ $(DISSERTATION_MARKDOWN): $(DISSERTATION_FRONTMATTER) $(CHAPTER_MARKDOWN_FILES)
echo "" >> $(DISSERTATION_MARKDOWN)
.SILENT: wordcount
-wordcount: $(DISSERTATION_PDF_NO_REFERENCES)
+.PHONY: wordcount
+wordcount: $(CHAPTER_WORDCOUNT_FILES) $(DISSERTATION_WORDCOUNT_FILE)
$(foreach chapter_index,$(CHAPTER_INDICES), \
- echo "$(chapter_title): $$(pandoc --lua-filter $(WORDCOUNT_FILTER) $(chapter_markdown))"; \
+ echo "$(chapter_title): $(shell cat $(chapter_wordcount_file))"; \
)
echo "Footnotes: ???"
echo "References: ???"
- echo "Total: $$(pdfgrep -o '\w+' $(DISSERTATION_PDF_NO_REFERENCES) | wc -w) ($$(pandoc --lua-filter $(WORDCOUNT_FILTER) $(DISSERTATION_MARKDOWN)) + footnotes)"
+ echo "Total: $(shell cat $(DISSERTATION_WORDCOUNT_FILE))"
+
+$(CHAPTER_WORDCOUNT_FILE_PATTERN): $(CHAPTER_MARKDOWN_FILE_PATTERN) $(WORDCOUNT_FILTER)
+ pandoc --lua-filter $(WORDCOUNT_FILTER) $< > $@
+
+$(DISSERTATION_WORDCOUNT_FILE): $(DISSERTATION_PDF_NO_REFERENCES) $(WORDCOUNT_FILTER) $(DISSERTATION_MARKDOWN)
+ echo "$(shell pdfgrep -o '\w+' $(DISSERTATION_PDF_NO_REFERENCES) | wc -w) ($(shell pandoc --lua-filter $(WORDCOUNT_FILTER) $(DISSERTATION_MARKDOWN)) + footnotes)" \
+ > $(DISSERTATION_WORDCOUNT_FILE)
$(DISSERTATION_PDF_NO_REFERENCES): $(DISSERTATION_LATEX_NO_REFERENCES)
pandoc \
@@ -118,4 +131,4 @@ $(DISSERTATION_LATEX_NO_REFERENCES): $(DISSERTATION_LATEX)
tail -n +$$(( $(bib_end_line_index) + 1 )) $(DISSERTATION_LATEX) >> $(DISSERTATION_LATEX_NO_REFERENCES)
clean:
- rm -f $(LOG_PDF) $(SCRAPBOOK_PDF) $(DISSERTATION_MARKDOWN) $(DISSERTATION_LATEX) $(DISSERTATION_LATEX_NO_REFERENCES) $(DISSERTATION_PDF) $(DISSERTATION_PDF_NO_REFERENCES)
+ rm -f $(LOG_PDF) $(SCRAPBOOK_PDF) $(DISSERTATION_MARKDOWN) $(DISSERTATION_LATEX) $(DISSERTATION_LATEX_NO_REFERENCES) $(DISSERTATION_PDF) $(DISSERTATION_PDF_NO_REFERENCES) $(CHAPTER_WORDCOUNT_FILES) $(DISSERTATION_WORDCOUNT_FILE)