]> git.ipfire.org Git - thirdparty/man-pages.git/blob - share/mk/lint/man/man.mk
135ac397d41a5746338b4f6bbf579f7e8825f64d
[thirdparty/man-pages.git] / share / mk / lint / man / man.mk
1 ########################################################################
2 # Copyright 2021-2023, Alejandro Colomar <alx@kernel.org>
3 # SPDX-License-Identifier: GPL-3.0-or-later
4 ########################################################################
5
6
7 ifndef MAKEFILE_LINT_MAN_MAN_INCLUDED
8 MAKEFILE_LINT_MAN_MAN_INCLUDED := 1
9
10
11 include $(MAKEFILEDIR)/build/_.mk
12 include $(MAKEFILEDIR)/configure/build-depends/coreutils.mk
13 include $(MAKEFILEDIR)/configure/build-depends/grep.mk
14 include $(MAKEFILEDIR)/configure/build-depends/mandoc.mk
15 include $(MAKEFILEDIR)/lint/_.mk
16 include $(MAKEFILEDIR)/src.mk
17
18
19 mandoc_man_ignore_grep := $(DATAROOTDIR)/lint/mandoc/man.ignore.grep
20
21
22 linters_man := mandoc tbl
23
24
25 $(foreach l, $(linters_man), \
26 $(eval _LINT_man_$(l) := \
27 $(patsubst $(MANDIR)/%, $(_MANDIR)/%.lint-man.$(l).touch, \
28 $(NONSO_MAN))))
29
30
31 $(_LINT_man_mandoc): $(_MANDIR)/%.lint-man.mandoc.touch: $(MANDIR)/% $(mandoc_man_ignore_grep) $(MK) | $$(@D)/
32 $(info LINT (mandoc) $@)
33 ! ($(MANDOC) -man $(MANDOCFLAGS) $< 2>&1 \
34 | $(GREP) -v -f '$(mandoc_man_ignore_grep)' \
35 ||:; \
36 ) \
37 | $(GREP) ^ >&2
38 $(TOUCH) $@
39
40 $(_LINT_man_tbl): $(_MANDIR)/%.lint-man.tbl.touch: $(MANDIR)/% $(MK) | $$(@D)/
41 $(info LINT (tbl comment) $@)
42 if $(GREP) -q '^\.TS$$' $< && ! $(HEAD) -n1 $< | $(GREP) -q '\\" t$$'; \
43 then \
44 >&2 $(ECHO) "$<:1: missing '\\\" t' comment:"; \
45 >&2 $(HEAD) -n1 <$<; \
46 exit 1; \
47 fi
48 if $(HEAD) -n1 $< | $(GREP) -q '\\" t$$' && ! $(GREP) -q '^\.TS$$' $<; \
49 then \
50 >&2 $(ECHO) "$<:1: spurious '\\\" t' comment:"; \
51 >&2 $(HEAD) -n1 <$<; \
52 exit 1; \
53 fi
54 if $(TAIL) -n+2 <$< | $(GREP) -q '\\" t$$'; \
55 then \
56 >&2 $(ECHO) "$<: spurious '\\\" t' not in first line:"; \
57 >&2 $(GREP) -n '\\" t$$' $< /dev/null; \
58 exit 1; \
59 fi
60 $(TOUCH) $@
61
62
63 $(foreach l, $(linters_man), \
64 $(eval .PHONY: lint-man-$(l)))
65 $(foreach l, $(linters_man), \
66 $(eval lint-man-$(l): $(_LINT_man_$(l));))
67 .PHONY: lint-man
68 lint-man: $(foreach l, $(linters_man), lint-man-$(l));
69
70
71 endif # include guard