This is a first step to automating example program checks. It extracts source snippets introduced by "Program source", assuming it's C, and attempts to compile it. For now, only man pages with a single "Program source" entry are processed. The compiled code isn't linked to avoid having to handle library requirements (e.g. -ldl). Signed-off-by: Stephen Kitt <steve@xxxxxxx> --- Makefile | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Makefile b/Makefile index 0da0328d8..3f597d7c3 100644 --- a/Makefile +++ b/Makefile @@ -266,6 +266,23 @@ check-groff-warnings: done; \ rm -f "$$GROFF_LOG" +# Check that man pages' examples programs (for now, only pages with a +# single program) actually compile +.PHONY: check-example-programs +check-example-programs: + GCC_LOG="$$(mktemp --tmpdir manpages-checksXXXX)" || exit $$?; \ + for manpage in $$(grep -rc 'Program source' man?/* | grep ':1$$' | cut -d: -f1); \ + do \ + (man -Tutf8 $$manpage | \ + col -bx | \ + sed -n '/Program source/,/^[[:space:]]\{0,3\}[^[:space:]]/p' | \ + tail -n+2 | \ + head -n-1 | \ + gcc -xc -c -o/dev/null -) 2>| "$$GCC_LOG"; \ + [ -s "$$GCC_LOG" ] && { echo "$$manpage: "; cat "$$GCC_LOG"; echo; }; \ + done; \ + rm -f "$$GCC_LOG" + # someone might also want to look at /var/catman/cat2 or so ... # a problem is that the location of cat pages varies a lot -- 2.30.2