Makefile (1710 bytes)
1 # Maintenance targets for the tmpl repository. 2 3 .POSIX: 4 .PHONY: index check check-sh check-c check-lisp check-py check-index 5 6 PYTHON = python3 7 8 # Replace every placeholder with a word so the checkers see valid syntax. 9 FILL = sed 's/<+[^>]*+>/x/g' 10 11 # Rebuild INDEX.md from the templates and their summary comments. 12 index: 13 { printf '# Index\n\nGenerated by `make index`. Do not edit by hand.\n\n| Template | Summary |\n|---|---|\n'; \ 14 bin/tmpl -l | awk -F '\t' '{ printf "| `%s` | %s |\n", $$1, $$2 }'; } > INDEX.md 15 16 check: check-sh check-c check-lisp check-py check-index 17 18 # Parse every shell template with sh -n and shellcheck. 19 check-sh: 20 @status=0; \ 21 for f in $$(grep -l '<+' $$(find sh -type f) openrc.init bin/tmpl); do \ 22 $(FILL) "$$f" > .check.sh; \ 23 sh -n .check.sh || { echo "sh -n: $$f"; status=1; }; \ 24 shellcheck -s sh -S warning .check.sh || { echo "shellcheck: $$f"; status=1; }; \ 25 done; rm -f .check.sh; exit $$status 26 27 # Compile every C template with the placeholders replaced by a statement. 28 check-c: 29 @status=0; \ 30 for f in $$(grep -l '<+' c/*.c); do \ 31 sed 's/<+[^>]*+>/;/g' "$$f" | cc -fsyntax-only -x c - || { echo "cc: $$f"; status=1; }; \ 32 done; exit $$status 33 34 # Read every Common Lisp template. Skip when sbcl is not installed. 35 check-lisp: 36 @command -v sbcl >/dev/null || { echo "check-lisp: sbcl not installed, skipped"; exit 0; }; \ 37 status=0; \ 38 for f in $$(grep -l '<+' cl/*); do \ 39 $(FILL) "$$f" > .check.lisp; \ 40 sbcl --script tests/read-forms.lisp .check.lisp || { echo "read: $$f"; status=1; }; \ 41 done; rm -f .check.lisp; exit $$status 42 43 check-py: 44 $(PYTHON) -m pytest -q 45 46 # INDEX.md must match the templates. 47 check-index: index 48 git diff --exit-code -- INDEX.md