nix-book/Makefile
2023-12-03 20:07:46 +00:00

61 lines
2.3 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Tab characters are invisible evil. Use a different prefix in recipes.
.RECIPEPREFIX = >
# The operator != is not negation; it executes a shell script and sets a variable to its output.
STATIC_ADOC_FILES != find source -name '*.adoc'
GENERATED_ADOC_FILES != find source -name '*.adoc0' | sed 's/\.adoc0/-generated.adoc/'
ADOC_FILES = $(STATIC_ADOC_FILES) $(GENERATED_ADOC_FILES)
DATE != date +%F
TIME != date +"%T %Z"
MAIN_ADOC_FILE = source/book.adoc
HTML_FILE = index.html
PDF_FILE = wombats-book-of-nix.pdf
ADOC_ATTR_DATE = -a docdate="$(DATE)" -a doctime="$(TIME)"
ADOC_ATTR_AUTHORS = -a authors="Amy de Buitléir"
ADOC_ATTRIBUTES = $(ADOC_ATTR_DATE) $(ADOC_ATTR_AUTHORS)
ADOC_HTML_ATTRIBUTES = -a stylesheet=../themes/html.css -a imagesdir=images
ADOC_PDF_ATTRIBUTES = -a pdf-themesdir=themes -a pdf-theme=pdf -a imagesdir=../images
.PHONY: debug
debug :
> @echo "STATIC_ADOC_FILES=$(STATIC_ADOC_FILES)"
> @echo "GENERATED_ADOC_FILES=$(GENERATED_ADOC_FILES)"
> @echo "ADOC_FILES=$(ADOC_FILES)"
.PHONY: all
all : html pdf
.PHONY: html
html : $(HTML_FILE)
.PHONY: pdf
pdf : $(PDF_FILE)
# Files with the "adoc0" extension contain code that must be executed and included in order to generate asciidoc files.
# My "run-code-inline" script is available at https://github.com/mhwombat/bin/blob/master/run-code-inline.
# We want to treat any paths in commands as relative to the adoc0 file, so we cd to its directory.
# The "dir" and "notdir" functions extract the directory and base filename from a path, respectively.
%-generated.adoc : %.adoc0
> cd $(dir $@); run-code-inline < $(notdir $<) 2>&1 | tee $(notdir $@)
> sed -i 's/\x0d\x1b.\x4b//g' $@
# The last line fixes some weird characters generated by some nix commands
$(HTML_FILE) : $(ADOC_FILES)
> asciidoctor -b html5 -d book $(ADOC_ATTRIBUTES) $(ADOC_HTML_ATTRIBUTES) -o $@ $(MAIN_ADOC_FILE)
$(PDF_FILE) : $(ADOC_FILES)
> asciidoctor-pdf -d book $(ADOC_ATTRIBUTES) $(ADOC_PDF_ATTRIBUTES) -o $@ $(MAIN_ADOC_FILE)
.PHONY: clean
clean :
> rm -rf $(HTML_FILE) $(PDF_FILE)
> find source -name '*-generated.adoc' -delete
.PHONY: spellcheck
spellcheck :
> cat index.html | aspell --lang=en_IE --encoding=utf-8 --add-extra-dicts=./wordlist --mode=html list | sort -u
# dictionary/en_book.rws : wordlist
# > aspell --lang=en create master ./$@ < $<